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