Mercurial > hg > beaglert
comparison projects/basic/render.cpp @ 13:6adb088196a7
Fixed ADC bug; added a simple passthrough test
author | andrewm |
---|---|
date | Fri, 23 Jan 2015 15:17:09 +0000 |
parents | a6beeba3a648 |
children | ad5cd8dd99b3 |
comparison
equal
deleted
inserted
replaced
12:a6beeba3a648 | 13:6adb088196a7 |
---|---|
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 float gFrequency; | 12 float gFrequency; |
13 float gPhase; | 13 float gPhase; |
14 float gInverseSampleRate; | 14 float gInverseSampleRate; |
15 int gNumChannels; | |
16 | 15 |
17 // initialise_render() is called once before the audio rendering starts. | 16 // initialise_render() is called once before the audio rendering starts. |
18 // Use it to perform any initialisation and allocation which is dependent | 17 // Use it to perform any initialisation and allocation which is dependent |
19 // on the period size or sample rate. | 18 // on the period size or sample rate. |
20 // | 19 // |
30 void *userData) | 29 void *userData) |
31 { | 30 { |
32 // Retrieve a parameter passed in from the initAudio() call | 31 // Retrieve a parameter passed in from the initAudio() call |
33 gFrequency = *(float *)userData; | 32 gFrequency = *(float *)userData; |
34 | 33 |
35 gNumChannels = numAudioChannels; | |
36 gInverseSampleRate = 1.0 / audioSampleRate; | 34 gInverseSampleRate = 1.0 / audioSampleRate; |
37 gPhase = 0.0; | 35 gPhase = 0.0; |
38 | 36 |
39 return true; | 37 return true; |
40 } | 38 } |
51 float out = 0.8f * sinf(gPhase); | 49 float out = 0.8f * sinf(gPhase); |
52 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | 50 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; |
53 if(gPhase > 2.0 * M_PI) | 51 if(gPhase > 2.0 * M_PI) |
54 gPhase -= 2.0 * M_PI; | 52 gPhase -= 2.0 * M_PI; |
55 | 53 |
56 for(int channel = 0; channel < gNumChannels; channel++) | 54 for(int channel = 0; channel < gNumAudioChannels; channel++) |
57 audioOut[n * gNumChannels + channel] = out; | 55 audioOut[n * gNumAudioChannels + channel] = out; |
58 } | 56 } |
59 } | 57 } |
60 | 58 |
61 // cleanup_render() is called once at the end, after the audio has stopped. | 59 // cleanup_render() is called once at the end, after the audio has stopped. |
62 // Release any resources that were allocated in initialise_render(). | 60 // Release any resources that were allocated in initialise_render(). |