在OSX AVAudioSession替代获得音频驱动程序采样率 [英] AVAudioSession alternative on OSX to get audio driver sample rate

查看:1116
本文介绍了在OSX AVAudioSession替代获得音频驱动程序采样率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IOS可以使用 [AVAudioSession sharedInstance] SAMPLERATE]; 来检索音频驱动程序当前使用的采样率。 AVAudioSession不OSX上存在的,所以我想知道如何来实现同样的事情在OSX,因为我找不到太多的话题。

on IOS you can use [[AVAudioSession sharedInstance] sampleRate]; to retrieve the current sample rate used by the audio driver. AVAudioSession does not exist on OSX, so I am wondering how to achieve the same thing on OSX, as I could not find much on the topic.

感谢

推荐答案

好吧,

经过一番更深入的研究的音频硬件服务的似乎做OSX的伎俩。下面是一些例子code:

after some more in depth research Audio Hardware Services seems to do the trick on OSX. Here is some example code:

//get the default output device
AudioObjectPropertyAddress addr;
UInt32 size;
addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(AudioDeviceID);
err = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);

//get its sample rate
addr.mSelector = kAudioDevicePropertyNominalSampleRate;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(Float64);
Float64 outSampleRate;
err = AudioHardwareServiceGetPropertyData(deviceID, &addr, 0, NULL, &size, &outSampleRate);
//if there is no error, outSampleRate contains the sample rate

不幸的是,不是那么容易的IOS版本,但做这项工作!这会给你的采样率设置,您可以在OSX改变的音频与MIDI设置

这篇关于在OSX AVAudioSession替代获得音频驱动程序采样率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆