Mercurial > hg > beaglert
comparison core/RTAudio.cpp @ 539:b486344aa796 prerelease
merge
| author | Giulio Moro <giuliomoro@yahoo.it> |
|---|---|
| date | Fri, 24 Jun 2016 01:43:53 +0100 |
| parents | bfcbeb437869 |
| children |
comparison
equal
deleted
inserted
replaced
| 538:58652b93ef7e | 539:b486344aa796 |
|---|---|
| 165 cout << "Couldn't set value on amplifier mute pin\n"; | 165 cout << "Couldn't set value on amplifier mute pin\n"; |
| 166 return -1; | 166 return -1; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 if(settings->numAnalogInChannels != settings->numAnalogOutChannels){ | |
| 171 printf("Error: TODO: a different number of channels for inputs and outputs is not yet supported\n"); | |
| 172 return 1; | |
| 173 } | |
| 174 unsigned int numAnalogChannels = settings->numAnalogInChannels; | |
| 170 // Limit the analog channels to sane values | 175 // Limit the analog channels to sane values |
| 171 if(settings->numAnalogChannels != 2 | 176 if(numAnalogChannels != 2 |
| 172 && settings->numAnalogChannels != 4 | 177 && numAnalogChannels != 4 |
| 173 && settings->numAnalogChannels != 8) { | 178 && numAnalogChannels != 8) { |
| 174 cout << "Invalid number of analog channels: " << settings->numAnalogChannels << ". Valid values are 2, 4, 8.\n"; | 179 cout << "Invalid number of analog channels: " << numAnalogChannels << ". Valid values are 2, 4, 8.\n"; |
| 175 return -1; | 180 return -1; |
| 176 } | 181 } |
| 177 | 182 |
| 178 // Initialise the rendering environment: sample rates, frame counts, numbers of channels | 183 // Initialise the rendering environment: sample rates, frame counts, numbers of channels |
| 179 gContext.audioSampleRate = 44100.0; | 184 gContext.audioSampleRate = 44100.0; |
| 180 gContext.audioChannels = 2; | 185 |
| 186 // TODO: settings a different number of channels for inputs and outputs is not yet supported | |
| 187 gContext.audioInChannels = 2; | |
| 188 gContext.audioOutChannels = 2; | |
| 181 | 189 |
| 182 if(settings->useAnalog) { | 190 if(settings->useAnalog) { |
| 183 gContext.audioFrames = settings->periodSize; | 191 gContext.audioFrames = settings->periodSize; |
| 184 | 192 |
| 185 gContext.analogFrames = gContext.audioFrames * 4 / settings->numAnalogChannels; | 193 // TODO: a different number of channels for inputs and outputs is not yet supported |
| 186 gContext.analogChannels = settings->numAnalogChannels; | 194 gContext.analogFrames = gContext.audioFrames * 4 / settings->numAnalogInChannels; |
| 187 gContext.analogSampleRate = gContext.audioSampleRate * 4.0 / (float)settings->numAnalogChannels; | 195 gContext.analogInChannels = settings->numAnalogInChannels; |
| 196 gContext.analogOutChannels = settings->numAnalogOutChannels; | |
| 197 unsigned int numAnalogChannelsForSampleRate = settings->numAnalogInChannels; | |
| 198 gContext.analogSampleRate = gContext.audioSampleRate * 4.0 / (float)numAnalogChannelsForSampleRate; | |
| 188 } | 199 } |
| 189 else { | 200 else { |
| 190 gContext.audioFrames = settings->periodSize; | 201 gContext.audioFrames = settings->periodSize; |
| 191 | 202 |
| 192 gContext.analogFrames = 0; | 203 gContext.analogFrames = 0; |
| 193 gContext.analogChannels = 0; | 204 gContext.analogInChannels = 0; |
| 205 gContext.analogOutChannels = 0; | |
| 194 gContext.analogSampleRate = 0; | 206 gContext.analogSampleRate = 0; |
| 195 } | 207 } |
| 196 | 208 |
| 209 if(gContext.analogInChannels != gContext.analogOutChannels){ | |
| 210 printf("Error: TODO: a different number of channels for inputs and outputs is not yet supported\n"); | |
| 211 return -1; | |
| 212 } | |
| 213 unsigned int analogChannels = gContext.analogInChannels; | |
| 197 // Sanity check the combination of channels and period size | 214 // Sanity check the combination of channels and period size |
| 198 if( gContext.analogChannels != 0 && ((gContext.analogChannels <= 4 && gContext.analogFrames < 2) || | 215 if( analogChannels != 0 && ((analogChannels <= 4 && gContext.analogFrames < 2) || |
| 199 (gContext.analogChannels <= 2 && gContext.analogFrames < 4)) ) | 216 (analogChannels <= 2 && gContext.analogFrames < 4)) ) |
| 200 { | 217 { |
| 201 cout << "Error: " << gContext.analogChannels << " channels and period size of " << gContext.analogFrames << " not supported.\n"; | 218 cout << "Error: " << analogChannels << " channels and period size of " << gContext.analogFrames << " not supported.\n"; |
| 202 return 1; | 219 return 1; |
| 203 } | 220 } |
| 204 | 221 |
| 205 // For now, digital frame rate is equal to audio frame rate | 222 // For now, digital frame rate is equal to audio frame rate |
| 206 if(settings->useDigital) { | 223 if(settings->useDigital) { |
| 229 cout << "Error: unable to prepare GPIO for PRU audio\n"; | 246 cout << "Error: unable to prepare GPIO for PRU audio\n"; |
| 230 return 1; | 247 return 1; |
| 231 } | 248 } |
| 232 | 249 |
| 233 // Get the PRU memory buffers ready to go | 250 // Get the PRU memory buffers ready to go |
| 234 if(gPRU->initialise(settings->pruNumber, gContext.analogFrames, gContext.analogChannels, | 251 if(gContext.analogInChannels != gContext.analogOutChannels){ |
| 252 printf("Error: TODO: a different number of channels for inputs and outputs is not yet supported\n"); | |
| 253 return 1; | |
| 254 } | |
| 255 | |
| 256 if(gPRU->initialise(settings->pruNumber, gContext.analogFrames, analogChannels, | |
| 235 settings->numMuxChannels, true)) { | 257 settings->numMuxChannels, true)) { |
| 236 cout << "Error: unable to initialise PRU\n"; | 258 cout << "Error: unable to initialise PRU\n"; |
| 237 return 1; | 259 return 1; |
| 238 } | 260 } |
| 239 | 261 |
