Re: memcpy woes
Re: memcpy woes
- Subject: Re: memcpy woes
- From: Hamilton Feltman <email@hidden>
- Date: Wed, 17 Aug 2011 20:42:30 -0700
You're on the right track, it's weird that he uses a memcpy per sample, a single memcpy will take care of this as long as the data formats are the same.
You could do something like this:
AudioSampleType *sample = musicPlaybackState->samplePtr; AudioBuffer buf = ioData->mBuffers[0];
memcpy(buf.mData, sample, inNumberFrames * sizeof(AudioSampleType));
musicPlaybackState->samplePtr += inNumberFrames * sizeof(AudioSampleType);
But there might be bigger problems already, for example samplePtr is modified in this audio callback thread. So what happens when it runs out of data, you can't modify it from another thread and expect good things. Better to use a lockless ringbuffer.
Also, always check the number of buffers and the sizes and whether it contains interleaved stereo data instead of blindly writing to it.
On Aug 17, 2011, at 6:23 AM, pollock mcgee wrote: 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
References: | |
| >memcpy woes (From: pollock mcgee <email@hidden>) |