Looks like a buffer misalignment issue. The glitch is periodic, my bet is
this is equal to some multiple of your block size. Can't tell what's really
going on from your code. Check your input proc perhaps?

Kevin

On Mon, Apr 13, 2015 at 8:29 PM, Anthony Myatt <[email protected]> wrote:

> Hello,
>
> I am converting from the following format:
>
>     const int four_bytes_per_float = 4;
>     const int eight_bits_per_byte = 8;
>     _stereoGraphStreamFormat.mFormatID          = kAudioFormatLinearPCM;
>     _stereoGraphStreamFormat.mFormatFlags       =
> kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
>     _stereoGraphStreamFormat.mBytesPerPacket    = four_bytes_per_float;
>     _stereoGraphStreamFormat.mFramesPerPacket   = 1;
>     _stereoGraphStreamFormat.mBytesPerFrame     = four_bytes_per_float;
>     _stereoGraphStreamFormat.mChannelsPerFrame  = 2;
>     _stereoGraphStreamFormat.mBitsPerChannel    = eight_bits_per_byte *
> four_bytes_per_float;
>     _stereoGraphStreamFormat.mSampleRate        = 44100;
>
> to the following format:
>
>     interleavedAudioDescription.mFormatID          =
> kAudioFormatLinearPCM;
>     interleavedAudioDescription.mFormatFlags       =
> kAudioFormatFlagIsSignedInteger;
>     interleavedAudioDescription.mChannelsPerFrame  = 2;
>     interleavedAudioDescription.mBytesPerPacket    =
> sizeof(SInt16)*interleavedAudioDescription.mChannelsPerFrame;
>     interleavedAudioDescription.mFramesPerPacket   = 1;
>     interleavedAudioDescription.mBytesPerFrame     =
> sizeof(SInt16)*interleavedAudioDescription.mChannelsPerFrame;
>     interleavedAudioDescription.mBitsPerChannel    = 8 * sizeof(SInt16);
>     interleavedAudioDescription.mSampleRate        = 44100;
>
> Using the following code:
>
>     int32_t availableBytes = 0;
>
>     void* tailL = TPCircularBufferTail(inputBufferL(), &availableBytes);
>     void* tailR = TPCircularBufferTail(inputBufferR(), &availableBytes);
>
>     // If we have no data in the buffer, we simply return
>     if (availableBytes <= 0)
>     {
>         return;
>     }
>
>
>     // ========== Non-Interleaved to Interleaved (Plus Samplerate
> Conversion) =========
>
>
>
>     // Get the number of frames available
>     UInt32 frames = availableBytes / this->mInputFormat.mBytesPerFrame;
>
>
>     pcmOutputBuffer->mBuffers[0].mDataByteSize = frames *
> interleavedAudioDescription.mBytesPerFrame;
>
>
>     struct complexInputDataProc_t data = (struct complexInputDataProc_t) {
> .self = this, .sourceL = tailL, .sourceR = tailR, .byteLength =
> availableBytes };
>
>
>
>     // Do the conversion
>     OSStatus result =
> AudioConverterFillComplexBuffer(interleavedAudioConverter,
>                                                       complexInputDataProc,
>                                                       &data,
>                                                       &frames,
>                                                       pcmOutputBuffer,
>                                                       NULL);
>
>
>
>     // Tell the buffers how much data we consumed during the conversion so
> that it can be removed
>     TPCircularBufferConsume(inputBufferL(), availableBytes);
>     TPCircularBufferConsume(inputBufferR(), availableBytes);
>
>
>     // ========== Buffering Of Interleaved Samples =========
>
>
>
>     // If we got converted frames back from the converter, we want to add
> it to a separate buffer
>     if (frames > 0)
>     {
>         // Make sure we have enough space in the buffer to store the new
> data
>         TPCircularBufferHead(&pcmCircularBuffer, &availableBytes);
>
>
>         if (availableBytes > pcmOutputBuffer->mBuffers[0].mDataByteSize)
>         {
>             // Add the newly converted data to the buffer
>             TPCircularBufferProduceBytes(&pcmCircularBuffer,
> pcmOutputBuffer->mBuffers[0].mData, frames *
> interleavedAudioDescription.mBytesPerFrame);
>         }
>         else
>         {
>             printf("No Space in Buffer\n");
>         }
>     }
>
>
> However I am getting the following output:
>
>
> It should be a perfect sine wave, however as you can see it is not.
>
> I have been working on this for days now and just can’t seem to find where
> it is going wrong.
> Can anyone see something that I might be missing?
>
>
> Kind regards,
>
> Anthony Myatt
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
>
> https://lists.apple.com/mailman/options/coreaudio-api/kevin.c.dixon%40gmail.com
>
> This email sent to [email protected]
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to