Mercurial > hg > beaglert
comparison projects/basic_network/render.cpp @ 24:ad5cd8dd99b3 bbb_network
UDP communication in place, pre-alpha
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 08 May 2015 11:12:13 +0100 |
parents | |
children | 98aed580452a |
comparison
equal
deleted
inserted
replaced
23:182ae9367104 | 24:ad5cd8dd99b3 |
---|---|
1 /* | |
2 * render.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include "../../include/RTAudioSettings.h" | |
9 #include "../../include/render.h" | |
10 #include <cmath> | |
11 #include "../../include/client.h" | |
12 #include "../../include/RTAudio.h" // to schedule lower prio parallel process | |
13 #include <rtdk.h> | |
14 float gFrequency; | |
15 float gPhase; | |
16 float gInverseSampleRate; | |
17 int gCount=0; | |
18 networkData networkObject; | |
19 AuxiliaryTask transmitReceiveDataTask; | |
20 | |
21 void transmitReceiveData(){ | |
22 printf("transmitAndReceiveData\n"); | |
23 while(!gShouldStop){ | |
24 //sendMessage(networkObject); | |
25 //receiveMessage(networkObject); | |
26 usleep(10000); | |
27 } | |
28 closeSockets(); | |
29 } | |
30 | |
31 // initialise_render() is called once before the audio rendering starts. | |
32 // Use it to perform any initialisation and allocation which is dependent | |
33 // on the period size or sample rate. | |
34 // | |
35 // userData holds an opaque pointer to a data structure that was passed | |
36 // in from the call to initAudio(). | |
37 // | |
38 // Return true on success; returning false halts the program. | |
39 bool initialise_render(int numMatrixChannels, int numDigitalChannels, int numAudioChannels, | |
40 int numMatrixFramesPerPeriod, | |
41 int numAudioFramesPerPeriod, | |
42 float matrixSampleRate, float audioSampleRate, | |
43 void *userData, RTAudioSettings *settings) | |
44 { | |
45 // Retrieve a parameter passed in from the initAudio() call | |
46 gFrequency = *(float *)userData; | |
47 | |
48 gInverseSampleRate = 1.0 / audioSampleRate; | |
49 gPhase = 0.0; | |
50 | |
51 networkObject.counter=&gCount; | |
52 networkObject.variables[0]=&gFrequency; | |
53 networkObject.variables[1]=&gPhase; | |
54 networkObject.numVariables=2; | |
55 setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); | |
56 transmitReceiveDataTask=createAuxiliaryTaskLoop(*transmitReceiveData, 50, "transmit-receive-data"); | |
57 //scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work | |
58 return true; | |
59 } | |
60 | |
61 // 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 | |
63 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
64 // will be 0. | |
65 | |
66 void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, | |
67 float *analogIn, float *analogOut, uint32_t *digital) | |
68 { | |
69 for(int n = 0; n < numAudioFrames; n++) { | |
70 float out = 0.7f * sinf(gPhase); | |
71 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | |
72 if(gPhase > 2.0 * M_PI) | |
73 gPhase -= 2.0 * M_PI; | |
74 | |
75 for(int channel = 0; channel < gNumAudioChannels; channel++) | |
76 audioOut[n * gNumAudioChannels + channel] = out; | |
77 if(gCount==0){ | |
78 scheduleAuxiliaryTask(transmitReceiveDataTask); | |
79 } | |
80 gCount++; | |
81 } | |
82 } | |
83 | |
84 // cleanup_render() is called once at the end, after the audio has stopped. | |
85 // Release any resources that were allocated in initialise_render(). | |
86 | |
87 void cleanup_render() | |
88 { | |
89 } |