30 #include "utility/dspinst.h"
34 #define BASE_AMPLITUDE 0x6000
51 uint32_t i, ph, index, index2, scale;
68 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
72 scale = (ph >> 8) & 0xFFFF;
74 val1 *= 0x10000 - scale;
75 *bp++ = multiply_32x32_rshift32(val1 + val2,
magnitude);
80 case WAVEFORM_ARBITRARY:
87 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
90 if (index2 >= 2048) index2 = 0;
93 scale = (ph >> 8) & 0xFFFF;
95 val1 *= 0x10000 - scale;
96 *bp++ = multiply_32x32_rshift32(val1 + val2,
magnitude);
101 case WAVEFORM_SQUARE:
102 magnitude15 = signed_saturate_rshift(
magnitude, 16, 1);
103 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
104 if (ph & 0x80000000) {
105 *bp++ = -magnitude15;
113 case WAVEFORM_BANDLIMIT_SQUARE:
114 for (
int i = 0 ; i < AUDIO_BLOCK_SAMPLES ; i++)
116 uint32_t new_ph = ph + inc ;
123 case WAVEFORM_SAWTOOTH:
124 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
125 *bp++ = signed_multiply_32x16t(
magnitude, ph);
130 case WAVEFORM_SAWTOOTH_REVERSE:
131 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
132 *bp++ = signed_multiply_32x16t(0xFFFFFFFFu -
magnitude, ph);
137 case WAVEFORM_BANDLIMIT_SAWTOOTH:
138 case WAVEFORM_BANDLIMIT_SAWTOOTH_REVERSE:
139 for (i = 0 ; i < AUDIO_BLOCK_SAMPLES; i++)
141 uint32_t new_ph = ph + inc ;
143 if (
tone_type == WAVEFORM_BANDLIMIT_SAWTOOTH_REVERSE)
151 case WAVEFORM_TRIANGLE:
152 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
153 uint32_t phtop = ph >> 30;
154 if (phtop == 1 || phtop == 2) {
155 *bp++ = ((0xFFFF - (ph >> 15)) *
magnitude) >> 16;
157 *bp++ = (((int32_t)ph >> 15) *
magnitude) >> 16;
163 case WAVEFORM_TRIANGLE_VARIABLE:
166 uint32_t fall = 0xFFFFFFFF / (0xFFFF - (
pulse_width >> 16));
167 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
169 uint32_t n = (ph >> 16) * rise;
172 uint32_t n = 0x7FFFFFFF - (((ph -
pulse_width/2) >> 16) * fall);
173 *bp++ = (((int32_t)n >> 16) *
magnitude) >> 16;
175 uint32_t n = ((ph +
pulse_width/2) >> 16) * rise + 0x80000000;
176 *bp++ = (((int32_t)n >> 16) *
magnitude) >> 16;
184 magnitude15 = signed_saturate_rshift(
magnitude, 16, 1);
185 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
189 *bp++ = -magnitude15;
195 case WAVEFORM_BANDLIMIT_PULSE:
196 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++)
198 int32_t new_ph = ph + inc ;
200 *bp++ = (int16_t) ((val *
magnitude) >> 16) ;
205 case WAVEFORM_SAMPLE_HOLD:
206 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
208 uint32_t newph = ph + inc;
220 end = bp + AUDIO_BLOCK_SAMPLES;
223 *bp++ = signed_saturate_rshift(val1 +
tone_offset, 16, 0);
245 uint32_t i, ph, index, index2, scale, priorphase;
253 priorphase =
phasedata[AUDIO_BLOCK_SAMPLES-1];
257 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
259 int32_t ipart = n >> 27;
261 #ifdef IMPROVE_EXPONENTIAL_ACCURACY
265 n = multiply_accumulate_32x32_rshift32_rounded(536870912, x, 1494202713);
266 int32_t sq = multiply_32x32_rshift32_rounded(x, x);
267 n = multiply_accumulate_32x32_rshift32_rounded(n, sq, 1934101615);
268 n = n + (multiply_32x32_rshift32_rounded(sq,
269 multiply_32x32_rshift32_rounded(x, 1358044250)) << 1);
274 n = (n + 134217728) << 3;
276 n = multiply_32x32_rshift32_rounded(n, n);
277 n = multiply_32x32_rshift32_rounded(n, 715827883) << 3;
280 uint32_t scale = n >> (14 - ipart);
281 uint64_t phstep = (uint64_t)inc * scale;
282 uint32_t phstep_msw = phstep >> 32;
283 if (phstep_msw < 0x7FFE) {
291 }
else if (moddata) {
294 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
303 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
312 if (shapedata)
release(shapedata);
317 if (shapedata)
release(shapedata);
325 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
330 scale = (ph >> 8) & 0xFFFF;
332 val1 *= 0x10000 - scale;
333 *bp++ = multiply_32x32_rshift32(val1 + val2,
magnitude);
337 case WAVEFORM_ARBITRARY:
340 if (shapedata)
release(shapedata);
344 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
348 if (index2 >= 2048) index2 = 0;
351 scale = (ph >> 8) & 0xFFFF;
353 val1 *= 0x10000 - scale;
354 *bp++ = multiply_32x32_rshift32(val1 + val2,
magnitude);
360 magnitude15 = signed_saturate_rshift(
magnitude, 16, 1);
361 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
362 uint32_t width = ((shapedata->
data[i] + 0x8000) & 0xFFFF) << 16;
366 *bp++ = -magnitude15;
372 case WAVEFORM_SQUARE:
373 magnitude15 = signed_saturate_rshift(
magnitude, 16, 1);
374 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
376 *bp++ = -magnitude15;
383 case WAVEFORM_BANDLIMIT_PULSE:
386 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++)
388 uint32_t width = ((shapedata->
data[i] + 0x8000) & 0xFFFF) << 16;
390 *bp++ = (int16_t) ((val *
magnitude) >> 16) ;
395 case WAVEFORM_BANDLIMIT_SQUARE:
396 for (i = 0 ; i < AUDIO_BLOCK_SAMPLES ; i++)
399 *bp++ = (int16_t) ((val *
magnitude) >> 16) ;
403 case WAVEFORM_SAWTOOTH:
404 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
409 case WAVEFORM_SAWTOOTH_REVERSE:
410 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
415 case WAVEFORM_BANDLIMIT_SAWTOOTH:
416 case WAVEFORM_BANDLIMIT_SAWTOOTH_REVERSE:
417 for (i = 0 ; i < AUDIO_BLOCK_SAMPLES ; i++)
420 val = (int16_t) ((val *
magnitude) >> 16) ;
421 *bp++ =
tone_type == WAVEFORM_BANDLIMIT_SAWTOOTH_REVERSE ? (int16_t) -val : (int16_t) +val ;
425 case WAVEFORM_TRIANGLE_VARIABLE:
427 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
428 uint32_t width = (shapedata->
data[i] + 0x8000) & 0xFFFF;
429 uint32_t rise = 0xFFFFFFFF / width;
430 uint32_t fall = 0xFFFFFFFF / (0xFFFF - width);
431 uint32_t halfwidth = width << 15;
434 if (ph < halfwidth) {
435 n = (ph >> 16) * rise;
437 }
else if (ph < 0xFFFFFFFF - halfwidth) {
438 n = 0x7FFFFFFF - (((ph - halfwidth) >> 16) * fall);
439 *bp++ = (((int32_t)n >> 16) *
magnitude) >> 16;
441 n = ((ph + halfwidth) >> 16) * rise + 0x80000000;
442 *bp++ = (((int32_t)n >> 16) *
magnitude) >> 16;
449 case WAVEFORM_TRIANGLE:
450 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
452 uint32_t phtop = ph >> 30;
453 if (phtop == 1 || phtop == 2) {
454 *bp++ = ((0xFFFF - (ph >> 15)) *
magnitude) >> 16;
456 *bp++ = (((int32_t)ph >> 15) *
magnitude) >> 16;
460 case WAVEFORM_SAMPLE_HOLD:
461 for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
463 if (ph < priorphase) {
474 end = bp + AUDIO_BLOCK_SAMPLES;
477 *bp++ = signed_saturate_rshift(val1 +
tone_offset, 16, 0);
480 if (shapedata)
release(shapedata);
static void release(audio_block_t *block)
static audio_block_t * allocate(void)
audio_block_t * receiveReadOnly(unsigned int index=0)
void transmit(audio_block_t *block, unsigned char index=0)
int16_t data[AUDIO_BLOCK_SAMPLES]