Mercurial > hg > beaglert
comparison core/RTAudio.cpp @ 19:c98863e63174 matrix_gpio
Renamed matrixGpio to digital and matrix to analog
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 30 Apr 2015 16:58:41 +0100 |
parents | 670be80463a3 |
children | ad5cd8dd99b3 |
comparison
equal
deleted
inserted
replaced
18:31503d9de101 | 19:c98863e63174 |
---|---|
59 char *gPRUFilename;//[256] = "pru_rtaudio.bin"; // path to PRU binary file | 59 char *gPRUFilename;//[256] = "pru_rtaudio.bin"; // path to PRU binary file |
60 int gRTAudioVerbose = 0; // Verbosity level for debugging | 60 int gRTAudioVerbose = 0; // Verbosity level for debugging |
61 int gAmplifierMutePin = -1; | 61 int gAmplifierMutePin = -1; |
62 int gAmplifierShouldBeginMuted = 0; | 62 int gAmplifierShouldBeginMuted = 0; |
63 | 63 |
64 // Number of audio and matrix channels, globally accessible | 64 // Number of audio and analog channels, globally accessible |
65 // At least gNumMatrixChannels and gNumMatrixGpioChannels need to be global to be used | 65 // At least gNumAnalogChannels and gNumDigitalChannels need to be global to be used |
66 // by the analogRead() and analogWrite() and the digital macros without creating | 66 // by the AnalogRead() and AnalogWrite() and the digital macros without creating |
67 // extra confusion in their use cases by passing this argument | 67 // extra confusion in their use cases by passing this argument |
68 int gNumAudioChannels = 0; | 68 int gNumAudioChannels = 0; |
69 int gNumMatrixChannels = 0; | 69 int gNumAnalogChannels = 0; |
70 int gNumMatrixGpioChannels = 0; | 70 int gNumDigitalChannels = 0; |
71 | 71 |
72 // initAudio() prepares the infrastructure for running PRU-based real-time | 72 // initAudio() prepares the infrastructure for running PRU-based real-time |
73 // audio, but does not actually start the calculations. | 73 // audio, but does not actually start the calculations. |
74 // periodSize indicates the number of _sensor_ frames per period: the audio period size | 74 // periodSize indicates the number of _sensor_ frames per period: the audio period size |
75 // is twice this value. In total, the audio latency in frames will be 4*periodSize, | 75 // is twice this value. In total, the audio latency in frames will be 4*periodSize, |
76 // plus any latency inherent in the ADCs and DACs themselves. | 76 // plus any latency inherent in the ADCs and DACs themselves. |
77 // useMatrix indicates whether to enable the ADC and DAC or just use the audio codec. | 77 // useAnalog indicates whether to enable the ADC and DAC or just use the audio codec. |
78 // numMatrixChannels indicates how many ADC and DAC channels to use. | 78 // numAnalogChannels indicates how many ADC and DAC channels to use. |
79 // userData is an opaque pointer which will be passed through to the initialise_render() | 79 // userData is an opaque pointer which will be passed through to the initialise_render() |
80 // function for application-specific use | 80 // function for application-specific use |
81 // | 81 // |
82 // Returns 0 on success. | 82 // Returns 0 on success. |
83 | 83 |
89 if(gRTAudioVerbose == 1) | 89 if(gRTAudioVerbose == 1) |
90 rt_printf("Running with Xenomai\n"); | 90 rt_printf("Running with Xenomai\n"); |
91 | 91 |
92 if(gRTAudioVerbose) { | 92 if(gRTAudioVerbose) { |
93 cout << "Starting with period size " << settings->periodSize << "; "; | 93 cout << "Starting with period size " << settings->periodSize << "; "; |
94 if(settings->useMatrix) | 94 if(settings->useAnalog) |
95 cout << "matrix enabled\n"; | 95 cout << "analog enabled\n"; |
96 else | 96 else |
97 cout << "matrix disabled\n"; | 97 cout << "analog disabled\n"; |
98 cout << "DAC level " << settings->dacLevel << "dB; ADC level " << settings->adcLevel; | 98 cout << "DAC level " << settings->dacLevel << "dB; ADC level " << settings->adcLevel; |
99 cout << "dB; headphone level " << settings->headphoneLevel << "dB\n"; | 99 cout << "dB; headphone level " << settings->headphoneLevel << "dB\n"; |
100 if(settings->beginMuted) | 100 if(settings->beginMuted) |
101 cout << "Beginning with speaker muted\n"; | 101 cout << "Beginning with speaker muted\n"; |
102 } | 102 } |
120 cout << "Couldn't set value on amplifier mute pin\n"; | 120 cout << "Couldn't set value on amplifier mute pin\n"; |
121 return -1; | 121 return -1; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 // Limit the matrix channels to sane values | 125 // Limit the analog channels to sane values |
126 if(settings->numMatrixChannels >= 8) | 126 if(settings->numAnalogChannels >= 8) |
127 settings->numMatrixChannels = 8; | 127 settings->numAnalogChannels = 8; |
128 else if(settings->numMatrixChannels >= 4) | 128 else if(settings->numAnalogChannels >= 4) |
129 settings->numMatrixChannels = 4; | 129 settings->numAnalogChannels = 4; |
130 else | 130 else |
131 settings->numMatrixChannels = 2; | 131 settings->numAnalogChannels = 2; |
132 | 132 |
133 // Sanity check the combination of channels and period size | 133 // Sanity check the combination of channels and period size |
134 if(settings->numMatrixChannels <= 4 && settings->periodSize < 2) { | 134 if(settings->numAnalogChannels <= 4 && settings->periodSize < 2) { |
135 cout << "Error: " << settings->numMatrixChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; | 135 cout << "Error: " << settings->numAnalogChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; |
136 return 1; | 136 return 1; |
137 } | 137 } |
138 if(settings->numMatrixChannels <= 2 && settings->periodSize < 4) { | 138 if(settings->numAnalogChannels <= 2 && settings->periodSize < 4) { |
139 cout << "Error: " << settings->numMatrixChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; | 139 cout << "Error: " << settings->numAnalogChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; |
140 return 1; | 140 return 1; |
141 } | 141 } |
142 | 142 |
143 // Use PRU for audio | 143 // Use PRU for audio |
144 gPRU = new PRU(); | 144 gPRU = new PRU(); |
145 gAudioCodec = new I2c_Codec(); | 145 gAudioCodec = new I2c_Codec(); |
146 | 146 |
147 gNumMatrixGpioChannels = settings->useMatrixGpio ? settings->numMatrixGpioChannels : 0; //this is called here to make sure prepareGPIO initializes the appropriate GPIO pins | 147 gNumDigitalChannels = settings->useDigital ? settings->numDigitalChannels : 0; //this is called here to make sure prepareGPIO initializes the appropriate GPIO pins |
148 if(gPRU->prepareGPIO(settings->useMatrix, settings->useMatrixGpio, 1, 1)) { | 148 if(gPRU->prepareGPIO(settings->useAnalog, settings->useDigital, 1, 1)) { |
149 cout << "Error: unable to prepare GPIO for PRU audio\n"; | 149 cout << "Error: unable to prepare GPIO for PRU audio\n"; |
150 return 1; | 150 return 1; |
151 } | 151 } |
152 if(gPRU->initialise(0, settings->periodSize, settings->numMatrixChannels, true)) { | 152 if(gPRU->initialise(0, settings->periodSize, settings->numAnalogChannels, true)) { |
153 cout << "Error: unable to initialise PRU\n"; | 153 cout << "Error: unable to initialise PRU\n"; |
154 return 1; | 154 return 1; |
155 } | 155 } |
156 if(gAudioCodec->initI2C_RW(2, settings->codecI2CAddress, -1)) { | 156 if(gAudioCodec->initI2C_RW(2, settings->codecI2CAddress, -1)) { |
157 cout << "Unable to open codec I2C\n"; | 157 cout << "Unable to open codec I2C\n"; |
165 // Set default volume levels | 165 // Set default volume levels |
166 BeagleRT_setDACLevel(settings->dacLevel); | 166 BeagleRT_setDACLevel(settings->dacLevel); |
167 BeagleRT_setADCLevel(settings->adcLevel); | 167 BeagleRT_setADCLevel(settings->adcLevel); |
168 BeagleRT_setHeadphoneLevel(settings->headphoneLevel); | 168 BeagleRT_setHeadphoneLevel(settings->headphoneLevel); |
169 | 169 |
170 // Initialise the rendering environment: pass the number of audio and matrix | 170 // Initialise the rendering environment: pass the number of audio and analog |
171 // channels, the period size for matrix and audio, and the sample rates | 171 // channels, the period size for analog and audio, and the sample rates |
172 | 172 |
173 int audioPeriodSize = settings->periodSize * 2; | 173 int audioPeriodSize = settings->periodSize * 2; |
174 float audioSampleRate = 44100.0; | 174 float audioSampleRate = 44100.0; |
175 float matrixSampleRate = 22050.0; | 175 float analogSampleRate = 22050.0; |
176 if(settings->useMatrix) { | 176 if(settings->useAnalog) { |
177 audioPeriodSize = settings->periodSize * settings->numMatrixChannels / 4; | 177 audioPeriodSize = settings->periodSize * settings->numAnalogChannels / 4; |
178 matrixSampleRate = audioSampleRate * 4.0 / (float)settings->numMatrixChannels; | 178 analogSampleRate = audioSampleRate * 4.0 / (float)settings->numAnalogChannels; |
179 } | 179 } |
180 | 180 |
181 gNumAudioChannels = 2; | 181 gNumAudioChannels = 2; |
182 gNumMatrixChannels = settings->useMatrix ? settings->numMatrixChannels : 0; | 182 gNumAnalogChannels = settings->useAnalog ? settings->numAnalogChannels : 0; |
183 if(!initialise_render(gNumMatrixChannels, gNumMatrixGpioChannels, gNumAudioChannels, | 183 if(!initialise_render(gNumAnalogChannels, gNumDigitalChannels, gNumAudioChannels, |
184 settings->useMatrix ? settings->periodSize : 0, /* matrix period size */ | 184 settings->useAnalog ? settings->periodSize : 0, /* analog period size */ |
185 audioPeriodSize, | 185 audioPeriodSize, |
186 matrixSampleRate, audioSampleRate, | 186 analogSampleRate, audioSampleRate, |
187 userData)) { | 187 userData)) { |
188 cout << "Couldn't initialise audio rendering\n"; | 188 cout << "Couldn't initialise audio rendering\n"; |
189 return 1; | 189 return 1; |
190 } | 190 } |
191 | 191 |