• 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
memcpy woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

memcpy woes


  • Subject: memcpy woes
  • From: pollock mcgee <email@hidden>
  • Date: Wed, 17 Aug 2011 13:23:58 +0000
  • Importance: Normal

Hi, I was wondering if someone could help. I am trying to decipher a buffer so I can verify that I understand how it works. It is a render callback that takes samples from an audio file that is referenced by the object musicPlayerState. The original code walks through the samples one at a time and copies them over to the buffer using memcpy in a for loop. 

musicPlaybackState->samplePtr stores the position of the audio file.  
currentframe is declared globally and initialised to zero.

What I am trying to do is remove the for loop so the callback simply dumps the entire 512 frames into the ioData buffer and then exits and thus avoiding the need to use the for loop. The code is a little convoluted. I have posted the original unmolested code underneath for clarity. It is taken from Chris Adamson's DalekSingalong code. 
I've been at it for days and I just can't seem to figure out whats going wrong or if it is even possible.





OSStatus MusicPlayerCallback (

   void * inRefCon,

   AudioUnitRenderActionFlags  * ioActionFlags,

   const AudioTimeStamp * inTimeStamp,

   UInt32 inBusNumber,

   UInt32 inNumberFrames,

   AudioBufferList * ioData) {

MusicPlaybackState *musicPlaybackState = (MusicPlaybackState*) inRefCon;

AudioSampleType *sample = musicPlaybackState->samplePtr;

size_t count= 1024;

AudioBuffer buf = ioData->mBuffers[0];


memcpy(buf.mData + ((currentframe)*(2)),

   sample,

   count);

currentframe+=512;

sample +=512;

musicPlaybackState->samplePtr = sample;

return noErr;

}


////////////Original code that works fine/////////////



OSStatus MusicPlayerCallback (

  void * inRefCon,

  AudioUnitRenderActionFlags * ioActionFlags,

  const AudioTimeStamp * inTimeStamp,

  UInt32 inBusNumber,

  UInt32 inNumberFrames,

  AudioBufferList * ioData) {

MusicPlaybackState *musicPlaybackState = (MusicPlaybackState*) inRefCon;



AudioSampleType *sample = musicPlaybackState->samplePtr;

size_t count= 2;

AudioBuffer buf = ioData->mBuffers[0];


for (int currentframe=0; currentframe<inNumberFrames; currentframe++) {

 

memcpy(buf.mData + ((currentframe)*(2)),

  sample,

  count);

sample ++;

musicPlaybackState->samplePtr = sample;

}

 _______________________________________________
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: memcpy woes
      • From: Hamilton Feltman <email@hidden>
  • Prev by Date: Re: Identifying AUs from host?
  • Next by Date: AMR-NB in Lion
  • Previous by thread: Re: Question about HostCallback_GetTransportState
  • Next by thread: Re: memcpy woes
  • Index(es):
    • Date
    • Thread