Mercurial > hg > beaglert
comparison projects/scope/undefined @ 94:2fe6690fcab7
Added scope project, copied and edited from nodejsbeaglert
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 22 Jul 2015 11:38:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
93:8c7f537d0a21 | 94:2fe6690fcab7 |
---|---|
1 /* | |
2 * render.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include <BeagleRT.h> | |
9 #include <cmath> | |
10 #include <client.h> | |
11 | |
12 float gFrequency; | |
13 float gPhase; | |
14 float gInverseSampleRate; | |
15 int gCount=0; | |
16 networkData networkObject; | |
17 AuxiliaryTask transmitReceiveDataTask; | |
18 | |
19 void transmitReceiveData(){ | |
20 printf("transmitReceiveData auxiliary task has started\n"); | |
21 while(!gShouldStop){ | |
22 sendMessage(networkObject); | |
23 receiveMessage(networkObject); | |
24 usleep(1000); | |
25 } | |
26 closeSockets(); | |
27 } | |
28 | |
29 // setup() is called once before the audio rendering starts. | |
30 // Use it to perform any initialisation and allocation which is dependent | |
31 // on the period size or sample rate. | |
32 // | |
33 // userData holds an opaque pointer to a data structure that was passed | |
34 // in from the call to initAudio(). | |
35 // | |
36 // Return true on success; returning false halts the program. | |
37 bool setup(BeagleRTContext *context, void *userData) | |
38 { | |
39 // Retrieve a parameter passed in from the initAudio() call | |
40 gFrequency = *(float *)userData; | |
41 | |
42 gInverseSampleRate = 1.0 / context->audioSampleRate; | |
43 gPhase = 0.0; | |
44 | |
45 networkObject.counter=&gCount; | |
46 networkObject.variables[0]=&gFrequency; | |
47 networkObject.variables[1]=&gPhase; | |
48 networkObject.numVariables=2; | |
49 | |
50 setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); | |
51 transmitReceiveDataTask= BeagleRT_createAuxiliaryTask(*transmitReceiveData, 80, "transmit-receive-data"); | |
52 //scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work | |
53 return true; | |
54 } | |
55 | |
56 // render() is called regularly at the highest priority by the audio engine. | |
57 // Input and output are given from the audio hardware and the other | |
58 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
59 // will be 0. | |
60 | |
61 void render(BeagleRTContext *context, void *userData) | |
62 { | |
63 for(unsigned int n = 0; n < context->audioFrames; n++) { | |
64 float out = 0.7f * sinf(gPhase); | |
65 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | |
66 if(gPhase > 2.0 * M_PI) | |
67 gPhase -= 2.0 * M_PI; | |
68 | |
69 for(unsigned int channel = 0; channel < context->audioChannels; channel++) | |
70 context->audioOut[n * context->audioChannels + channel] = out; | |
71 | |
72 if(gCount == 0){ | |
73 BeagleRT_scheduleAuxiliaryTask(transmitReceiveDataTask); | |
74 } | |
75 gCount++; | |
76 } | |
77 } | |
78 | |
79 // cleanup() is called once at the end, after the audio has stopped. | |
80 // Release any resources that were allocated in setup(). | |
81 | |
82 void cleanup(BeagleRTContext *context, void *userData) | |
83 { | |
84 } |