user293895
user293895

Reputation: 1527

Heavy Distortion when playing vorbis in RemoteIO Audio Unit

I am trying to play an Ogg Vorbis file in RemoteIO, I use the following code for gaining the PCM samples from the vorbis:I am trying to play an Ogg Vorbis file in RemoteIO, I use the following code for gaining the PCM samples from the vorbis:

ssize_t r = ov_read(ds->vf,pcm->buf,sizeof(pcm->buf),SYSTEM_ENDIAN,2,1,NULL);

According to the docs on ov_read this puts samples in the buffer with a little endian format, 16 bit signed samples. This works fine, and I have been feeding the RemoteIO this data, however the sound is heavily distorted, although recognisable and playing in the right time. This is the format I am using:

AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = 44100.0;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
streamFormat.mBytesPerPacket = 4;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = 4;
streamFormat.mChannelsPerFrame = 2;
streamFormat.mBitsPerChannel = 16;

Upvotes: 1

Views: 201

Answers (1)

Nik Reiman
Nik Reiman

Reputation: 40390

When looking at your code, a few things jump out, though I'm not sure that any (or all) of them are necessarily responsible for the problems you've described.

First of all, streamFormat.mBytesPerPacket should be 8 if you are doing stereo processing. On iOS/OSX, it's important to understand the relationship between frames, channels, and a packet. It looks something like this:

Frames, Channels, and Packets, oh my!

Moreover, I would add kAudioFormatFlagsNativeEndian to streamFormat.mFormatFlags. Also, I would suggest setting streamFormat.mReserved to 0 just to be on the safe side.

I'm a bit suspicious that the SYSTEM_ENDIAN flag in your call to ov_read() will deliver you data correctly, so if there are corresponding flags for big/little endian, I'd suggest trying them as well.

Upvotes: 1

Related Questions