Mercurial > hg > beaglert
comparison projects/basic_network/render.cpp @ 41:4255ecbb9bec ultra-staging
Timers to measure performances, ultra experimental
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 19 May 2015 16:41:07 +0100 |
parents | 98aed580452a |
children | d3f869b98147 |
comparison
equal
deleted
inserted
replaced
40:419ce4ebfc4c | 41:4255ecbb9bec |
---|---|
9 #include "../../include/render.h" | 9 #include "../../include/render.h" |
10 #include <cmath> | 10 #include <cmath> |
11 #include "../../include/client.h" | 11 #include "../../include/client.h" |
12 #include "../../include/RTAudio.h" // to schedule lower prio parallel process | 12 #include "../../include/RTAudio.h" // to schedule lower prio parallel process |
13 #include <rtdk.h> | 13 #include <rtdk.h> |
14 #include <native/timer.h> | |
15 #include "../../include/PRU.h" | |
14 float gFrequency; | 16 float gFrequency; |
15 float gPhase; | 17 float gPhase; |
16 float gInverseSampleRate; | 18 float gInverseSampleRate; |
17 int gCount=0; | 19 int gCount=0; |
18 networkData networkObject; | 20 networkData networkObject; |
19 AuxiliaryTask transmitReceiveDataTask; | 21 networkAudio netAudio; |
22 extern PRU *gPRU; | |
23 AuxiliaryTask printIntervalTask; | |
24 AuxiliaryTask transmitReceiveAudioTask; | |
25 void transmitReceiveData(){ //transmit and receive asynchronous messages | |
26 // printf("transmitReceiveData auxiliary task has started\n"); | |
27 // while(!gShouldStop){ | |
28 // sendMessage(&networkObject); | |
29 // receiveMessage(networkObject); | |
30 // usleep(1000); | |
31 // } | |
32 // closeSockets(); | |
33 } | |
20 | 34 |
21 void transmitReceiveData(){ | 35 void transmitReceiveAudio(){ //transmit and receive audio buffers |
22 printf("transmitReceiveData auxiliary task has started\n"); | 36 sendAudio(&netAudio); |
23 while(!gShouldStop){ | |
24 sendMessage(networkObject); | |
25 receiveMessage(networkObject); | |
26 usleep(1000); | |
27 } | |
28 closeSockets(); | |
29 } | 37 } |
38 | |
30 | 39 |
31 // initialise_render() is called once before the audio rendering starts. | 40 // initialise_render() is called once before the audio rendering starts. |
32 // Use it to perform any initialisation and allocation which is dependent | 41 // Use it to perform any initialisation and allocation which is dependent |
33 // on the period size or sample rate. | 42 // on the period size or sample rate. |
34 // | 43 // |
46 gFrequency = *(float *)userData; | 55 gFrequency = *(float *)userData; |
47 | 56 |
48 gInverseSampleRate = 1.0 / audioSampleRate; | 57 gInverseSampleRate = 1.0 / audioSampleRate; |
49 gPhase = 0.0; | 58 gPhase = 0.0; |
50 | 59 |
51 networkObject.counter=&gCount; | 60 // networkObject.counter=&gCount; |
52 networkObject.variables[0]=&gFrequency; | 61 // networkObject.variables[0]=&gFrequency; |
53 networkObject.variables[1]=&gPhase; | 62 // networkObject.variables[1]=&gPhase; |
54 networkObject.numVariables=2; | 63 // networkObject.numVariables=2; |
55 setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); | 64 // netAudio.doneOnTime=1; |
56 transmitReceiveDataTask=createAuxiliaryTaskLoop(*transmitReceiveData, 80, "transmit-receive-data"); | 65 // netAudio.index=0; |
57 //scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work | 66 // netAudio.currentBuffer=0; |
67 // setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); | |
68 //// transmitReceiveDataTask=createAuxiliaryTaskLoop(*transmitReceiveData, 10, "transmit-receive-data"); | |
69 //// scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work | |
70 // transmitReceiveAudioTask=createAuxiliaryTaskLoop(*transmitReceiveAudio, 98, "transmit-receive-audio"); | |
58 return true; | 71 return true; |
59 } | 72 } |
60 | 73 |
61 // render() is called regularly at the highest priority by the audio engine. | 74 // render() is called regularly at the highest priority by the audio engine. |
62 // Input and output are given from the audio hardware and the other | 75 // Input and output are given from the audio hardware and the other |
66 void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, | 79 void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, |
67 float *analogIn, float *analogOut, uint32_t *digital) | 80 float *analogIn, float *analogOut, uint32_t *digital) |
68 { | 81 { |
69 for(int n = 0; n < numAudioFrames; n++) { | 82 for(int n = 0; n < numAudioFrames; n++) { |
70 float out = 0.7f * sinf(gPhase); | 83 float out = 0.7f * sinf(gPhase); |
84 float fake=0.1; | |
85 for(int a=0; a<24; a++){ | |
86 fake = 0.7f * sinf(fake+out); | |
87 } | |
88 fake/=1000000000000000; | |
71 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | 89 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; |
72 if(gPhase > 2.0 * M_PI) | 90 if(gPhase > 2.0 * M_PI) |
73 gPhase -= 2.0 * M_PI; | 91 gPhase -= 2.0 * M_PI; |
74 | 92 |
75 for(int channel = 0; channel < gNumAudioChannels; channel++) | 93 // for(int channel = 0; channel < gNumAudioChannels; channel++) |
76 audioOut[n * gNumAudioChannels + channel] = out; | 94 // audioOut[n * gNumAudioChannels + channel] = audioIn[n * gNumAudioChannels + 0]+audioIn[n * gNumAudioChannels + 1]; |
77 if(gCount==0){ | 95 audioOut[n * gNumAudioChannels] = fake*0.0000000001; |
78 scheduleAuxiliaryTask(transmitReceiveDataTask); | 96 audioOut[n * gNumAudioChannels+1]=out; |
97 if(0==gCount){ | |
98 // scheduleAuxiliaryTask(transmitReceiveDataTask); | |
79 } | 99 } |
100 // if(netAudio.index==(NETWORK_AUDIO_BUFFER_SIZE)){ // when the buffer is ready ... | |
101 // netAudio.index=0; //reset the counter | |
102 // if(netAudio.doneOnTime==0) | |
103 // rt_printf("Network buffer underrun :-{\n"); | |
104 // netAudio.timestamp=gCount; | |
105 // netAudio.currentBuffer=!netAudio.currentBuffer; //switch buffer | |
106 // netAudio.doneOnTime=0; | |
107 // scheduleAuxiliaryTask(transmitReceiveAudioTask); //send the buffer | |
108 // } | |
109 // netAudio.buffers[netAudio.currentBuffer][netAudio.index++]=audioOut[n*gNumAudioChannels + 0];//copy channel 0 to the buffer | |
80 gCount++; | 110 gCount++; |
81 } | 111 } |
82 } | 112 } |
83 | 113 |
84 // cleanup_render() is called once at the end, after the audio has stopped. | 114 // cleanup_render() is called once at the end, after the audio has stopped. |
85 // Release any resources that were allocated in initialise_render(). | 115 // Release any resources that were allocated in initialise_render(). |
86 | 116 |
87 void cleanup_render() | 117 void cleanup_render() |
88 { | 118 { |
119 // closeSockets(); | |
89 } | 120 } |