Mercurial > hg > beaglert
changeset 183:2bdb48d1fca6
Fixed BBD chorus project
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 15 Jan 2016 23:48:08 +0000 |
parents | 4c5acd649d46 |
children | 9108a0a34cb8 |
files | projects/bucket_brigade_chorus/render.cpp |
diffstat | 1 files changed, 37 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/bucket_brigade_chorus/render.cpp Fri Jan 15 23:46:25 2016 +0000 +++ b/projects/bucket_brigade_chorus/render.cpp Fri Jan 15 23:48:08 2016 +0000 @@ -7,8 +7,6 @@ float gFrequency1, gFrequency2; float gInverseSampleRate; -Scope scope; //create a scope object - // initialise_render() is called once before the audio rendering starts. // Use it to perform any initialisation and allocation which is dependent // on the period size or sample rate. @@ -22,23 +20,27 @@ extern I2c_Codec *gAudioCodec; extern PRU *gPRU; float D=5264; -#define delayLength 512 +#define delayLength 256 float delay[delayLength]; int writePointer=0; int readPointer=writePointer+1; AuxiliaryTask updatePll; void updatePllFunction(){ -// rt_printf("now\n"); - gPRU->setGPIOTestPin(); - gAudioCodec->setPllD(D); - gPRU->clearGPIOTestPin(); +// gPRU->setGPIOTestPin(); + static int count = 0; + while(!gShouldStop){ + gAudioCodec->setPllD(D); + count++; + if((count&4095)==0) + printf("sampling rate: %f\n",gAudioCodec->getAudioSamplingRate()); + usleep(100); + } +// gPRU->clearGPIOTestPin(); } bool setup(BeagleRTContext *context, void *userData) { - scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope - gInverseSampleRate = 1.0/context->audioSampleRate; gPhase1 = 0.0; @@ -46,7 +48,7 @@ gFrequency1 = 200.0; gFrequency2 = 201.0; - updatePll=BeagleRT_createAuxiliaryTask(&updatePllFunction, 98, "update PLL"); + updatePll=BeagleRT_createAuxiliaryTask(&updatePllFunction, 91, "update PLL"); for(int n=0; n<delayLength; n++){ delay[n]=0; } @@ -60,34 +62,42 @@ void render(BeagleRTContext *context, void *userData) { +// printf("here\n"); + static bool init = false; + if(init == false){ + BeagleRT_scheduleAuxiliaryTask(updatePll); +// gAudioCodec->setPllP(2); +// gAudioCodec->setPllR(); +// gAudioCodec->setAudioSamplingRate(43600); +// printf("samplingRate: %f, k: %f\n", gAudioCodec->getAudioSamplingRate(), gAudioCodec->getPllK()); + init = true; + } static int count=0; static float lfoPhase=0; static float feedback=0; - int updateRate=8; - if((count&(updateRate-1))==0 && digitalReadFrame(context,0,P8_07)==GPIO_HIGH){ - float amplitude=context->analogIn[0]/0.84*4990; - float rate=context->analogIn[1]*20+0.1; + int updateRate=1; + if((count&(updateRate-1))==0){ + float amplitude = 8000; + float rate = 2; lfoPhase+=rate*2*M_PI*updateRate*context->analogFrames/context->audioSampleRate; D=amplitude+amplitude*sinf(lfoPhase); - BeagleRT_scheduleAuxiliaryTask(updatePll); if((count&255)==0){ - rt_printf("gpio: %d\n",digitalReadFrame(context,0,P8_07)); - rt_printf("D: %.0f\n", D); - rt_printf("rate: %f\n", rate/2); - rt_printf("amplitude: %.3f\n", amplitude); - rt_printf("feedback: %.3f\n\n", feedback); +// rt_printf("frequency: %f\n", gAudioCodec->getAudioSamplingRate()); +// rt_printf("D: %.0f\n", D); +// rt_printf("rate: %f\n", rate); +// rt_printf("amplitude: %.3f\n", amplitude); +// rt_printf("feedback: %.3f\n\n", feedback); } } count++; for(unsigned int n = 0; n < context->audioFrames; n++) { - feedback=context->analogIn[n/2*context->analogChannels+2]/0.84*1.2; - if(digitalReadFrame(context,n,P8_08)==GPIO_LOW) - feedback=0; - delay[writePointer++]=context->audioIn[n*context->audioChannels+0] + delay[readPointer]*feedback; - context->audioOut[n*context->audioChannels+0]=context->audioIn[n*context->audioChannels+0]+delay[readPointer++]; -// context->audioOut[n*context->audioChannels+1]=sinf(gPhase1); - context->analogOut[n/2*context->analogChannels+0]=D/10000; + feedback = 0.4; + float input = audioReadFrame(context, n, 0) + audioReadFrame(context, n, 1); + delay[writePointer++] = input + delay[readPointer]*feedback; + float output = (input + 0.9*delay[readPointer++] ) * 0.5; + audioWriteFrame(context, n, 0, output); + audioWriteFrame(context, n, 1, output); if(writePointer>=delayLength) writePointer-=delayLength; if(readPointer>=delayLength) @@ -99,7 +109,6 @@ gPhase1 -= 2.0 * M_PI; if(gPhase2 > 2.0 * M_PI) gPhase2 -= 2.0 * M_PI; - } }