Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa AVAUDIOBUFER和AVAudioFormat,将interleaved设置为true将生成零值样本数据_Cocoa_Avfoundation - Fatal编程技术网

Cocoa AVAUDIOBUFER和AVAudioFormat,将interleaved设置为true将生成零值样本数据

Cocoa AVAUDIOBUFER和AVAudioFormat,将interleaved设置为true将生成零值样本数据,cocoa,avfoundation,Cocoa,Avfoundation,我有一个Cocoa应用程序,它使用AVAudioBuffer和AVAudioFormat从音频文件读取样本数据。然而,我对AVAudioFormat的交织属性感到困惑 下面是代码(Xamarin,但这不应该是相关的)\u文件是AVAudioFile的一个实例 using (var format = new AVAudioFormat(AVAudioCommonFormat.PCMFloat32, _file.FileFormat.SampleRate, channelCount, interle

我有一个Cocoa应用程序,它使用
AVAudioBuffer
AVAudioFormat
从音频文件读取样本数据。然而,我对
AVAudioFormat
的交织属性感到困惑

下面是代码(Xamarin,但这不应该是相关的)<代码>\u文件是
AVAudioFile
的一个实例

using (var format = new AVAudioFormat(AVAudioCommonFormat.PCMFloat32, _file.FileFormat.SampleRate, channelCount, interleaved: true))
using (var buffer = new AVAudioPcmBuffer(format, checked((uint)frameCount)))
{
    _file.ReadIntoBuffer(buffer, out var error);

    Span<float> span;
    unsafe
    {
        var bufferPointer = (float*)Marshal.ReadIntPtr(buffer.FloatChannelData);
        span = new Span<float>(bufferPointer, (int)(frameCount * channelCount));
    }

    return span.ToArray();
}
使用(var格式=新的AVAudioFormat(AVAudioCommonFormat.PCMFloat32,_file.FileFormat.SampleRate,channelCount,交错:true))
使用(var buffer=new AVAudioPcmBuffer(格式,选中((uint)帧数)))
{
_ReadIntoBuffer(buffer,out-var错误);
跨度;
不安全的
{
var bufferPointer=(float*)Marshal.ReadIntPtr(buffer.FloatChannelData);
span=新的span(缓冲指针,(int)(帧计数*通道计数));
}
返回span.ToArray();
}
因此,这其中的关键部分是传递给
AVAudioFormat
的构造函数的交错值。如果为true(如上所述),则缓冲区中的
FloatChannelData
均为零。如果为false,则样本数据按预期显示

我感到困惑,因为我假设交错值指定了缓冲区中数据的所需格式。我试图找到解释其作用的文档,但没有成功

请有人解释一下交错的作用,我应该如何决定要使用的值,以及为什么当它为真时,样本数据都为零


这里显然有一些需要学习的地方,因此,如果您能给我指一些官方(或其他)文档来解释这一点,我将不胜感激。

您明白了吗?不,对不起。如果我这样做了,我会发布更新。