// returns kAudioTypeInput or kAudioTypeOutput ASDeviceType getDeviceType(AudioDeviceID deviceID) { UInt32 propertySize = 256; // if there are any output streams, then it is an output AudioDeviceGetPropertyInfo(deviceID, 0, false, kAudioDevicePropertyStreams, &propertySize, NULL); if (propertySize > 0) return kAudioTypeOutput; // if there are any input streams, then it is an input AudioDeviceGetPropertyInfo(deviceID, 0, true, kAudioDevicePropertyStreams, &propertySize, NULL); if (propertySize > 0) return kAudioTypeInput; return kAudioTypeUnknown; }
bool CAUOutputDevice::GetPreferredChannelLayout(CCoreAudioChannelLayout& layout) { if (!m_DeviceId) return false; UInt32 propertySize = 0; Boolean writable = false; OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, &writable); if (ret) return false; void* pBuf = malloc(propertySize); ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, pBuf); if (ret) CLog::Log(LOGERROR, "CAUOutputDevice::GetPreferredChannelLayout: " "Unable to retrieve preferred channel layout. Error = %s", GetError(ret).c_str()); else { // Copy the result into the caller's instance layout.CopyLayout(*((AudioChannelLayout*)pBuf)); } free(pBuf); return (ret == noErr); }
bool CoreAudioUtilities::hasChannel(AudioDeviceID id, bool isInput) { OSStatus status = noErr; UInt32 size = 0; bool result = false; Boolean input = (isInput ? TRUE : FALSE); status = AudioDeviceGetPropertyInfo(id, 0, input, kAudioDevicePropertyStreamConfiguration, &size, NULL); if (status) { LOG_ERROR("Can't get device property info: kAudioDevicePropertyStreamConfiguration"); return false; } AudioBufferList *list = (AudioBufferList *) malloc(size); status = AudioDeviceGetProperty(id, 0, input, kAudioDevicePropertyStreamConfiguration, &size, list); if (status) { LOG_INFO("Can't get device property: kAudioDevicePropertyStreamConfiguration." " The device has no " + (isInput ? std::string("input") : std::string("output")) + " device."); free(list); return false; } for (unsigned i = 0; i < list->mNumberBuffers; ++i) { if (list->mBuffers[i].mNumberChannels > 0) { result = true; break; } } free(list); return result; }
PlexAudioDevice::PlexAudioDevice(AudioDeviceID deviceID) : m_deviceID(deviceID) , m_isValid(false) , m_supportsDigital(false) { UInt32 paramSize = 0; OSStatus err = noErr; // Retrieve the length of the device name. SAFELY(AudioDeviceGetPropertyInfo(deviceID, 0, false, kAudioDevicePropertyDeviceName, ¶mSize, NULL)); if (err == noErr) { // Retrieve the name of the device. char* pStrName = new char[paramSize]; pStrName[0] = '\0'; SAFELY(AudioDeviceGetProperty(deviceID, 0, false, kAudioDevicePropertyDeviceName, ¶mSize, pStrName)); if (err == noErr) { m_deviceName = pStrName; // See if the device is writable (can output). m_hasOutput = computeHasOutput(); // If the device does have output, see if it supports digital. if (m_hasOutput) m_supportsDigital = computeDeviceSupportsDigital(); m_isValid = true; } delete[] pStrName; } }
bool PlexAudioDevice::computeDeviceSupportsDigital() { bool ret = false; OSStatus err = noErr; UInt32 paramSize = 0; // Retrieve all the output streams. SAFELY(AudioDeviceGetPropertyInfo(m_deviceID, 0, FALSE, kAudioDevicePropertyStreams, ¶mSize, NULL)); if (err == noErr) { int numStreams = paramSize / sizeof(AudioStreamID); AudioStreamID* pStreams = (AudioStreamID *)malloc(paramSize); SAFELY(AudioDeviceGetProperty(m_deviceID, 0, FALSE, kAudioDevicePropertyStreams, ¶mSize, pStreams)); if (err == noErr) { for (int i=0; i<numStreams && ret == false; i++) { if (computeStreamSupportsDigital(pStreams[i])) ret = true; } } free(pStreams); } return ret; }
static PaError InitializeDeviceInfo(PaMacCoreDeviceInfo *macCoreDeviceInfo, AudioDeviceID macCoreDeviceId, PaHostApiIndex hostApiIndex ) { PaDeviceInfo *deviceInfo = &macCoreDeviceInfo->inheritedDeviceInfo; deviceInfo->structVersion = 2; deviceInfo->hostApi = hostApiIndex; PaError err = paNoError; UInt32 propSize; err = conv_err(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL)); // FIXME: this allocation should be part of the allocations group char *name = PaUtil_AllocateMemory(propSize); err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name)); if (!err) { deviceInfo->name = name; } Float64 sampleRate; propSize = sizeof(Float64); err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyNominalSampleRate, &propSize, &sampleRate)); if (!err) { deviceInfo->defaultSampleRate = sampleRate; } // Get channel info err = GetChannelInfo(deviceInfo, macCoreDeviceId, 1); err = GetChannelInfo(deviceInfo, macCoreDeviceId, 0); return err; }
void CCoreAudioHardware::GetOutputDeviceName(std::string& name) { AudioDeviceID deviceId = GetDefaultOutputDevice(); if(deviceId) { UInt32 size = 0; // TODO: Change to kAudioObjectPropertyObjectName AudioDeviceGetPropertyInfo(deviceId,0, false, kAudioDevicePropertyDeviceName, &size, NULL); char *m_buffer = (char*)malloc(size); OSStatus ret = AudioDeviceGetProperty(deviceId, 0, false, kAudioDevicePropertyDeviceName, &size, m_buffer); if (ret && !m_buffer) { name ="Default"; } else { name = m_buffer; free(m_buffer); } } else { name = "Default"; } }
/* ========== idAudioHardwareOSX::GetAvailableNominalSampleRates ========== */ void idAudioHardwareOSX::GetAvailableNominalSampleRates( void ) { UInt32 size; OSStatus status; int i, rangeCount; AudioValueRange *rangeArray; status = AudioDeviceGetPropertyInfo( selectedDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates, &size, NULL ); if ( status != kAudioHardwareNoError ) { common->Warning( "AudioDeviceGetPropertyInfo %d kAudioDevicePropertyAvailableNominalSampleRates failed. status: %s", selectedDevice, ExtractStatus( status ) ); return; } rangeCount = size / sizeof( AudioValueRange ); rangeArray = (AudioValueRange *)malloc( size ); common->Printf( "%d possible rate(s)\n", rangeCount ); status = AudioDeviceGetProperty( selectedDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates, &size, rangeArray ); if ( status != kAudioHardwareNoError ) { common->Warning( "AudioDeviceGetProperty %d kAudioDevicePropertyAvailableNominalSampleRates failed. status: %s", selectedDevice, ExtractStatus( status ) ); free( rangeArray ); return; } for( i = 0; i < rangeCount; i++ ) { common->Printf( " %d: min %g max %g\n", i, rangeArray[ i ].mMinimum, rangeArray[ i ].mMaximum ); } free( rangeArray ); }
std::vector<UInt32> CoreAudioUtilities::dataSourceList(AudioDeviceID id, bool isInput) { OSStatus status = noErr; std::vector<UInt32> result; Boolean input = (isInput ? TRUE : FALSE); UInt32 size = 0; status = AudioDeviceGetPropertyInfo(id, 0, input, kAudioDevicePropertyDataSources, &size, NULL); if (status) { LOG_ERROR("Can't get device property info: kAudioDevicePropertyDataSources"); return result; } if (!size) { return result; } UInt32 * ids = (UInt32 *) malloc(size); status = AudioDeviceGetProperty(id, 0, input, kAudioDevicePropertyDataSources, &size, ids); if (status) { LOG_ERROR("Can't get device property: kAudioDevicePropertyDataSources"); } else { for (unsigned i = 0; i < (size / sizeof(UInt32)); i++) { result.push_back(ids[i]); } } free(ids); return result; }
bool isAnOutputDevice(AudioDeviceID deviceID) { UInt32 propertySize = 256; // if there are any output streams, then it is an output AudioDeviceGetPropertyInfo(deviceID, 0, false, kAudioDevicePropertyStreams, &propertySize, NULL); if (propertySize > 0) return true; return false; }
bool isAnInputDevice(AudioDeviceID deviceID) { UInt32 propertySize = 256; // if there are any input streams, then it is an input AudioDeviceGetPropertyInfo(deviceID, 0, true, kAudioDevicePropertyStreams, &propertySize, NULL); if (propertySize > 0) return kAudioTypeInput; return false; }
OSStatus get_total_channels(AudioDeviceID device, int* channelCount, bool isInput) { OSStatus err = noErr; UInt32 outSize; Boolean outWritable; AudioBufferList* bufferList = 0; AudioStreamID* streamList = 0; int i, numStream; err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreams, &outSize, &outWritable); if (err == noErr) { streamList = (AudioStreamID*)malloc(outSize); numStream = outSize/sizeof(AudioStreamID); JCALog("get_total_channels device stream number = %ld numStream = %ld\n", device, numStream); err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreams, &outSize, streamList); if (err == noErr) { AudioStreamBasicDescription streamDesc; outSize = sizeof(AudioStreamBasicDescription); for (i = 0; i < numStream; i++) { err = AudioStreamGetProperty(streamList[i], 0, kAudioDevicePropertyStreamFormat, &outSize, &streamDesc); JCALog("get_total_channels streamDesc mFormatFlags = %ld mChannelsPerFrame = %ld\n", streamDesc.mFormatFlags, streamDesc.mChannelsPerFrame); } } } *channelCount = 0; err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable); if (err == noErr) { bufferList = (AudioBufferList*)malloc(outSize); err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList); if (err == noErr) { for (i = 0; i < bufferList->mNumberBuffers; i++) *channelCount += bufferList->mBuffers[i].mNumberChannels; } } if (streamList) free(streamList); if (bufferList) free(bufferList); return err; }
UInt32 CoreAudioDevice::propertyDataSize(UInt32 channel, CoreAudioDeviceSection section, AudioHardwarePropertyID property) const { UInt32 size = 0; if (AudioDeviceGetPropertyInfo(deviceID, channel, section, property, &size, NULL) != 0) { fprintf(stderr,"Error while fetching audio device property size. Exiting."); exit(0); } return size; }
bool PlexAudioDevice::computeHasOutput() { UInt32 dataSize = 0; Boolean isWritable = false; AudioDeviceGetPropertyInfo(m_deviceID, 0, FALSE, kAudioDevicePropertyStreams, &dataSize, &isWritable); if (dataSize == 0) return false; return true; }
const char* CCoreAudioDevice::GetName(CStdString& name, const AudioDeviceID &id) { UInt32 size = 0; AudioDeviceGetPropertyInfo(id,0, false, kAudioDevicePropertyDeviceName, &size, NULL); // TODO: Change to kAudioObjectPropertyObjectName OSStatus ret = AudioDeviceGetProperty(id, 0, false, kAudioDevicePropertyDeviceName, &size, name.GetBufferSetLength(size)); if (ret) { CLog::Log(LOGERROR, "CCoreAudioDevice::GetName: Unable to get device name - id: 0x%04x Error = 0x%08x (%4.4s)", id, ret, CONVERT_OSSTATUS(ret)); return NULL; } return name.c_str(); }
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const { QAudioFormat rc; UInt32 propSize = 0; if (AudioDeviceGetPropertyInfo(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreams, &propSize, 0) == noErr) { const int sc = propSize / sizeof(AudioStreamID); if (sc > 0) { AudioStreamID* streams = new AudioStreamID[sc]; if (AudioDeviceGetProperty(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreams, &propSize, streams) == noErr) { for (int i = 0; i < sc; ++i) { if (AudioStreamGetPropertyInfo(streams[i], 0, kAudioStreamPropertyPhysicalFormat, &propSize, 0) == noErr) { AudioStreamBasicDescription sf; if (AudioStreamGetProperty(streams[i], 0, kAudioStreamPropertyPhysicalFormat, &propSize, &sf) == noErr) { rc = toQAudioFormat(sf); break; } } } } delete streams; } } return rc; }
Boolean AudioOutputHasVolumeControl(AudioDeviceID device, Boolean *isWritable) { OSStatus err = AudioObjectIsPropertySettable(device, &kAudioOutputVolumeProperty, isWritable); if (noErr == err) { return TRUE; } else { UInt32 channel; err = AudioOutputGetStereoChannels(device, &channel, NULL); if (noErr == err) { return noErr == AudioDeviceGetPropertyInfo(device, channel, FALSE, kAudioDevicePropertyVolumeScalar, NULL, isWritable); } } return FALSE; }
/* * Sets the value of system sound volume. * * @param [Float] volume * The value that set volume to system. * range of volume is 0.0 .. 1.0. * @example * System::Sound.set_volume(0.75) */ static VALUE rb_sys_set_volume(VALUE obj, VALUE volume) { AudioDeviceID device; OSStatus err; UInt32 size; Boolean canset = false; UInt32 channels[2]; float involume; if (!FIXFLOAT_P(volume)) { rb_raise(rb_eTypeError, "wrong type of argument"); } involume = NUM2DBL(volume); if (involume < 0.0 || involume > 1.0) { rb_raise(rb_eRangeError, "out of range"); } // get device device = get_audio_device_id(); size = sizeof(canset); err = AudioDeviceGetPropertyInfo(device, 0, false, kAudioDevicePropertyVolumeScalar, &size, &canset); if (err == noErr && canset == true) { size = sizeof involume; err = AudioDeviceSetProperty(device, NULL, 0, false, kAudioDevicePropertyVolumeScalar, size, &involume); return Qnil; } // else, try seperate channes // get channels size = sizeof(channels); err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels); if (err != noErr) { rb_raise(rb_eRuntimeError, "Failed to get channel numbers"); } // set volume size = sizeof(float); err = AudioDeviceSetProperty(device, 0, channels[0], false, kAudioDevicePropertyVolumeScalar, size, &involume); if (err != noErr) { rb_raise(rb_eRuntimeError, "Failed to set volume of channel"); } err = AudioDeviceSetProperty(device, 0, channels[1], false, kAudioDevicePropertyVolumeScalar, size, &involume); if (err != noErr) { rb_raise(rb_eRuntimeError, "Failed to set volume of channel"); } return Qnil; }
static int gviHardwareGetNumChannels(GVDevice device, GVDeviceType type) { OSStatus result; UInt32 size; int numStreams; result = AudioDeviceGetPropertyInfo(device->m_deviceID, 0, (type & GV_CAPTURE)?true:false, kAudioDevicePropertyStreams, &size, NULL); if(result != noErr) return 1; numStreams = (size / sizeof(AudioStreamID)); return numStreams; }
static bool_t check_card_capability(AudioDeviceID id, bool_t is_input, char * devname, char *uidname, size_t name_len) { unsigned int slen=name_len; Boolean writable=0; CFStringRef dUID=NULL; bool_t ret=FALSE; int err =AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyDeviceName, &slen,devname); if (err != kAudioHardwareNoError) { ms_error("get kAudioDevicePropertyDeviceName error %ld", err); return FALSE; } err =AudioDeviceGetPropertyInfo(id, 0, is_input, kAudioDevicePropertyStreamConfiguration, &slen, &writable); if (err != kAudioHardwareNoError) { ms_error("get kAudioDevicePropertyDeviceName error %ld", err); return FALSE; } AudioBufferList *buflist = ms_malloc(slen); err = AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyStreamConfiguration, &slen, buflist); if (err != kAudioHardwareNoError) { ms_error("get kAudioDevicePropertyDeviceName error %ld", err); ms_free(buflist); return FALSE; } UInt32 j; for (j = 0; j < buflist->mNumberBuffers; j++) { if (buflist->mBuffers[j].mNumberChannels > 0) { ret=TRUE; break; } } ms_free(buflist); if (ret==FALSE) return FALSE; slen = sizeof(CFStringRef); err =AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyDeviceUID, &slen,&dUID); if (err != kAudioHardwareNoError) { ms_error("get kAudioHardwarePropertyDevices error %ld", err); return FALSE; } CFStringGetCString(dUID, uidname, sizeof(uidname),CFStringGetSystemEncoding()); ms_message("CA: devname:%s uidname:%s", devname, uidname); return ret; }
UInt32 CCoreAudioDevice::GetTotalOutputChannels(const AudioDeviceID &id) { UInt32 channels = 0; UInt32 size = 0; AudioDeviceGetPropertyInfo(id, 0, false, kAudioDevicePropertyStreamConfiguration, &size, NULL); AudioBufferList* pList = (AudioBufferList*)malloc(size); OSStatus ret = AudioDeviceGetProperty(id, 0, false, kAudioDevicePropertyStreamConfiguration, &size, pList); if (!ret) for(UInt32 buffer = 0; buffer < pList->mNumberBuffers; ++buffer) channels += pList->mBuffers[buffer].mNumberChannels; else CLog::Log(LOGERROR, "CCoreAudioDevice::GetTotalOutputChannels: Unable to get total device output channels - id: 0x%04x Error = 0x%08x (%4.4s)", id, ret, CONVERT_OSSTATUS(ret)); CLog::Log(LOGDEBUG, "CCoreAudioDevice::GetTotalOutputChannels: Found %u channels in %u buffers", channels, pList->mNumberBuffers); free(pList); return channels; }
bool CCoreAudioDevice::GetPreferredChannelLayout(CoreAudioChannelList* pChannelMap) { if (!pChannelMap || !m_DeviceId) return false; UInt32 propertySize = 0; Boolean writable = false; OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, &writable); if (ret) return false; // kAudioChannelLabel_Unknown = -1 (0xffffffff) // kAudioChannelLabel_Unused = 0 // kAudioChannelLabel_Left = 1 // kAudioChannelLabel_Right = 2 // ... void* pBuf = malloc(propertySize); AudioChannelLayout* pLayout = (AudioChannelLayout*)pBuf; ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, pBuf); if (ret) CLog::Log(LOGERROR, "CCoreAudioUnit::GetPreferredChannelLayout: Unable to retrieve preferred channel layout. Error = 0x%08x (%4.4s)", ret, CONVERT_OSSTATUS(ret)); else { if(pLayout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions) { for (UInt32 i = 0; i < pLayout->mNumberChannelDescriptions; i++) { if (pLayout->mChannelDescriptions[i].mChannelLabel == kAudioChannelLabel_Unknown) pChannelMap->push_back(i + 1); // TODO: This is not the best way to handle unknown/unconfigured speaker layouts else pChannelMap->push_back(pLayout->mChannelDescriptions[i].mChannelLabel); // Will be one of kAudioChannelLabel_xxx } } else { // TODO: Determine if a method that uses a channel bitmap is also necessary free(pLayout); return false; } } free(pLayout); return (ret == noErr); }
bool CCoreAudioDevice::GetDataSources(CoreAudioDataSourceList* pList) { if (!pList || !m_DeviceId) return false; UInt32 propertySize = 0; Boolean writable = false; OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false, kAudioDevicePropertyDataSources, &propertySize, &writable); if (ret) return false; UInt32 sources = propertySize / sizeof(UInt32); UInt32* pSources = new UInt32[sources]; ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyDataSources, &propertySize, pSources); if (!ret) for (UInt32 i = 0; i < sources; i++) pList->push_back(pSources[i]);; delete[] pSources; return (!ret); }
bool CCoreAudioDevice::GetPreferredChannelLayout(CoreAudioChannelList* pChannelMap) { if (!pChannelMap || !m_DeviceId) return false; UInt32 propertySize = 0; Boolean writable = false; OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, &writable); if (ret) return false; UInt32 channels = propertySize / sizeof(SInt32); SInt32* pMap = new SInt32[channels]; ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyPreferredChannelLayout, &propertySize, pMap); if (!ret) for (UInt32 i = 0; i < channels; i++) pChannelMap->push_back(pMap[i]);; delete[] pMap; return (!ret); }
const std::string& InputImplAudioUnit::Device::getName() { if( mDeviceName.length() == 0 ) { OSStatus err; UInt32 size; AudioDeviceID nativeDeviceId = static_cast<AudioDeviceID>( mDeviceId ); err = AudioDeviceGetPropertyInfo( nativeDeviceId, 0, true, kAudioDevicePropertyDeviceName, &size, NULL ); if( err != noErr ) { throw InvalidDeviceInputExc(); } char buf[size]; err = AudioDeviceGetProperty( nativeDeviceId, 0, true, kAudioDevicePropertyDeviceName, &size, buf ); if( err != noErr ) { throw InvalidDeviceInputExc(); } mDeviceName = std::string( buf ); } return mDeviceName; }
int AudioDevice::CountChannels() { OSStatus err; UInt32 propSize; int result = 0; err = AudioDeviceGetPropertyInfo(mID, 0, mIsInput, kAudioDevicePropertyStreamConfiguration, &propSize, NULL); if (err) return 0; AudioBufferList *buflist = (AudioBufferList *)malloc(propSize); err = AudioDeviceGetProperty(mID, 0, mIsInput, kAudioDevicePropertyStreamConfiguration, &propSize, buflist); if (!err) { for (UInt32 i = 0; i < buflist->mNumberBuffers; ++i) { result += buflist->mBuffers[i].mNumberChannels; } } free(buflist); return result; }
bool CCoreAudioDevice::GetStreams(AudioStreamIdList* pList) { if (!pList || !m_DeviceId) return false; UInt32 propertySize = 0; Boolean writable = false; OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false, kAudioDevicePropertyStreams, &propertySize, &writable); if (ret) return false; UInt32 streamCount = propertySize / sizeof(AudioStreamID); AudioStreamID* pStreamList = new AudioStreamID[streamCount]; ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyStreams, &propertySize, pStreamList); if (!ret) { for (UInt32 stream = 0; stream < streamCount; stream++) pList->push_back(pStreamList[stream]); } delete[] pStreamList; return (ret == noErr); }
static PaError GetChannelInfo(PaDeviceInfo *deviceInfo, AudioDeviceID macCoreDeviceId, int isInput) { UInt32 propSize; PaError err = paNoError; UInt32 i; int numChannels = 0; AudioBufferList *buflist; err = conv_err(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize, NULL)); buflist = PaUtil_AllocateMemory(propSize); err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize, buflist)); if (!err) { for (i = 0; i < buflist->mNumberBuffers; ++i) { numChannels += buflist->mBuffers[i].mNumberChannels; } if (isInput) deviceInfo->maxInputChannels = numChannels; else deviceInfo->maxOutputChannels = numChannels; int frameLatency; propSize = sizeof(UInt32); err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyLatency, &propSize, &frameLatency)); if (!err) { double secondLatency = frameLatency / deviceInfo->defaultSampleRate; if (isInput) { deviceInfo->defaultLowInputLatency = secondLatency; deviceInfo->defaultHighInputLatency = secondLatency; } else { deviceInfo->defaultLowOutputLatency = secondLatency; deviceInfo->defaultHighOutputLatency = secondLatency; } } } PaUtil_FreeMemory(buflist); return err; }
QList<int> QAudioDeviceInfoInternal::supportedChannelCounts() { QList<int> rc; // Can mix down to 1 channel rc << 1; UInt32 propSize = 0; int channels = 0; if (AudioDeviceGetPropertyInfo(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreamConfiguration, &propSize, 0) == noErr) { AudioBufferList* audioBufferList = static_cast<AudioBufferList*>(qMalloc(propSize)); if (audioBufferList != 0) { if (AudioDeviceGetProperty(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreamConfiguration, &propSize, audioBufferList) == noErr) { for (int i = 0; i < int(audioBufferList->mNumberBuffers); ++i) { channels += audioBufferList->mBuffers[i].mNumberChannels; rc << channels; } } qFree(audioBufferList); } } return rc; }
QList<int> QAudioDeviceInfoInternal::supportedSampleRates() { QSet<int> rc; // Add some common frequencies rc << 8000 << 11025 << 22050 << 44100; // UInt32 propSize = 0; if (AudioDeviceGetPropertyInfo(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyAvailableNominalSampleRates, &propSize, 0) == noErr) { const int pc = propSize / sizeof(AudioValueRange); if (pc > 0) { AudioValueRange* vr = new AudioValueRange[pc]; if (AudioDeviceGetProperty(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyAvailableNominalSampleRates, &propSize, vr) == noErr) { for (int i = 0; i < pc; ++i) rc << vr[i].mMaximum; } delete vr; } } return rc.toList(); }