We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 413 - Mix_Chunk loop/callback error with samples of certain lengths
Summary: Mix_Chunk loop/callback error with samples of certain lengths
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: PowerPC Mac OS X 10.4 (Intel)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-08 18:27 UTC by Jesse Anders
Modified: 2007-07-14 21:42 UTC (History)
1 user (show)

See Also:


Attachments
Audio sample (24.06 KB, audio/wav)
2007-03-08 18:34 UTC, Jesse Anders
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Anders 2007-03-08 18:27:40 UTC
In the mix_channels() function, it appears that looping and playback termination behaves incorrectly when the length of the sample is an even multiple of the value of the 'len' argument. When the 'loop' argument to Mix_PlayChannel() is > 0, the sound plays back one fewer times than requested, and the callback is not called when the sound finishes playing.

Here is a short program that demonstrates this behavior:

/******************************************************************************/

#include "SDL.h"
#include "SDL_mixer.h"

#include <iostream>

void Callback(int) { std::cout << "Callback() was called." << std::endl; }

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_AUDIO);
    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
    Mix_ChannelFinished(Callback);

    std::cout << "\nPlaying sample with loop = 1: Should play twice, but\n"
              << "will only play once and callback will not be called.\n\n"
              << "(Press any key followed by enter to quit)" << std::endl;

    Mix_Chunk* sound = Mix_LoadWAV("sdl_mixer_bug.wav");
    Mix_PlayChannel(-1, sound, 1);

    std::cin.get();

    Mix_FreeChunk(sound);
    Mix_CloseAudio();
    SDL_Quit();

    return 0;
}

/******************************************************************************/

Here is the URL of the audio file used:

http://cmldev.net/wp-content/uploads/2007/03/sdl_mixer_bug.wav

The length of this particular sample is 98304, which is an even multiple of 4096, the value I get for the mix_channels() 'len' argument when the buffer size is set to 1024.

I'm using SDL_mixer 1.2.7 in OS X 10.4.8.
Comment 1 Jesse Anders 2007-03-08 18:34:20 UTC
Created attachment 197 [details]
Audio sample

Here is the audio sample as an attachment.
Comment 2 Sam Lantinga 2007-07-14 21:42:10 UTC
This is fixed in subversion revision 3277, thanks!  This was a great test case, BTW.