Skip to content
Browse files

Merge pull request #1880 from cerupcat/master

Fixed sound not restarting after an interupttion (phone call or alarm clock)
  • Loading branch information...
2 parents eb45d59 + fe534e2 commit 2d62d2e13f68bc02646e756dcaa40675e6a73823 @ofTheo ofTheo committed Mar 9, 2013
View
5 addons/ofxiPhone/src/sound/ofxiPhoneSoundStream.h
@@ -4,6 +4,7 @@
#include "ofBaseSoundStream.h"
#include "ofTypes.h"
+#import <AudioToolbox/AudioToolbox.h>
class ofxiPhoneSoundStream : public ofBaseSoundStream{
@@ -32,7 +33,9 @@ class ofxiPhoneSoundStream : public ofBaseSoundStream{
int getNumInputChannels();
int getNumOutputChannels();
-
+
+ static AudioUnit audioUnit;
+
private:
long unsigned long tickCount;
int nInputChannels;
View
20 addons/ofxiPhone/src/sound/ofxiPhoneSoundStream.mm
@@ -24,7 +24,7 @@
static bool isSetup = false;
static bool isRunning = false;
AudioStreamBasicDescription format, audioFormat;
-AudioUnit audioUnit = NULL;
+AudioUnit ofxiPhoneSoundStream::audioUnit = NULL;
AudioBufferList inputBufferList; // input buffer
static ofBaseSoundInput * soundInputPtr = NULL;
static ofBaseSoundOutput * soundOutputPtr = NULL;
@@ -68,10 +68,22 @@ bool checkStatus(OSStatus error) {
// called when the audio system is interrupted (backgrounded, etc)
static void rioInterruptionListener(void *inClientData, UInt32 inInterruption) {
- if(inInterruption == kAudioSessionBeginInterruption)
+ ofxiPhoneSoundStream * rio = (ofxiPhoneSoundStream *)inClientData;
+
+ if(inInterruption == kAudioSessionBeginInterruption){
ofLog(OF_LOG_VERBOSE, "ofxiPhoneSoundStream: Audio session interrupted");
- else if(inInterruption == kAudioSessionEndInterruption)
+
+ AudioOutputUnitStop( rio->audioUnit );
+ }
+ else if(inInterruption == kAudioSessionEndInterruption){
ofLog(OF_LOG_VERBOSE, "ofxiPhoneSoundStream: Audio session resumed");
+
+ if(isRunning){
+ // make sure we are again the active session
+ AudioSessionSetActive( true );
+ AudioOutputUnitStart( rio->audioUnit );
+ }
+ }
}
static OSStatus playbackCallback(void *inRefCon,
@@ -123,7 +135,7 @@ static OSStatus recordingCallback(void *inRefCon,
ioData = &inputBufferList;
// obtain recorded samples
- OSStatus status = AudioUnitRender(audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
+ OSStatus status = AudioUnitRender(ofxiPhoneSoundStream::audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
if(checkStatus(status)) {
ofLog(OF_LOG_ERROR, "ofxiPhoneSoundStream: Couldn't render input audio samples");
return status;

0 comments on commit 2d62d2e

Please sign in to comment.
Something went wrong with that request. Please try again.