Ticket #5093: PushGameSound.patch

File PushGameSound.patch, 1.3 KB (added by bmkx, 14 years ago)

Small fixes for BPushGameSound

  • src/kits/game/PushGameSound.cpp

     
    1616
    1717
    1818BPushGameSound::BPushGameSound(size_t inBufferFrameCount, const gs_audio_format *format,
    19             size_t inBufferCount, BGameSoundDevice *device)
    20     :   BStreamingGameSound(inBufferFrameCount, format, inBufferCount, device)
     19        size_t inBufferCount, BGameSoundDevice *device)
     20    :
     21    BStreamingGameSound(inBufferFrameCount, format, inBufferCount, device),
     22    fLockPos(0),
     23    fPlayPos(0)
    2124{
    2225    fPageLocked = new BList;
    2326
     
    153156        return;
    154157   
    155158    if (fPlayPos + bytes > fBufferSize) {
    156         size_t remainder = fPlayPos + bytes - fBufferSize;
     159        size_t remainder = fBufferSize - fPlayPos;
    157160        char * buffer = (char*)inBuffer;
    158161       
    159162        // fill the buffer with the samples left at the end of our buffer
    160         memcpy(buffer, &fBuffer[fPlayPos], remainder);
     163        if (remainder)
     164            memcpy(buffer, &fBuffer[fPlayPos], remainder);
    161165        fPlayPos = 0;
    162166       
    163167        // fill the remainder of the buffer by looping to the start
     
    170174    } else {
    171175        memcpy(inBuffer, &fBuffer[fPlayPos], bytes);
    172176        fPlayPos += bytes;
     177        fPlayPos %= fBufferSize;
    173178    }
    174179   
    175180    BStreamingGameSound::FillBuffer(inBuffer, inByteCount);