• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TPCircularBuffer Recording for later Playback
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TPCircularBuffer Recording for later Playback


  • Subject: Re: TPCircularBuffer Recording for later Playback
  • From: Morgan Packard <email@hidden>
  • Date: Wed, 31 Oct 2012 14:59:46 -0400

As I understand it, a circular buffer is for short-term transfer of a relatively small amount of data, often between threads, one of which is a dedicated "producer", and the other of which is the "consumer". If all you need to do is store some data for later, there's no need for a circular buffer -- you can just write to memory and read it when you're ready.
-Morgan

On Wed, Oct 31, 2012 at 2:55 PM, Kevin Dixon <email@hidden> wrote:
Make sure you are satisfying the channel expectations of the RemoteIO
unit. For example, are you feeding interleaved data of two channels
into a single channel output?

-Kevin

On Tue, Oct 30, 2012 at 11:24 PM, Pier <email@hidden> wrote:
> Hi,
>
>
> I'm trying to write a bunch of samples to a a TPCircularBuffer, provided
> Michael Tyson by
> http://atastypixel.com/blog/a-simple-fast-circular-buffer-implementation-for-audio-processing/comment-page-1/#comment-4988
>
>
> I am successful in playing back these recorded samples in real time.
> Something like a monitor.
>
>
> However, I wish to keep the samples in the TPCircularBuffer for later
> playback, and so I implemented 2 flags, rio->recording and rio->playing.
>
> My idea was that I would activate rio->recording to be YES using a button.
> Record for a while, and then stop recording by setting the flag to be NO.
> Theoretically, TPCircularBuffer would have my audio info saved.
>
>
> However, when I activate rio->playing to be YES in the playback Callback, I
> simply hear some jittery sound that has no semblance of what I recorded.
>
>
> Am I using the buffer correctly? Or is this usually done another way?
>
>
> Thanks.
>
>
> Pier.
>
>
>
> static OSStatus recordingCallback(void *inRefCon,
>
>                                   AudioUnitRenderActionFlags *ioActionFlags,
>
>                                   const AudioTimeStamp *inTimeStamp,
>
>                                   UInt32 inBusNumber,
>
>                                   UInt32 inNumberFrames,
>
>                                   AudioBufferList *ioData) {
>
>
>     RIO *rio = (RIO*)inRefCon;
>
>     AudioUnit rioUnit = rio->theAudioUnit;
>
>     //ExtAudioFileRef eaf = rio->outEAF;
>
>     AudioBufferList abl = rio->audioBufferList;
>
>
>
>     SInt32 samples[NUMBER_OF_SAMPLES]; // A large enough size to not have to
> worry about buffer overrun
>
>     abl.mNumberBuffers = 1;
>
>     abl.mBuffers[0].mData = &samples;
>
>     abl.mBuffers[0].mNumberChannels = 1;
>
>     abl.mBuffers[0].mDataByteSize = inNumberFrames  * sizeof(SInt16);
>
>
>
>     OSStatus result;
>
>     result = AudioUnitRender(rioUnit,
>
>                              ioActionFlags,
>
>                              inTimeStamp,
>
>                              inBusNumber,
>
>                              inNumberFrames,
>
>                              &abl);
>
>
>
>     if (noErr != result) { NSLog(@"Obtain recorded samples error"); }
>
>
>
>     // React to a recording flag, if recording, save the abl into own
> buffer, else ignore
>
>     if (rio->recording)
>
>     {
>
>         TPCircularBufferProduceBytes(&rio->buffer, abl.mBuffers[0].mData,
> inNumberFrames  * sizeof(SInt16));
>
>         NSLog(@"Recording!");
>
>     }
>
>     else
>
>     {
>
>         NSLog(@"Not Recording!");
>
>     }
>
>     // once stop recording save the circular buffer to a temp circular
> buffer
>
>
>     return noErr;
>
> }
>
>
> static OSStatus playbackCallback(void *inRefCon,
>
>                                  AudioUnitRenderActionFlags *ioActionFlags,
>
>                                  const AudioTimeStamp *inTimeStamp,
>
>                                  UInt32 inBusNumber,
>
>                                  UInt32 inNumberFrames,
>
>                                  AudioBufferList *ioData) {
>
>
>
>     RIO *rio = (RIO*)inRefCon;
>
>
>
>     int bytesToCopy = ioData->mBuffers[0].mDataByteSize;
>
>     SInt16 *targetBuffer = (SInt16*)ioData->mBuffers[0].mData;
>
>
>
>     // Pull audio from playthrough buffer
>
>     int32_t availableBytes;
>
>
>
>     if (rio->playing)
>
>     {
>
>         SInt16 * tempbuffer = TPCircularBufferTail(&rio->buffer,
> &availableBytes);
>
>         memcpy(targetBuffer, tempbuffer, MIN(bytesToCopy, availableBytes));
>
>         TPCircularBufferConsume(&rio->buffer, MIN(bytesToCopy,
> availableBytes));
>
>         NSLog(@"Playing!");
>
>     }
>
>     else
>
>     {
>
>        NSLog(@"Playing silence!");
>
>
>
>        for (int i = 0 ; i < ioData->mNumberBuffers; i++){
>
>         //get the buffer to be filled
>
>         AudioBuffer buffer = ioData->mBuffers[i];
>
>         UInt32 *frameBuffer = buffer.mData;
>
>
>         //loop through the buffer and fill the frames
>
>            for (int j = 0; j < inNumberFrames; j++){
>
>                frameBuffer[j] = 0;
>
>            }
>
>        }
>
>     }
>
>
>    return noErr;
>
> }
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



--
===============
Morgan Packard
cell: (720) 891-0122
aim: mpackardatwork
twitter: @morganpackard

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: TPCircularBuffer Recording for later Playback
      • From: Pier <email@hidden>
References: 
 >TPCircularBuffer Recording for later Playback (From: Pier <email@hidden>)
 >Re: TPCircularBuffer Recording for later Playback (From: Kevin Dixon <email@hidden>)

  • Prev by Date: Re: TPCircularBuffer Recording for later Playback
  • Next by Date: Handling Interruptions While Recording in AAC is Difficult
  • Previous by thread: Re: TPCircularBuffer Recording for later Playback
  • Next by thread: Re: TPCircularBuffer Recording for later Playback
  • Index(es):
    • Date
    • Thread