static void FillBufferPortion(char * ptr, int remaining) { int len; char *sptr; while (remaining > 0) { if (MixBufferUsed == MixBufferSize) { MixCallBack(); MixBufferUsed = 0; MixBufferCurrent++; if (MixBufferCurrent >= MixBufferCount) { MixBufferCurrent -= MixBufferCount; } } while (remaining > 0 && MixBufferUsed < MixBufferSize) { sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed; len = MixBufferSize - MixBufferUsed; if (remaining < len) { len = remaining; } memcpy(ptr, sptr, len); ptr += len; MixBufferUsed += len; remaining -= len; } } }
int32_t SDLDrv_PCM_BeginPlayback(char *BufferStart, int32_t BufferSize, int32_t NumDivisions, void ( *CallBackFunc )( void ) ) { if (!Initialised) { ErrorCode = SDLErr_Uninitialised; return SDLErr_Error; } if (Playing) { SDLDrv_PCM_StopPlayback(); } MixBuffer = BufferStart; MixBufferSize = BufferSize; MixBufferCount = NumDivisions; MixBufferCurrent = 0; MixBufferUsed = 0; MixCallBack = CallBackFunc; // prime the buffer MixCallBack(); Mix_Resume(-1); Playing = 1; return SDLErr_Ok; }
int CoreAudioDrv_PCM_BeginPlayback(char *BufferStart, int BufferSize, int NumDivisions, void ( *CallBackFunc )( void ) ) { if (!Initialised) { ErrorCode = CAErr_Uninitialised; return CAErr_Error; } if (Playing) { CoreAudioDrv_PCM_StopPlayback(); } MixBuffer = BufferStart; MixBufferSize = BufferSize; MixBufferCount = NumDivisions; MixBufferCurrent = 0; MixBufferUsed = 0; MixCallBack = CallBackFunc; // prime the buffer MixCallBack(); AudioOutputUnitStart(output_audio_unit); Playing = 1; return CAErr_Ok; }
static OSStatus fillInput( void * inRefCon, AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * ioDataList) { UInt32 remaining, len; char *ptr, *sptr; AudioBuffer *ioData; ioData = &ioDataList->mBuffers[0]; remaining = ioData->mDataByteSize; ptr = ioData->mData; while (remaining > 0) { if (MixBufferUsed == MixBufferSize) { CoreAudioDrv_PCM_Lock(); MixCallBack(); CoreAudioDrv_PCM_Unlock(); MixBufferUsed = 0; MixBufferCurrent++; if (MixBufferCurrent >= MixBufferCount) { MixBufferCurrent -= MixBufferCount; } } while (remaining > 0 && MixBufferUsed < MixBufferSize) { sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed; len = MixBufferSize - MixBufferUsed; if (remaining < len) { len = remaining; } memcpy(ptr, sptr, len); ptr += len; MixBufferUsed += len; remaining -= len; } } return noErr; }
static void fillData(int32_t chan, void *ptr, int32_t remaining, void *udata) { int32_t len; char *sptr; UNREFERENCED_PARAMETER(chan); UNREFERENCED_PARAMETER(udata); if (!MixBuffer || !MixCallBack) return; SDL_LockMutex(EffectFence); while (remaining > 0) { if (MixBufferUsed == MixBufferSize) { MixCallBack(); MixBufferUsed = 0; MixBufferCurrent++; if (MixBufferCurrent >= MixBufferCount) { MixBufferCurrent -= MixBufferCount; } } while (remaining > 0 && MixBufferUsed < MixBufferSize) { sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed; len = MixBufferSize - MixBufferUsed; if (remaining < len) { len = remaining; } memcpy(ptr, sptr, len); ptr = (void *)((uintptr_t)(ptr) + len); MixBufferUsed += len; remaining -= len; } } SDL_UnlockMutex(EffectFence); }