AVAudioSinkNode具有非默认值,但仍为设备本地采样率 [英] AVAudioSinkNode with non-default, but still device-native sample rates

查看:265
本文介绍了AVAudioSinkNode具有非默认值,但仍为设备本地采样率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将 AVAudioSinkNode 配置为附加到 AVAudioEngine inputNode 像这样:

I've configured AVAudioSinkNode attached to AVAudioEngine's inputNode like so:

let sinkNode = AVAudioSinkNode() { (timestamp, frames, audioBufferList) -> OSStatus in
    print("SINK: \(timestamp.pointee.mHostTime) - \(frames) - \(audioBufferList.pointee.mNumberBuffers)")
    return noErr
}

audioEngine.attach(sinkNode)
audioEngine.connect(audioEngine.inputNode, to: sinkNode, format: nil)
audioEngine.prepare()

do {
    try audioEngine.start()
    print("AudioEngine started.")
} catch {
    print("AudioEngine did not start!")
}

我已经将其单独配置为使用内置麦克风设备(我确定

I've separately configured it to use the "Built-in Microphone" device (which I am sure it does use).

如果我为麦克风设置了采样率44100(使用苹果在所有Mac上提供的音频MIDI设置应用程序),则一切正常:

If I set sample rate 44100 for the mic (using "Audio MIDI Setup" app provided by Apple on all Macs), everything works as expected:

AudioEngine started.
SINK: 692312319180567 - 512 - 2
SINK: 692312348024104 - 512 - 2
SINK: 692312359634082 - 512 - 2
SINK: 692312371244059 - 512 - 2
SINK: 692312382854036 - 512 - 2
...

但是,如果我使用音频MIDI设置应用程序(由Apple在所有Mac上提供),然后将麦克风的采样率更改为除<44>(例如48000)以外的任何值,那么接收器节点似乎没有任何作用(什么都不打印)。

However, if I use "Audio MIDI Setup" app (provided by Apple on all Macs), and change the mic's sample rate to anything other than 44100 (say 48000), then the sink node doesn't seem to do anything (doesn't print anything).

当然,最初,我是想通过编程方式来修改麦克风的采样率。但是后来我发现,通过标准的音频MIDI设置应用程序更改设备采样率时,也会发生同样的情况。因此,我用于设置采样率的代码无需在此处发布。

Of course, originally I was trying to modify the mic's sample rate programmatically. But later on I discovered that the same happens when I just change the device sample rate via the standard "Audio MIDI Setup" app. Therefore, the code I have for setting the sample rate is unnecessary to post here.

有人知道是否 AVAudioSinkNode 允许将采样率硬编码到其中吗

我找不到其他解释...

I cannot find any other explanation...

推荐答案

I 我一直在玩AVAudioSinkNodes,在我看来,它并不受限于44100采样率。

I've been toying around with AVAudioSinkNodes and it doesn't appear to me to be restricted to a 44100 sampling rate.

在我的情况下,当我检查输入和接收器的采样率时节点附加后,我得到以下信息:

In my case, when I check the sampling rate of my input and sink nodes after attaching them, I get the following:

Input node sample rates: 
    IF <AVAudioFormat 0x600002527700:  2 ch,  48000 Hz, Float32, non-inter> 
    OF <AVAudioFormat 0x60000250fac0:  2 ch,  48000 Hz, Float32, non-inter>

Sink node sample rates: 
    IF <AVAudioFormat 0x60000250fbb0:  2 ch,  44100 Hz, Float32, non-inter> 
    OF <AVAudioFormat 0x60000250fb60:  2 ch,  44100 Hz, Float32, non-inter>

但是一旦将它们连接在一起,就会得到以下内容:

But once I connected them together, I got the following:

Input node sample rates: 
    IF <AVAudioFormat 0x600002527980:  1 ch,  48000 Hz, Float32> 
    OF <AVAudioFormat 0x600002506760:  2 ch,  48000 Hz, Float32, non-inter>

Sink node sample rates: 
    IF <AVAudioFormat 0x600002506710:  2 ch,  48000 Hz, Float32, non-inter> 
    OF <AVAudioFormat 0x600002505db0:  2 ch,  48000 Hz, Float32, non-inter>

我刚开始使用音频框架,但这似乎表明接收器节点的采样率不是

I'm new to working with audio frameworks, but this does seem to suggest that the sink node's sample rate isn't hardcoded.

您的连接

audioEngine.connect(audioEngine.inputNode, to: sinkNode, format: nil)

似乎与我的有所不同。对与错,我将格式明确指定为 audioEngine.inputNode.outputFormat(forBus:0),从而显示了设置。不确定是否会有所不同。

seems to differ from mine. Rightly or wrongly, I explicitly specified the format as audioEngine.inputNode.outputFormat(forBus: 0) which led to the settings shown. Not sure if that makes a difference.

这篇关于AVAudioSinkNode具有非默认值,但仍为设备本地采样率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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