AudioStreamBasicDescriptionを使用してAudioUnitでプロパティを設定しようとしています。サウンドデータのフォーマットを設定しようとしています。返されるエラーコードは-10868です。 iOS 3.1.3以下でのみ発生しますが、3.2以上で動作します。したがって、シミュレータでは、iPod touchの4.2では動作しますが、第1世代のiPod touchでは動作しません。AudioUnitプロパティのエラー(エラーコード-10868)
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ではサポートされていないと思いますか?サポートされているフォーマットはどこで見つけることができますか?私が試してみることができる他のフォーマット上の任意のポインタ?
使用されるコールバックレンダリング:私は主な問題は、浮動小数点オーディオは前のバージョン4.0へのiOSでサポートされていなかったということだと思います
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;
}
これは正しいと思われます。私はAudioUnitのプログラミングとサウンドプログラミングには一般的に新しいです。レンダリングコールバックを浮動小数点から固定小数点形式に変換するにはどうすればいいですか?レンダリングコールバックを表示するために質問を更新します。 – ErikPerik