giuliomoro@301: #include giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: giuliomoro@153: float gPhase1, gPhase2; giuliomoro@153: float gFrequency1, gFrequency2; giuliomoro@153: float gInverseSampleRate; giuliomoro@153: giuliomoro@153: WriteFile file1; giuliomoro@153: WriteFile file2; giuliomoro@153: giuliomoro@301: bool setup(BelaContext *context, void *userData) giuliomoro@153: { giuliomoro@153: gInverseSampleRate = 1.0/context->audioSampleRate; giuliomoro@153: file1.init("out1.m"); //set the file name to write to giuliomoro@153: file1.setHeader("myvar=[\n"); //set a line to be printed at the beginning of the file giuliomoro@153: file1.setFooter("];\n"); //set a line to be printed at the end of the file giuliomoro@153: file1.setEcho(true); // enable echo to the console (as well as to the file) giuliomoro@153: file1.setFormat("%.5f %.10f %f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers) giuliomoro@153: file2.init("out2.m"); giuliomoro@153: file2.setHeader("input=[\n"); giuliomoro@153: file2.setFooter("];\n"); giuliomoro@153: file2.setEcho(false); giuliomoro@153: file2.setFormat("%f\n"); giuliomoro@153: gPhase1 = 0.0; giuliomoro@153: gPhase2 = 0.0; giuliomoro@153: giuliomoro@153: gFrequency1 = 200.0; giuliomoro@153: gFrequency2 = 201.0; giuliomoro@153: return true; giuliomoro@153: } giuliomoro@153: giuliomoro@301: void render(BelaContext *context, void *userData) giuliomoro@153: { giuliomoro@153: static int count = 0; giuliomoro@153: if((count&16383) == 0){ giuliomoro@153: file2.log(context->audioIn, context->audioFrames); //write the input buffer every so often giuliomoro@153: } giuliomoro@153: for(unsigned int n = 0; n < context->audioFrames; n++) { giuliomoro@153: float chn1 = sinf(gPhase1); giuliomoro@153: float chn2 = sinf(gPhase2); giuliomoro@153: gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; giuliomoro@153: gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; giuliomoro@153: if(gPhase1 > 2.0 * M_PI) giuliomoro@153: gPhase1 -= 2.0 * M_PI; giuliomoro@153: if(gPhase2 > 2.0 * M_PI) giuliomoro@153: gPhase2 -= 2.0 * M_PI; giuliomoro@153: if( (count&511) == 0){ giuliomoro@153: file1.log(chn1); giuliomoro@153: file1.log(chn2); giuliomoro@153: file1.log(count); giuliomoro@153: } giuliomoro@153: count++; giuliomoro@153: } giuliomoro@153: } giuliomoro@153: giuliomoro@153: // cleanup_render() is called once at the end, after the audio has stopped. giuliomoro@153: // Release any resources that were allocated in initialise_render(). giuliomoro@153: giuliomoro@301: void cleanup(BelaContext *context, void *userData) giuliomoro@153: { giuliomoro@153: giuliomoro@153: }