Mercurial > hg > beaglert
comparison projects/scope/render.cpp @ 141:44d07fa9bd03 ClockSync
Ultra-basic feedback for clock sync works^CIssues: response time of the IIR filter is too slow, requires PID and better filtering algorithm.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 14 Sep 2015 15:42:11 +0100 |
parents | e77e2e712fbc |
children | 55c1e591cb2e |
comparison
equal
deleted
inserted
replaced
140:5edc6d0713ef | 141:44d07fa9bd03 |
---|---|
24 //ReceiveAudioThread receiveAudio1; | 24 //ReceiveAudioThread receiveAudio1; |
25 ClockSynchronizer clockSynchronizer; | 25 ClockSynchronizer clockSynchronizer; |
26 extern I2c_Codec* gAudioCodec; | 26 extern I2c_Codec* gAudioCodec; |
27 VirtualClock virtualClock; | 27 VirtualClock virtualClock; |
28 ClockSyncThread clockSyncThread; | 28 ClockSyncThread clockSyncThread; |
29 AuxiliaryTask testTime; | |
30 void testTimeFunction(){ | |
31 rt_printf("time=["); | |
32 while(!gShouldStop){ | |
33 rt_task_sleep(50000*1e3); | |
34 rt_printf("%f, ", virtualClock.getNow()); | |
35 rt_printf("%f, ", virtualClock.getPeriod()); | |
36 rt_task_sleep(20000); | |
37 rt_printf("%f,", virtualClock.getNow()); | |
38 rt_printf("%f\n", virtualClock.getPeriod()); | |
39 } | |
40 rt_printf("];"); | |
41 } | |
29 bool setup(BeagleRTContext *context, void *userData) | 42 bool setup(BeagleRTContext *context, void *userData) |
30 { | 43 { |
31 // receiveAudio0.init(10000, context->audioFrames, 0); | 44 // receiveAudio0.init(10000, context->audioFrames, 0); |
32 // receiveAudio1.init(10000, context->audioFrames, 1); | 45 // receiveAudio1.init(10000, context->audioFrames, 1); |
33 | 46 |
34 // scope.setup(); //call this once in setup to initialise the scope | 47 // scope.setup(); //call this once in setup to initialise the scope |
35 // scope.setPort(0, 9999); | 48 // scope.setPort(0, 9999); |
36 // scope.setPort(1, 10000); | 49 // scope.setPort(1, 10000); |
37 // networkSend.setup(context->audioSampleRate, context->audioFrames, 0, 9999, "192.168.7.1"); | 50 // networkSend.setup(context->audioSampleRate, context->audioFrames, 0, 9999, "192.168.7.1"); |
38 clockSynchronizer.setup(); | 51 // clockSynchronizer.setup(); |
39 virtualClock.init(); | 52 virtualClock.init(); |
40 clockSyncThread.init(true, 5000, virtualClock); //start as slave | 53 clockSyncThread.init(true, 5000, virtualClock); //start as slave |
41 gInverseSampleRate = 1.0/context->audioSampleRate; | 54 gInverseSampleRate = 1.0/context->audioSampleRate; |
42 | 55 |
43 gPhase1 = 0.0; | 56 gPhase1 = 0.0; |
44 gPhase2 = 0.0; | 57 gPhase2 = 0.0; |
45 | 58 |
46 gFrequency1 = 200.0; | 59 gFrequency1 = 200.0; |
47 gFrequency2 = 201.0; | 60 gFrequency2 = 201.0; |
48 | 61 |
62 // testTime=BeagleRT_createAuxiliaryTask(testTimeFunction, 80, "testTimeTask"); | |
49 return true; | 63 return true; |
50 } | 64 } |
51 | 65 |
52 // render() is called regularly at the highest priority by the audio engine. | 66 // render() is called regularly at the highest priority by the audio engine. |
53 // Input and output are given from the audio hardware and the other | 67 // Input and output are given from the audio hardware and the other |
56 | 70 |
57 void render(BeagleRTContext *context, void *userData) | 71 void render(BeagleRTContext *context, void *userData) |
58 { | 72 { |
59 virtualClock.sync(context->audioFrames); | 73 virtualClock.sync(context->audioFrames); |
60 static int count=0; | 74 static int count=0; |
61 if(count==0) | 75 if(count==0){ |
62 clockSyncThread.startThread(); | 76 // BeagleRT_scheduleAuxiliaryTask(testTime); |
77 clockSyncThread.startThread(); //make sure you uncomment .init in setup() | |
78 } | |
63 static float phase=0; | 79 static float phase=0; |
64 float phaseInc=200.0/44100.0*2*M_PI; | 80 float phaseInc=200.0/44100.0*2*M_PI; |
65 // rt_printf("phaseInc: %f, phase: %f\n",phaseInc,phase); | 81 // rt_printf("phaseInc: %f, phase: %f\n",phaseInc,phase); |
66 for(unsigned int n=0; n<context->audioFrames; n++){ | 82 for(unsigned int n=0; n<context->audioFrames; n++){ |
67 context->audioOut[n*2]=sinf(phaseInc);//context->audioIn[n*2]; | 83 context->audioOut[n*2]=sinf(phaseInc);//context->audioIn[n*2]; |