const std::vector<InputDeviceRef>& InputImplAudioUnit::getDevices( bool forceRefresh ) { if( forceRefresh || ! sDevicesEnumerated ) { sDevices.clear(); UInt32 propSize; AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices, &propSize, NULL ); uint32_t deviceCount = ( propSize / sizeof(AudioDeviceID) ); AudioDeviceID deviceIds[deviceCount]; AudioHardwareGetProperty( kAudioHardwarePropertyDevices, &propSize, &deviceIds ); for( uint32_t i = 0; i < deviceCount; i++ ) { try { InputDeviceRef aDevice = InputDeviceRef( new Device( deviceIds[i] ) ); sDevices.push_back( aDevice ); } catch( InvalidDeviceInputExc ) { continue; } } sDevicesEnumerated = true; } return sDevices; }
const std::vector<InputDeviceRef>& InputImplAudioUnit::getDevices( bool forceRefresh ) { if( forceRefresh || ! sDevicesEnumerated ) { sDevices.clear(); sDevices.push_back( InputDeviceRef( new InputImplAudioUnit::Device() ) ); sDevicesEnumerated = true; } return sDevices; }
InputDeviceRef Input::findDeviceByNameContains( const std::string &nameFragment ) { const std::vector<InputDeviceRef>& devices = getDevices(); for (size_t i = 0; i < devices.size(); ++i) { if (devices[i]->getName().find(nameFragment) != std::string::npos) return devices[i]; } return InputDeviceRef(); }
InputDeviceRef Input::findDeviceByName( const std::string &name ) { const std::vector<InputDeviceRef>& devices = getDevices(); for (size_t i = 0; i < devices.size(); ++i) { if (devices[i]->getName() == name) return devices[i]; } return InputDeviceRef(); }
InputDeviceRef InputImplAudioUnit::getDefaultDevice() { AudioDeviceID aDeviceId; UInt32 param = sizeof( AudioDeviceID ); OSStatus err = AudioHardwareGetProperty( kAudioHardwarePropertyDefaultInputDevice, ¶m, &aDeviceId ); if( err != noErr ) { //TODO std::cout << "Error getting default device" << std::endl; throw; } return InputDeviceRef( new InputImplAudioUnit::Device( aDeviceId ) ); }
InputDeviceRef Input::findDeviceByNameContains( const std::string &nameFragment ) { return InputDeviceRef(); }
InputDeviceRef Input::findDeviceByName( const std::string &name ) { return InputDeviceRef(); }
Input::Input() { mImpl = std::shared_ptr<InputImpl>( new InputPlatformImpl( InputDeviceRef() ) ); }
InputDeviceRef InputImplAudioUnit::getDefaultDevice() { return InputDeviceRef( new InputImplAudioUnit::Device() ); }