xcode 音频单元采样率和缓冲区大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8739408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
audio-unit sample rate and buffer size
提问by Curnelious
i am facing a really misunderstanding when sampling the iphone audio with remoteIO.
在使用 remoteIO 对 iphone 音频进行采样时,我面临着一个真正的误解。
from one side, i can do this math: 44khz sample rate means 44 samples per 1ms. which means if i set bufferSize to 0.005 with :
一方面,我可以做这个数学运算:44khz 采样率意味着每 1 毫秒 44 个样本。这意味着如果我将 bufferSize 设置为 0.005:
float bufferLength = 0.00005;
AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(bufferLength), &bufferLength);
which means 5ms buffer size -which means 44*5=220 samples in buffer each callback.
BUT i get 512 samples from inNumberFrames
each callback . and it stay's fixed even when i change buffer length.
这意味着 5ms 缓冲区大小 - 这意味着每个回调缓冲区中有 44*5=220 个样本。但是我从inNumberFrames
每个回调中得到 512 个样本。即使我更改缓冲区长度,它也保持固定。
another thing , my callbacks are every 11ms and is not changing! i need faster callbacks .
另一件事,我的回调每 11 毫秒一次并且没有改变!我需要更快的回调。
so ! what is going on here ? who set what ?
所以 !这里发生了什么 ?谁设什么?
i need to pass a digital information in an FSK modulation, and have to know exactly buffer size in samples, and what time from the signal it has , in order to know how to FFT it correctly .
我需要在 FSK 调制中传递数字信息,并且必须确切知道样本中的缓冲区大小,以及它具有的信号的时间,以便知道如何正确地对其进行 FFT。
any explanation on this ? thanks a lot.
对此有何解释?多谢。
回答by hotpaw2
There is no way on all current iOS 10 devices to get RemoteIO audio recording buffer callbacks at a faster rate than every 5 to 6 milliseconds. The OS may even decide to switch to sending even larger buffers at a lower callback rate at runtime. The rate you request is merely a request, the OS then decides on the actual rates that are possible for the hardware, device driver, and device state. This rate may or may not stay fixed, so your app will just have to deal with different buffer sizes and rates.
所有当前的 iOS 10 设备都无法以比每 5 到 6 毫秒更快的速度获得 RemoteIO 音频记录缓冲区回调。操作系统甚至可能决定在运行时切换到以更低的回调率发送更大的缓冲区。您请求的速率只是一个请求,然后操作系统决定硬件、设备驱动程序和设备状态可能的实际速率。这个速率可能会也可能不会保持固定,所以你的应用程序只需要处理不同的缓冲区大小和速率。
One of your options might be to concatenate each callback buffer onto your own buffer, and chop up this second buffer however you like outside the audio callback. But this won't reduce actual latency.
您的选择之一可能是将每个回调缓冲区连接到您自己的缓冲区,然后在音频回调之外根据您的喜好切碎第二个缓冲区。但这不会减少实际延迟。
Added: some newer iOS devices allow returning audio unit buffers that are shorter than 5.x mS in duration, usually a power of 2 in size at a 48000 sample rate.
补充:一些较新的 iOS 设备允许返回持续时间短于 5.x 毫秒的音频单元缓冲区,通常在 48000 采样率下大小为 2 的幂。
回答by justin
i need to pass a digital information in an FSK modulation, and have to know exactly buffer size in samples, and what time from the signal it has , in order to know how to FFT it correctly.
我需要在 FSK 调制中传递数字信息,并且必须确切地知道样本中的缓冲区大小,以及它具有的信号的时间,以便知道如何正确地对其进行 FFT。
It doesn't work that way - you don't mandate various hosts or hardware to operate in an exact manner which is optimal for your processing. You can request reduced latency - to a point. Audio systems generally pass streaming pcm data in blocks of samples sized by a power of two for efficient realtime io.
它不是这样工作的 - 您不会要求各种主机或硬件以最适合您的处理的精确方式运行。您可以要求减少延迟 - 在一定程度上。音频系统通常以大小为 2 的幂的样本块的形式传递流式 pcm 数据,以实现高效的实时 io。
You would create your own buffer for your processor, and report latency (where applicable). You can attempt to reduce wall latency by choosing another sample rate, or by using a smaller N.
您将为处理器创建自己的缓冲区,并报告延迟(如果适用)。您可以尝试通过选择其他采样率或使用较小的 N 来减少墙延迟。
回答by jaybers
The audio session property is a suggested value. You can put in a really tiny number but will just go to the lowest value it can. The fastest that I have seen on an iOS device when using 16 bit stereo was 0.002902 second
( ~3ms ).
音频会话属性是一个建议值。你可以输入一个非常小的数字,但只会达到它所能达到的最低值。使用 16 位立体声时,我在 iOS 设备上看到的最快速度是0.002902 second
( ~3ms )。
That is 128 samples (LR stereo frames) per callback. Thus, 512 bytes per callback.
So 128/44100 = 0.002902 seconds
.
即每个回调 128 个样本(LR 立体声帧)。因此,每个回调 512 字节。所以128/44100 = 0.002902 seconds
。
You can check it with:
您可以通过以下方式检查:
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, &size, &bufferDuration)
Could the value 512 in the original post have meant bytes instead of samples?
原始帖子中的值 512 是否意味着字节而不是样本?