giuliomoro@94: #include giuliomoro@94: #include giuliomoro@94: #include giuliomoro@94: giuliomoro@94: float gPhase1, gPhase2; giuliomoro@94: float gFrequency1, gFrequency2; giuliomoro@94: float gInverseSampleRate; giuliomoro@94: giuliomoro@94: Scope scope; //create a scope object giuliomoro@94: giuliomoro@94: // initialise_render() is called once before the audio rendering starts. giuliomoro@94: // Use it to perform any initialisation and allocation which is dependent giuliomoro@94: // on the period size or sample rate. giuliomoro@94: // giuliomoro@94: // userData holds an opaque pointer to a data structure that was passed giuliomoro@94: // in from the call to initAudio(). giuliomoro@94: // giuliomoro@94: // Return true on success; returning false halts the program. giuliomoro@94: bool setup(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope giuliomoro@94: giuliomoro@94: gInverseSampleRate = 1.0/context->audioSampleRate; giuliomoro@94: giuliomoro@94: gPhase1 = 0.0; giuliomoro@94: gPhase2 = 0.0; giuliomoro@94: giuliomoro@94: gFrequency1 = 200.0; giuliomoro@94: gFrequency2 = 201.0; giuliomoro@94: return true; giuliomoro@94: } giuliomoro@94: giuliomoro@94: // render() is called regularly at the highest priority by the audio engine. giuliomoro@94: // Input and output are given from the audio hardware and the other giuliomoro@94: // ADCs and DACs (if available). If only audio is available, numMatrixFrames giuliomoro@94: // will be 0. giuliomoro@94: giuliomoro@94: void render(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: for(unsigned int n = 0; n < context->audioFrames; n++) { giuliomoro@94: giuliomoro@94: float chn1 = sinf(gPhase1); giuliomoro@94: float chn2 = sinf(gPhase2); giuliomoro@94: giuliomoro@94: float chn3 = context->audioIn[n*2 + 0]; giuliomoro@94: float chn4 = context->audioIn[n*2 + 1]; giuliomoro@94: giuliomoro@94: float chn5 = context->analogIn[(int)n/2*8 + 0]; giuliomoro@94: float chn6 = context->analogIn[(int)n/2*8 + 1]; giuliomoro@94: giuliomoro@94: // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); giuliomoro@94: scope.log(chn1); giuliomoro@94: //call this once every audio frame giuliomoro@94: //takes six or fewer floats as parameters giuliomoro@94: //first parameter becomes channel 1 etc giuliomoro@94: //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running giuliomoro@94: //then click the big red button on the toolbar on this page giuliomoro@94: giuliomoro@94: gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; giuliomoro@94: gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; giuliomoro@94: if(gPhase1 > 2.0 * M_PI) giuliomoro@94: gPhase1 -= 2.0 * M_PI; giuliomoro@94: if(gPhase2 > 2.0 * M_PI) giuliomoro@94: gPhase2 -= 2.0 * M_PI; giuliomoro@94: giuliomoro@94: } giuliomoro@94: } giuliomoro@94: giuliomoro@94: // cleanup_render() is called once at the end, after the audio has stopped. giuliomoro@94: // Release any resources that were allocated in initialise_render(). giuliomoro@94: giuliomoro@94: void cleanup(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: giuliomoro@94: }