admsyn / ofxAudioUnit

An openFrameworks addon which makes it easy to work with Audio Units on OSX and iOS
MIT License
120 stars 24 forks source link

input.setDevice() #20

Closed antimodular closed 9 years ago

antimodular commented 9 years ago

i am trying a simple recording and playback code: http://pastebin.com/WyfH2WQL

this code: input.setDevice("Built-in Microphone"); input.connectTo(output); input.start();

gives this error in the console: deviceID 50 Error -10851 while setting input unit's device ID

the runs ok but when trying to playback what was recorded the file is empty/ all quiet.

would you know why?

admsyn commented 9 years ago

Not sure. That error code corresponds to kAudioUnitErr_InvalidPropertyValue, but the fact that it's printing that message means it found a valid device (just failed when actually attempting to set it).

Is there anything weird about your setup that'd make the built in mic act oddly as an input?

admsyn commented 9 years ago

Actually I'm able to reproduce this on my computer, not sure what's up since it works if I try to set it to soundflower.

EDIT: It also seems to work, even though it prints an error message. Very odd.

admsyn commented 9 years ago

Fixed it! The issue was that the input device needs to be configured (calling start()) before setting its device. ofxAudioUnit caches the deviceID you set and re-sets it after you call start() which is why it worked anyway, though it printed the error for no reason. The erroneous error message was fixed with b2479a7

I'm not sure why your recorder isn't working, but the fact that you're setting the ofxAudioUnitInput's device implies that the mic isn't the default. Your external recorder may be just using the default input, and therefore just getting silence?

antimodular commented 9 years ago

yes error is gone now.

about the recorder: it says here: https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/Reference/Reference.html "In OS X, the audio comes from the system’s default audio input device as set by a user in System Preferences." so, does that mean ofxaudiounit will not be able to override what ever is set in the system pref?