iOS:音频单位:设置任意采样率

发布于 2024-10-02 05:59:25 字数 667 浏览 9 评论 0原文

我可以设置任何我想要的采样率吗?有什么限制?

硬件采样率怎么样?一旦设置完毕,对单元之间传递的内部采样率有何限制?

我猜测实际的硬件速率可能必须是 44.1KHz 的一些位移,并且任何内部采样率必须是该原始值的向下位移(例如 22.1KHz、11.05KHz)。这很接近吗?

据我了解,
1. 我设置音频会话的硬件采样率。
2.系统设置采样率尽可能接近我指定的采样率。
3. 然后,我在音频会话中查询我设置的相同属性,这将为我提供它正在使用的实际采样率

在音频单元(特别是 RemoteIO 单元)级别,文档指出该单元连接到的两个点硬件(即麦克风(输入)总线的输入范围和扬声器(输出)总线的输出范围),采样率可能检索但是 >未设置

但是,我在构造远程 I/O 单元时尝试访问该值,结果返回零。我想也许我需要启动该单元,然后才能从其连接中获取有意义的数据(启动它的行为可能会创建连接)。因此,这里的解决方案似乎是从音频会话中获取采样率并使用它,如上所述。

需要标签:音频单元

Can I set any sample rate I want? What are the restrictions?

How about the hardware sample rate? And once that is set, what is the restriction on the internal sample rates passed between units?

I'm guessing that the actual hardware rate may have to be some bit shift of 44.1KHz, and any internal sample rates must be a downward bit shift of this original value (e.g. 22.1KHz, 11.05KHz). Is this close?

As far as I understand,
1. I set the hardware sample rate from the Audio Session.
2. The system will set a sample rate as close as it is able to the sample rate I specified.
3. I then query the audio session for the same property I set, which will give me the actual sample rate it is using

At the level of audio units, specifically the RemoteIO unit, documentation states that the two points at which the unit connects to the hardware (ie the input scope of the microphone (input) bus and the output scope of the speaker (output) bus), the sample rate may be retrieved but not set.

However, I attempt to access this value while constructing the remote I/O unit, and it returns zero. I guess maybe I need to start the unit before I can get meaningful data from its connections (the act of starting it probably creates the connections). So the solution here appears to be to get the sample rate from the audio session and use that, as per the above.

NEED TAG: Audio-Unit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠意 2024-10-09 05:59:25

自从你提到 AudioSessions 以来,我假设你使用的是 iOS。因此您需要:

  1. 检查音频输入硬件。 AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable...)

  2. 将音频会话设置为“播放和录制”模式。 AudioSessionSetProperty (kAudioSessionProperty_AudioCategory...)kAudioSessionCategory_PlayAndRecord

  3. 激活会话。 AudioSessionSetActive()

  4. 获取首选采样率。 AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate)

然后,您可以使用正确的采样率设置音频处理链。

至于播放音频,您可以使用任何采样率,API 应将其转换为硬件的输出采样率。显然,如果您使用非常高的采样率,则会消耗大量内存和 CPU 时间。

I'm assuming you're on iOS since you mention AudioSessions. So you'll want to:

  1. Check for audio input hardware. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable...)

  2. Set audio session to "play & record" mode. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory...) with kAudioSessionCategory_PlayAndRecord

  3. Activate the session. AudioSessionSetActive()

  4. Get the preferred sample rate. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate)

Then you can set up your audio processing chain with the correct sample rate.

As for playing back audio, you can use any sample rate and the API should convert it to the hardware's output sample rate. Obviously if you use a very high sample rate, it'l consume a lot of memory and CPU time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文