fresla
January 25, 2023, 3:14am
#1
I am trying to mobe to nightlies as suggested by the forum post, I want to use sound input for iOS, but there is an issue I dont understand.
When the bool ofxiOSSoundStream::setup(const ofSoundStreamSettings & settings)
function runs it has an error:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x464630b96110)
On this line:
[(__bridge SoundInputStream *)soundInputStream start];
Does anyone have any clues as to how to solve this?
theo
January 26, 2023, 3:06am
#2
Ahh I wonder if its a permissions issue with the plist - you might need to add the microphone capability as described here:
fresla
January 26, 2023, 5:26am
#3
Seemingly the plist does nto trigger a request for access, I had to add some code do do that, I tried in a few ways but something like this worked:
bool ofxiOSSoundStream::setup(const ofSoundStreamSettings & settings) {
close();
microphonePermissionGranted = false;
AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];
if (permissionStatus == AVAudioSessionRecordPermissionGranted) {
microphonePermissionGranted = true;
ofLogVerbose("ofxiOSSoundStream") << "Has mic permission";
} else if (permissionStatus == AVAudioSessionRecordPermissionDenied) {
microphonePermissionGranted = false;
ofLogVerbose("ofxiOSSoundStream") << "No mic permission";
} else {
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession requestRecordPermission:^(BOOL granted) {
microphonePermissionGranted = granted;
ofLogVerbose("ofxiOSSoundStream") << "Asked for and got mic permission";
}];
}
if(microphonePermissionGranted) {
this->settings = settings;
if(settings.numInputChannels > 0) {
soundInputStream = (__bridge void *)[[SoundInputStream alloc] initWithNumOfChannels:settings.numInputChannels
withSampleRate:settings.sampleRate
withBufferSize:settings.bufferSize];
ofxiOSSoundStreamDelegate * delegate = [[ofxiOSSoundStreamDelegate alloc] initWithSoundInputFn:settings.inCallback];
((__bridge SoundInputStream *)soundInputStream).delegate = delegate;
[(__bridge SoundInputStream *)soundInputStream start];
}
if(settings.numOutputChannels > 0) {
soundOutputStream = (__bridge void *)[[SoundOutputStream alloc] initWithNumOfChannels:settings.numOutputChannels
withSampleRate:settings.sampleRate
withBufferSize:settings.bufferSize];
ofxiOSSoundStreamDelegate * delegate = [[ofxiOSSoundStreamDelegate alloc] initWithSoundOutputFn:settings.outCallback];
((__bridge SoundInputStream *)soundOutputStream).delegate = delegate;
[(__bridge SoundInputStream *)soundOutputStream start];
}
bool bOk = (soundInputStream != NULL) || (soundOutputStream != NULL);
return bOk;
}
else{
return false;
}
}
The app then asked for permission on run (before the soundstream was initialised) but crashed as described above.
fresla
January 29, 2023, 1:23am
#4
With some help I managed to get this going. I’m not sure if this a perfect solution but it helped me.
opened 12:23AM - 26 Jan 23 UTC
This is also a forum post (https://forum.openframeworks.cc/t/nightlies-and-ios-s… ound-input/41221)
but maybe it is more relevant here. Sound input for iOS is not currently working.
When the `bool ofxiOSSoundStream::setup(const ofSoundStreamSettings & settings)`
function runs it has an error:
`Thread 1: EXC_BAD_ACCESS (code=1, address=0x464630b96110)`
On this line:
` [(__bridge SoundInputStream *)soundInputStream start];`
Trying to trace these changes back, it seems maybe they came from this commit:
https://github.com/openframeworks/openFrameworks/pull/6889
EDIT: After some more checking, the sound player also does not work, it exits on another bridged function in load:
`bool ofxiOSSoundPlayer::load(const std::filesystem::path& fileName, bool stream) {
if(soundPlayer != NULL) {
unload();
}
string filePath = ofToDataPath(fileName);
soundPlayer = (__bridge void *)[[AVSoundPlayer alloc] init];
BOOL bOk = [(__bridge AVSoundPlayer *)soundPlayer loadWithPath:[NSString stringWithUTF8String:filePath.c_str()]];
return bOk;
}
`
Giving the EXC_BAD_ACCESS error on this line:
`BOOL bOk = [(__bridge AVSoundPlayer *)soundPlayer loadWithPath:[NSString stringWithUTF8String:filePath.c_str()]];
`
dimitre
January 31, 2023, 7:50pm
#5
hey @fresla can you please test it again with the current master or tomorrow nightly? thanks
fresla
January 31, 2023, 11:45pm
#6
Hi, yes the recent fixes work for me, soundstream input and output work as do the sound players. I do see the same issue as you meontioned on github, the playback level of the file is low when the soundstream input is active. Otherwise it is all working well.