robert@464: /* robert@464: ____ _____ _ _ robert@464: | __ )| ____| | / \ robert@464: | _ \| _| | | / _ \ robert@464: | |_) | |___| |___ / ___ \ robert@464: |____/|_____|_____/_/ \_\ robert@464: robert@464: The platform for ultra-low latency audio and sensor processing robert@464: robert@464: http://bela.io robert@464: robert@464: A project of the Augmented Instruments Laboratory within the robert@464: Centre for Digital Music at Queen Mary University of London. robert@464: http://www.eecs.qmul.ac.uk/~andrewm robert@464: robert@464: (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, robert@464: Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, robert@464: Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. robert@464: robert@464: The Bela software is distributed under the GNU Lesser General Public License robert@464: (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt robert@464: */ robert@464: robert@464: robert@464: #include robert@464: #include robert@464: #include robert@464: robert@464: float gPhase1, gPhase2; robert@464: float gFrequency1, gFrequency2; robert@464: float gInverseSampleRate; robert@464: robert@464: WriteFile file1; robert@464: WriteFile file2; robert@464: robert@464: bool setup(BelaContext *context, void *userData) robert@464: { robert@464: gInverseSampleRate = 1.0/context->audioSampleRate; robert@464: file1.init("out1.m"); //set the file name to write to robert@464: file1.setHeader("myvar=[\n"); //set a line to be printed at the beginning of the file robert@464: file1.setFooter("];\n"); //set a line to be printed at the end of the file robert@464: file1.setEcho(true); // enable echo to the console (as well as to the file) robert@464: file1.setFormat("%.5f %.10f %f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers) robert@464: file2.init("out2.m"); robert@464: file2.setHeader("input=[\n"); robert@464: file2.setFooter("];\n"); robert@464: file2.setEcho(false); robert@464: file2.setFormat("%f\n"); robert@464: gPhase1 = 0.0; robert@464: gPhase2 = 0.0; robert@464: robert@464: gFrequency1 = 200.0; robert@464: gFrequency2 = 201.0; robert@464: return true; robert@464: } robert@464: robert@464: void render(BelaContext *context, void *userData) robert@464: { robert@464: static int count = 0; robert@464: if((count&16383) == 0){ robert@464: file2.log(context->audioIn, context->audioFrames); //write the input buffer every so often robert@464: } robert@464: for(unsigned int n = 0; n < context->audioFrames; n++) { robert@464: float chn1 = sinf(gPhase1); robert@464: float chn2 = sinf(gPhase2); robert@464: gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; robert@464: gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; robert@464: if(gPhase1 > 2.0 * M_PI) robert@464: gPhase1 -= 2.0 * M_PI; robert@464: if(gPhase2 > 2.0 * M_PI) robert@464: gPhase2 -= 2.0 * M_PI; robert@464: if( (count&511) == 0){ robert@464: file1.log(chn1); robert@464: file1.log(chn2); robert@464: file1.log(count); robert@464: } robert@464: count++; robert@464: } robert@464: } robert@464: robert@464: // cleanup_render() is called once at the end, after the audio has stopped. robert@464: // Release any resources that were allocated in initialise_render(). robert@464: robert@464: void cleanup(BelaContext *context, void *userData) robert@464: { robert@464: robert@464: } robert@464: robert@464: /* ------------ Project Explantation ------------ */ robert@464: robert@464: /** robert@464: \example 07-write-file robert@464: robert@464: Writing data to a file robert@464: --------------------------- robert@464: robert@464: This sketch demonstrates how to log values from within a project for later processing or analysis. robert@464: robert@464: */ robert@464: