diff projects/scope/render.cpp @ 109:ad8a93cd7c39 scope-refactoring

Working for single-channel scope, or NetworkIO
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 18 Aug 2015 14:53:16 +0100
parents 2fe6690fcab7
children 9928b6366227
line wrap: on
line diff
--- a/projects/scope/render.cpp	Tue Aug 18 00:13:04 2015 +0100
+++ b/projects/scope/render.cpp	Tue Aug 18 14:53:16 2015 +0100
@@ -6,7 +6,7 @@
 float gFrequency1, gFrequency2;
 float gInverseSampleRate;
 
-Scope scope;    //create a scope object
+Scope scope(1);    //create a scope object with numChannels
 
 // initialise_render() is called once before the audio rendering starts.
 // Use it to perform any initialisation and allocation which is dependent
@@ -37,9 +37,10 @@
 
 void render(BeagleRTContext *context, void *userData)
 {
+	static int count=0;
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 	    
-	    float chn1 = sinf(gPhase1);
+		float chn1 = sinf(gPhase1);
 	    float chn2 = sinf(gPhase2);
 	    
 	    float chn3 = context->audioIn[n*2 + 0];
@@ -47,16 +48,17 @@
 	    
 	    float chn5 = context->analogIn[(int)n/2*8 + 0];
 	    float chn6 = context->analogIn[(int)n/2*8 + 1];
+		if((n&1)==0)
+		    scope.log(0, chn1);
 	    
 //	    scope.log(chn1, chn2, chn3, chn4, chn5, chn6);
-	    scope.log(chn1);
 	    //call this once every audio frame
 	    //takes six or fewer floats as parameters
 	    //first parameter becomes channel 1 etc
 	    //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running
 	    //then click the big red button on the toolbar on this page
 	    
-	    gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate;
+	    gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate * ((count&4095)/4096.0+1);
 	    gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate;
 		if(gPhase1 > 2.0 * M_PI)
 			gPhase1 -= 2.0 * M_PI;
@@ -64,6 +66,7 @@
 			gPhase2 -= 2.0 * M_PI;
 		
 	}
+	count++;
 }
 
 // cleanup_render() is called once at the end, after the audio has stopped.