gpt4 book ai didi

iphone - AudioUnit 设置属性错误(错误代码-10868)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:24:20 33 4
gpt4 key购买 nike

我正在尝试使用 AudioStreamBasicDescription 在 AudioUnit 中设置一个属性。我正在尝试设置声音数据的格式。返回的错误代码是-10868。它只发生在 iOS 3.1.3 或更低版本上,但适用于 3.2 或更高版本。所以它可以在模拟器中运行,在运行 4.2 的 iPod touch 上运行,但不能在第一代 iPod touch 上运行。

当我尝试为 AudioUnit 音调单元设置格式时发生错误。代码如下所示(来自 cocoawithlove.com )

// Set the format to 32 bit, single channel, floating point, linear PCM
const int four_bytes_per_float = 4;
const int eight_bits_per_byte = 8;
AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = sampleRate;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
streamFormat.mBytesPerPacket = four_bytes_per_float;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = four_bytes_per_float;
streamFormat.mChannelsPerFrame = 1;
streamFormat.mBitsPerChannel = four_bytes_per_float * eight_bits_per_byte;
err = AudioUnitSetProperty (toneUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&streamFormat,
sizeof(AudioStreamBasicDescription));
// err now has error code -10868

我检查了标题,这个错误代码对应于错误“kAudioUnitErr_FormatNotSupported”。所以我想我尝试设置的格式在 iOS 3.1 上不受支持?在哪里可以找到支持的格式?关于我可以尝试的其他格式的任何指示?

使用的渲染回调:

OSStatus RenderTone(
void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)

{
// Fixed amplitude is good enough for our purposes
const double amplitude = 0.25;

// Get the tone parameters out of the view controller
ToneGeneratorViewController *viewController =
(ToneGeneratorViewController *)inRefCon;
double theta = viewController->theta;
double theta_increment =
2.0 * M_PI * viewController->frequency / viewController->sampleRate;

// This is a mono tone generator so we only need the first buffer
const int channel = 0;
Float32 *buffer = (Float32 *)ioData->mBuffers[channel].mData;

// Generate the samples
for (UInt32 frame = 0; frame < inNumberFrames; frame++)
{
buffer[frame] = sin(theta) * amplitude;

theta += theta_increment;
if (theta > 2.0 * M_PI)
{
theta -= 2.0 * M_PI;
}
}

// Store the updated theta back in the view controller
viewController->theta = theta;

return noErr;
}

最佳答案

我认为主要问题是 iOS 4.0 之前的版本不支持浮点音频。我不确定 ARM float 支持有什么用,但我建议使用其中一种定点格式进行输入和输出。

关于iphone - AudioUnit 设置属性错误(错误代码-10868),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6722598/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com