static bool coreaudio_init_format(struct coreaudio_data *ca) { AudioStreamBasicDescription desc; OSStatus stat; UInt32 size = sizeof(desc); stat = get_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_INPUT, BUS_INPUT, &desc, &size); if (!ca_success(stat, ca, "coreaudio_init_format", "get input format")) return false; /* Certain types of devices have no limit on channel count, and * there's no way to know the actual number of channels it's using, * so if we encounter this situation just force to stereo */ if (desc.mChannelsPerFrame > 8) { desc.mChannelsPerFrame = 2; desc.mBytesPerFrame = 2 * desc.mBitsPerChannel / 8; desc.mBytesPerPacket = desc.mFramesPerPacket * desc.mBytesPerFrame; } stat = set_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_OUTPUT, BUS_INPUT, &desc, size); if (!ca_success(stat, ca, "coreaudio_init_format", "set output format")) return false; if (desc.mFormatID != kAudioFormatLinearPCM) { ca_warn(ca, "coreaudio_init_format", "format is not PCM"); return false; } ca->format = convert_ca_format(desc.mFormatFlags, desc.mBitsPerChannel); if (ca->format == AUDIO_FORMAT_UNKNOWN) { ca_warn(ca, "coreaudio_init_format", "unknown format flags: " "%u, bits: %u", (unsigned int)desc.mFormatFlags, (unsigned int)desc.mBitsPerChannel); return false; } ca->sample_rate = (uint32_t)desc.mSampleRate; ca->speakers = convert_ca_speaker_layout(desc.mChannelsPerFrame); if (ca->speakers == SPEAKERS_UNKNOWN) { ca_warn(ca, "coreaudio_init_format", "unknown speaker layout: " "%u channels", (unsigned int)desc.mChannelsPerFrame); return false; } return true; }
static bool coreaudio_init_format(struct coreaudio_data *ca) { AudioStreamBasicDescription desc; OSStatus stat; UInt32 size = sizeof(desc); stat = get_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_INPUT, BUS_INPUT, &desc, &size); if (!ca_success(stat, ca, "coreaudio_init_format", "get input format")) return false; stat = set_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_OUTPUT, BUS_INPUT, &desc, size); if (!ca_success(stat, ca, "coreaudio_init_format", "set output format")) return false; if (desc.mFormatID != kAudioFormatLinearPCM) { ca_warn(ca, "coreaudio_init_format", "format is not PCM"); return false; } ca->format = convert_ca_format(desc.mFormatFlags, desc.mBitsPerChannel); if (ca->format == AUDIO_FORMAT_UNKNOWN) { ca_warn(ca, "coreaudio_init_format", "unknown format flags: " "%u, bits: %u", (unsigned int)desc.mFormatFlags, (unsigned int)desc.mBitsPerChannel); return false; } ca->sample_rate = (uint32_t)desc.mSampleRate; ca->speakers = convert_ca_speaker_layout(desc.mChannelsPerFrame); if (ca->speakers == SPEAKERS_UNKNOWN) { ca_warn(ca, "coreaudio_init_format", "unknown speaker layout: " "%u channels", (unsigned int)desc.mChannelsPerFrame); return false; } return true; }