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

标签 iphone ios audiounit iphone-sdk-3.1

我正在尝试使用 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/

相关文章:

ios - 将Objective-C AudioUnits简介转换为Swift

IOS:audioEngine 的自定义实时音频效果?

iphone - iPhone麦克风音量

ios - 如何使 UIScrollView/UIPageControl 无限?

ios - 将 App 置于可编辑状态

javascript - Dropbox 选择按钮返回错误消息

ios - maximumFramesPerSlice,inNumberFrames和缓冲区持续时间之间的差异

ios - 在 Objective-C 中设置日期格式

iphone - 使用 MKstorekit4 实现不可更新订阅?

ios - 如何在 OauthSwift 库中设置回调 URL