Я пытаюсь установить свойство в AudioUnit, используя AudioStreamBasicDescription. Я пытаюсь установить формат для звуковых данных. Возвращенный код ошибки -10868. Это происходит только на iOS 3.1.3 или ниже, но работает на 3.2 или выше. Так что он работает в симуляторе, на iPod touch под управлением 4.2, но не на iPod touch 1-го поколения.
Ошибка возникает, когда я пытаюсь установить формат для тонального блока 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;
}