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: Scope scope; //create a scope object 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@98: #define delayLength 512 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@98: // rt_printf("now\n"); giuliomoro@98: gPRU->setGPIOTestPin(); giuliomoro@98: gAudioCodec->setPllD(D); giuliomoro@98: gPRU->clearGPIOTestPin(); giuliomoro@98: } giuliomoro@98: giuliomoro@98: bool setup(BeagleRTContext *context, void *userData) giuliomoro@98: { giuliomoro@98: scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope 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@98: updatePll=BeagleRT_createAuxiliaryTask(&updatePllFunction, 98, "update PLL"); giuliomoro@98: for(int n=0; nanalogIn[0]/0.84*4990; giuliomoro@98: float rate=context->analogIn[1]*20+0.1; giuliomoro@98: lfoPhase+=rate*2*M_PI*updateRate*context->analogFrames/context->audioSampleRate; giuliomoro@98: D=amplitude+amplitude*sinf(lfoPhase); giuliomoro@98: BeagleRT_scheduleAuxiliaryTask(updatePll); giuliomoro@98: if((count&255)==0){ giuliomoro@98: rt_printf("gpio: %d\n",digitalReadFrame(context,0,P8_07)); giuliomoro@98: rt_printf("D: %.0f\n", D); giuliomoro@98: rt_printf("rate: %f\n", rate/2); giuliomoro@98: rt_printf("amplitude: %.3f\n", amplitude); giuliomoro@98: 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@98: feedback=context->analogIn[n/2*context->analogChannels+2]/0.84*1.2; giuliomoro@98: if(digitalReadFrame(context,n,P8_08)==GPIO_LOW) giuliomoro@98: feedback=0; giuliomoro@98: delay[writePointer++]=context->audioIn[n*context->audioChannels+0] + delay[readPointer]*feedback; giuliomoro@98: context->audioOut[n*context->audioChannels+0]=context->audioIn[n*context->audioChannels+0]+delay[readPointer++]; giuliomoro@98: // context->audioOut[n*context->audioChannels+1]=sinf(gPhase1); giuliomoro@98: context->analogOut[n/2*context->analogChannels+0]=D/10000; 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: 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: }