Mercurial > hg > beaglert
comparison core/RTAudio.cpp @ 50:be427da6fb9c newapi
Removed old testing code that stopped audio after 10 seconds; command line parameter updates; D-Box updates (not fully working yet)
| author | andrewm | 
|---|---|
| date | Sat, 30 May 2015 12:34:32 -0500 | 
| parents | 643cbee74eda | 
| children | 3c3a1357657d | 
   comparison
  equal
  deleted
  inserted
  replaced
| 49:bb40e7e06b8c | 50:be427da6fb9c | 
|---|---|
| 50 const char gRTAudioThreadName[] = "beaglert-audio"; | 50 const char gRTAudioThreadName[] = "beaglert-audio"; | 
| 51 const char gRTAudioInterruptName[] = "beaglert-pru-irq"; | 51 const char gRTAudioInterruptName[] = "beaglert-pru-irq"; | 
| 52 | 52 | 
| 53 // Real-time tasks and objects | 53 // Real-time tasks and objects | 
| 54 RT_TASK gRTAudioThread; | 54 RT_TASK gRTAudioThread; | 
| 55 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS | |
| 55 RT_INTR gRTAudioInterrupt; | 56 RT_INTR gRTAudioInterrupt; | 
| 57 #endif | |
| 56 PRU *gPRU = 0; | 58 PRU *gPRU = 0; | 
| 57 I2c_Codec *gAudioCodec = 0; | 59 I2c_Codec *gAudioCodec = 0; | 
| 58 | 60 | 
| 59 vector<InternalAuxiliaryTask*> gAuxTasks; | 61 vector<InternalAuxiliaryTask*> gAuxTasks; | 
| 60 | 62 | 
| 255 if(gRTAudioVerbose) | 257 if(gRTAudioVerbose) | 
| 256 rt_printf("Warning: couldn't set value (high) on amplifier mute pin\n"); | 258 rt_printf("Warning: couldn't set value (high) on amplifier mute pin\n"); | 
| 257 } | 259 } | 
| 258 } | 260 } | 
| 259 | 261 | 
| 262 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS | |
| 260 gPRU->loop(&gRTAudioInterrupt, gUserData); | 263 gPRU->loop(&gRTAudioInterrupt, gUserData); | 
| 261 | 264 #else | 
| 265 gPRU->loop(0, gUserData); | |
| 266 #endif | |
| 262 // Now clean up | 267 // Now clean up | 
| 263 // gPRU->waitForFinish(); | 268 // gPRU->waitForFinish(); | 
| 264 gPRU->disable(); | 269 gPRU->disable(); | 
| 265 gAudioCodec->stopAudio(); | 270 gAudioCodec->stopAudio(); | 
| 266 gPRU->cleanupGPIO(); | 271 gPRU->cleanupGPIO(); | 
| 339 if(rt_task_create(&gRTAudioThread, gRTAudioThreadName, 0, BEAGLERT_AUDIO_PRIORITY, T_JOINABLE | T_FPU)) { | 344 if(rt_task_create(&gRTAudioThread, gRTAudioThreadName, 0, BEAGLERT_AUDIO_PRIORITY, T_JOINABLE | T_FPU)) { | 
| 340 cout << "Error: unable to create Xenomai audio thread" << endl; | 345 cout << "Error: unable to create Xenomai audio thread" << endl; | 
| 341 return -1; | 346 return -1; | 
| 342 } | 347 } | 
| 343 | 348 | 
| 349 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS | |
| 344 // Create an interrupt which the audio thread receives from the PRU | 350 // Create an interrupt which the audio thread receives from the PRU | 
| 345 int result = 0; | 351 int result = 0; | 
| 346 if((result = rt_intr_create(&gRTAudioInterrupt, gRTAudioInterruptName, PRU_RTAUDIO_IRQ, I_NOAUTOENA)) != 0) { | 352 if((result = rt_intr_create(&gRTAudioInterrupt, gRTAudioInterruptName, PRU_RTAUDIO_IRQ, I_NOAUTOENA)) != 0) { | 
| 347 cout << "Error: unable to create Xenomai interrupt for PRU (error " << result << ")" << endl; | 353 cout << "Error: unable to create Xenomai interrupt for PRU (error " << result << ")" << endl; | 
| 348 return -1; | 354 return -1; | 
| 349 } | 355 } | 
| 356 #endif | |
| 350 | 357 | 
| 351 // Start all RT threads | 358 // Start all RT threads | 
| 352 if(rt_task_start(&gRTAudioThread, &audioLoop, 0)) { | 359 if(rt_task_start(&gRTAudioThread, &audioLoop, 0)) { | 
| 353 cout << "Error: unable to start Xenomai audio thread" << endl; | 360 cout << "Error: unable to start Xenomai audio thread" << endl; | 
| 354 return -1; | 361 return -1; | 
| 411 free(taskStruct); | 418 free(taskStruct); | 
| 412 } | 419 } | 
| 413 gAuxTasks.clear(); | 420 gAuxTasks.clear(); | 
| 414 | 421 | 
| 415 // Delete the audio task and its interrupt | 422 // Delete the audio task and its interrupt | 
| 423 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS | |
| 416 rt_intr_delete(&gRTAudioInterrupt); | 424 rt_intr_delete(&gRTAudioInterrupt); | 
| 425 #endif | |
| 417 rt_task_delete(&gRTAudioThread); | 426 rt_task_delete(&gRTAudioThread); | 
| 418 | 427 | 
| 419 if(gPRU != 0) | 428 if(gPRU != 0) | 
| 420 delete gPRU; | 429 delete gPRU; | 
| 421 if(gAudioCodec != 0) | 430 if(gAudioCodec != 0) | 
