Mercurial > hg > beaglert
comparison projects/d-box/render.cpp @ 14:06f93bef7dd2
Updated remaining examples to new API
author | andrewm |
---|---|
date | Fri, 23 Jan 2015 15:35:10 +0000 |
parents | 8a575ba3ab52 |
children | 42a683058b6a |
comparison
equal
deleted
inserted
replaced
13:6adb088196a7 | 14:06f93bef7dd2 |
---|---|
27 extern PRU *gPRU; | 27 extern PRU *gPRU; |
28 extern StatusLED gStatusLED; | 28 extern StatusLED gStatusLED; |
29 extern bool gIsLoading; | 29 extern bool gIsLoading; |
30 extern bool gAudioIn; | 30 extern bool gAudioIn; |
31 extern int gPeriodSize; | 31 extern int gPeriodSize; |
32 int gChannels = 2; | |
33 | 32 |
34 float *gOscillatorBuffer1, *gOscillatorBuffer2; | 33 float *gOscillatorBuffer1, *gOscillatorBuffer2; |
35 float *gOscillatorBufferRead, *gOscillatorBufferWrite; | 34 float *gOscillatorBufferRead, *gOscillatorBufferWrite; |
36 int gOscillatorBufferReadPointer = 0; | 35 int gOscillatorBufferReadPointer = 0; |
37 int gOscillatorBufferReadCurrentSize = 0; | 36 int gOscillatorBufferReadCurrentSize = 0; |
129 #ifdef DBOX_CAPE_TEST | 128 #ifdef DBOX_CAPE_TEST |
130 void render_capetest(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, | 129 void render_capetest(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, |
131 uint16_t *matrixIn, uint16_t *matrixOut); | 130 uint16_t *matrixIn, uint16_t *matrixOut); |
132 #endif | 131 #endif |
133 | 132 |
134 bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, int numAudioFramesPerPeriod, float matrixSampleRate, float audioSampleRate, void *userData) { | 133 bool initialise_render(int numMatrixChannels, int numAudioChannels, |
135 gChannels = numChannels; | 134 int numMatrixFramesPerPeriod, |
135 int numAudioFramesPerPeriod, | |
136 float matrixSampleRate, float audioSampleRate, | |
137 void *userData) { | |
136 int oscBankHopSize = *(int *)userData; | 138 int oscBankHopSize = *(int *)userData; |
139 | |
140 if(numMatrixChannels != 8) { | |
141 printf("Error: D-Box needs matrix enabled with 8 channels.\n"); | |
142 return false; | |
143 } | |
137 | 144 |
138 // Allocate two buffers for rendering oscillator bank samples | 145 // Allocate two buffers for rendering oscillator bank samples |
139 // One will be used for writing in the background while the other is used for reading | 146 // One will be used for writing in the background while the other is used for reading |
140 // on the audio thread. 8-byte alignment needed for the NEON code. | 147 // on the audio thread. 8-byte alignment needed for the NEON code. |
141 if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gChannels * sizeof(float))) { | 148 if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) { |
142 printf("Error allocating render buffers\n"); | 149 printf("Error allocating render buffers\n"); |
143 return false; | 150 return false; |
144 } | 151 } |
145 if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gChannels * sizeof(float))) { | 152 if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) { |
146 printf("Error allocating render buffers\n"); | 153 printf("Error allocating render buffers\n"); |
147 return false; | 154 return false; |
148 } | 155 } |
149 gOscillatorBufferWrite = gOscillatorBuffer1; | 156 gOscillatorBufferWrite = gOscillatorBuffer1; |
150 gOscillatorBufferRead = gOscillatorBuffer2; | 157 gOscillatorBufferRead = gOscillatorBuffer2; |
151 | 158 |
152 memset(gOscillatorBuffer1, 0, oscBankHopSize * gChannels * sizeof(float)); | 159 memset(gOscillatorBuffer1, 0, oscBankHopSize * gNumAudioChannels * sizeof(float)); |
153 memset(gOscillatorBuffer2, 0, oscBankHopSize * gChannels * sizeof(float)); | 160 memset(gOscillatorBuffer2, 0, oscBankHopSize * gNumAudioChannels * sizeof(float)); |
154 | 161 |
155 // Initialise the dynamic wavetable used by the oscillator bank | 162 // Initialise the dynamic wavetable used by the oscillator bank |
156 // It should match the size of the static one already allocated in the OscillatorBank object | 163 // It should match the size of the static one already allocated in the OscillatorBank object |
157 // Don't forget a guard point at the end of the table | 164 // Don't forget a guard point at the end of the table |
158 gDynamicWavetableLength = gOscBanks[gCurrentOscBank]->lookupTableSize; | 165 gDynamicWavetableLength = gOscBanks[gCurrentOscBank]->lookupTableSize; |
220 if(gOscBanks[gCurrentOscBank]->state==bank_toreset) | 227 if(gOscBanks[gCurrentOscBank]->state==bank_toreset) |
221 gOscBanks[gCurrentOscBank]->resetOscillators(); | 228 gOscBanks[gCurrentOscBank]->resetOscillators(); |
222 | 229 |
223 if(gOscBanks[gCurrentOscBank]->state==bank_playing) | 230 if(gOscBanks[gCurrentOscBank]->state==bank_playing) |
224 { | 231 { |
225 assert(gChannels == 2); | 232 assert(gNumAudioChannels == 2); |
226 | 233 |
227 #ifdef OLD_OSCBANK | 234 #ifdef OLD_OSCBANK |
228 memset(audioOut, 0, numAudioFrames * gChannels * sizeof(float)); | 235 memset(audioOut, 0, numAudioFrames * gNumAudioChannels * sizeof(float)); |
229 | 236 |
230 /* Render the oscillator bank. The oscillator bank function is written in NEON assembly | 237 /* Render the oscillator bank. The oscillator bank function is written in NEON assembly |
231 * and it strips out all extra checks, so find out in advance whether we can render a whole | 238 * and it strips out all extra checks, so find out in advance whether we can render a whole |
232 * block or whether the frame will increment in the middle of this buffer. | 239 * block or whether the frame will increment in the middle of this buffer. |
233 */ | 240 */ |
260 gOscBanks[gCurrentOscBank]->oscillatorAmplitudes, | 267 gOscBanks[gCurrentOscBank]->oscillatorAmplitudes, |
261 gOscBanks[gCurrentOscBank]->oscillatorNormFreqDerivatives, | 268 gOscBanks[gCurrentOscBank]->oscillatorNormFreqDerivatives, |
262 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, | 269 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, |
263 gDynamicWavetable/*gOscBanks[gCurrentOscBank]->lookupTable*/); | 270 gDynamicWavetable/*gOscBanks[gCurrentOscBank]->lookupTable*/); |
264 framesRemaining -= gOscBanks[gCurrentOscBank]->hopCounter; | 271 framesRemaining -= gOscBanks[gCurrentOscBank]->hopCounter; |
265 audioOutWithOffset += gChannels * gOscBanks[gCurrentOscBank]->hopCounter; | 272 audioOutWithOffset += gNumAudioChannels * gOscBanks[gCurrentOscBank]->hopCounter; |
266 gOscBanks[gCurrentOscBank]->sampleCount += gOscBanks[gCurrentOscBank]->hopCounter; | 273 gOscBanks[gCurrentOscBank]->sampleCount += gOscBanks[gCurrentOscBank]->hopCounter; |
267 gOscBanks[gCurrentOscBank]->nextHop(); | 274 gOscBanks[gCurrentOscBank]->nextHop(); |
268 } | 275 } |
269 } | 276 } |
270 #else | 277 #else |
560 | 567 |
561 if(gOscillatorNeedsRender) { | 568 if(gOscillatorNeedsRender) { |
562 gOscillatorNeedsRender = false; | 569 gOscillatorNeedsRender = false; |
563 | 570 |
564 /* Render one frame into the write buffer */ | 571 /* Render one frame into the write buffer */ |
565 memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gChannels * sizeof(float)); | 572 memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels * sizeof(float)); |
566 | 573 |
567 oscillator_bank_neon(gOscBanks[gCurrentOscBank]->hopCounter, gOscillatorBufferWrite, | 574 oscillator_bank_neon(gOscBanks[gCurrentOscBank]->hopCounter, gOscillatorBufferWrite, |
568 gOscBanks[gCurrentOscBank]->actPartNum, gOscBanks[gCurrentOscBank]->lookupTableSize, | 575 gOscBanks[gCurrentOscBank]->actPartNum, gOscBanks[gCurrentOscBank]->lookupTableSize, |
569 gOscBanks[gCurrentOscBank]->oscillatorPhases, gOscBanks[gCurrentOscBank]->oscillatorNormFrequencies, | 576 gOscBanks[gCurrentOscBank]->oscillatorPhases, gOscBanks[gCurrentOscBank]->oscillatorNormFrequencies, |
570 gOscBanks[gCurrentOscBank]->oscillatorAmplitudes, | 577 gOscBanks[gCurrentOscBank]->oscillatorAmplitudes, |
571 gOscBanks[gCurrentOscBank]->oscillatorNormFreqDerivatives, | 578 gOscBanks[gCurrentOscBank]->oscillatorNormFreqDerivatives, |
572 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, | 579 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, |
573 /*gOscBanks[gCurrentOscBank]->lookupTable*/gDynamicWavetable); | 580 /*gOscBanks[gCurrentOscBank]->lookupTable*/gDynamicWavetable); |
574 | 581 |
575 gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gChannels; | 582 gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels; |
576 | 583 |
577 /* Update the pitch right before the hop | 584 /* Update the pitch right before the hop |
578 * Total CV range +/- N_OCT octaves | 585 * Total CV range +/- N_OCT octaves |
579 */ | 586 */ |
580 float pitch = (float)gPitchLatestInput / octaveSplitter - N_OCT/2; | 587 float pitch = (float)gPitchLatestInput / octaveSplitter - N_OCT/2; |