l@273: #include l@273: #include l@273: #include l@273: l@273: // set the frequency of the oscillators l@273: float gFrequency = 110.0; l@273: float gPhase; l@273: float gInverseSampleRate; l@273: l@273: // instantiate the scope l@273: Scope scope; l@273: l@273: bool setup(BeagleRTContext *context, void *userData) l@273: { l@273: // tell the scope how many channels and the sample rate l@273: scope.setup(3, context->audioSampleRate); l@273: l@273: gPhase = 0; l@273: gInverseSampleRate = 1.0f/context->audioSampleRate; l@273: l@273: return true; l@273: } l@273: l@273: float lastOut = 0.0; l@273: float lastOut2 = 0.0; l@273: void render(BeagleRTContext *context, void *userData) l@273: { l@273: // iterate over the audio frames and create three oscillators, seperated in phase by PI/2 l@273: for (unsigned int n=0; naudioFrames; n++){ l@273: float out = 0.8f * sinf(gPhase); l@273: float out2 = 0.8f * sinf(gPhase - M_PI/2); l@273: float out3 = 0.8f * sinf(gPhase + M_PI/2); l@273: gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; l@273: if(gPhase > 2.0 * M_PI) l@273: gPhase -= 2.0 * M_PI; l@273: l@273: // log the three oscillators to the scope l@273: scope.log(out, out2, out3); l@273: l@273: // optional - tell the scope to trigger when oscillator 1 becomes less than oscillator 2 l@273: // note this has no effect unless trigger mode is set to custom in the scope UI l@273: if (lastOut >= lastOut2 && out < out2){ l@273: scope.trigger(); l@273: } l@273: l@273: lastOut = out; l@273: lastOut2 = out2; l@273: } l@273: } l@273: l@273: void cleanup(BeagleRTContext *context, void *userData) l@273: { l@273: l@273: }