giuliomoro@98: #include giuliomoro@98: #include giuliomoro@98: #include giuliomoro@98: #include giuliomoro@98: giuliomoro@98: float gPhase1, gPhase2; giuliomoro@98: float gFrequency1, gFrequency2; giuliomoro@98: float gInverseSampleRate; giuliomoro@98: giuliomoro@98: // initialise_render() is called once before the audio rendering starts. giuliomoro@98: // Use it to perform any initialisation and allocation which is dependent giuliomoro@98: // on the period size or sample rate. giuliomoro@98: // giuliomoro@98: // userData holds an opaque pointer to a data structure that was passed giuliomoro@98: // in from the call to initAudio(). giuliomoro@98: // giuliomoro@98: // Return true on success; returning false halts the program. giuliomoro@98: #include giuliomoro@98: #include giuliomoro@98: extern I2c_Codec *gAudioCodec; giuliomoro@98: extern PRU *gPRU; giuliomoro@98: float D=5264; giuliomoro@183: #define delayLength 256 giuliomoro@98: float delay[delayLength]; giuliomoro@98: int writePointer=0; giuliomoro@98: int readPointer=writePointer+1; giuliomoro@98: AuxiliaryTask updatePll; giuliomoro@98: giuliomoro@98: void updatePllFunction(){ giuliomoro@183: // gPRU->setGPIOTestPin(); giuliomoro@183: static int count = 0; giuliomoro@183: while(!gShouldStop){ giuliomoro@183: gAudioCodec->setPllD(D); giuliomoro@183: count++; giuliomoro@183: if((count&4095)==0) giuliomoro@183: printf("sampling rate: %f\n",gAudioCodec->getAudioSamplingRate()); giuliomoro@183: usleep(100); giuliomoro@183: } giuliomoro@183: // gPRU->clearGPIOTestPin(); giuliomoro@98: } giuliomoro@98: giuliomoro@98: bool setup(BeagleRTContext *context, void *userData) giuliomoro@98: { giuliomoro@98: gInverseSampleRate = 1.0/context->audioSampleRate; giuliomoro@98: giuliomoro@98: gPhase1 = 0.0; giuliomoro@98: gPhase2 = 0.0; giuliomoro@98: giuliomoro@98: gFrequency1 = 200.0; giuliomoro@98: gFrequency2 = 201.0; giuliomoro@183: updatePll=BeagleRT_createAuxiliaryTask(&updatePllFunction, 91, "update PLL"); giuliomoro@98: for(int n=0; nsetPllP(2); giuliomoro@183: // gAudioCodec->setPllR(); giuliomoro@183: // gAudioCodec->setAudioSamplingRate(43600); giuliomoro@183: // printf("samplingRate: %f, k: %f\n", gAudioCodec->getAudioSamplingRate(), gAudioCodec->getPllK()); giuliomoro@183: init = true; giuliomoro@183: } giuliomoro@98: static int count=0; giuliomoro@98: static float lfoPhase=0; giuliomoro@98: static float feedback=0; giuliomoro@183: int updateRate=1; giuliomoro@183: if((count&(updateRate-1))==0){ giuliomoro@183: float amplitude = 8000; giuliomoro@183: float rate = 2; giuliomoro@98: lfoPhase+=rate*2*M_PI*updateRate*context->analogFrames/context->audioSampleRate; giuliomoro@98: D=amplitude+amplitude*sinf(lfoPhase); giuliomoro@98: if((count&255)==0){ giuliomoro@183: // rt_printf("frequency: %f\n", gAudioCodec->getAudioSamplingRate()); giuliomoro@183: // rt_printf("D: %.0f\n", D); giuliomoro@183: // rt_printf("rate: %f\n", rate); giuliomoro@183: // rt_printf("amplitude: %.3f\n", amplitude); giuliomoro@183: // rt_printf("feedback: %.3f\n\n", feedback); giuliomoro@98: } giuliomoro@98: } giuliomoro@98: count++; giuliomoro@98: giuliomoro@98: for(unsigned int n = 0; n < context->audioFrames; n++) { giuliomoro@183: feedback = 0.4; giuliomoro@183: float input = audioReadFrame(context, n, 0) + audioReadFrame(context, n, 1); giuliomoro@183: delay[writePointer++] = input + delay[readPointer]*feedback; giuliomoro@183: float output = (input + 0.9*delay[readPointer++] ) * 0.5; giuliomoro@183: audioWriteFrame(context, n, 0, output); giuliomoro@183: audioWriteFrame(context, n, 1, output); giuliomoro@98: if(writePointer>=delayLength) giuliomoro@98: writePointer-=delayLength; giuliomoro@98: if(readPointer>=delayLength) giuliomoro@98: readPointer-=delayLength; giuliomoro@98: giuliomoro@98: gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; giuliomoro@98: gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; giuliomoro@98: if(gPhase1 > 2.0 * M_PI) giuliomoro@98: gPhase1 -= 2.0 * M_PI; giuliomoro@98: if(gPhase2 > 2.0 * M_PI) giuliomoro@98: gPhase2 -= 2.0 * M_PI; giuliomoro@98: } giuliomoro@98: } giuliomoro@98: giuliomoro@98: // cleanup_render() is called once at the end, after the audio has stopped. giuliomoro@98: // Release any resources that were allocated in initialise_render(). giuliomoro@98: giuliomoro@98: void cleanup(BeagleRTContext *context, void *userData) giuliomoro@98: { giuliomoro@98: giuliomoro@98: }