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 1194 - Music integration, part 1
Summary: Music integration, part 1
Status: ASSIGNED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: x86 Windows 7
: P2 API change
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-29 19:01 UTC by Mason Wheeler
Modified: 2017-10-21 22:27 UTC (History)
2 users (show)

See Also:


Attachments
Diff patch for 1194 (46.91 KB, patch)
2011-04-29 19:02 UTC, Mason Wheeler
Details | Diff
Bugfix for first patch (1.39 KB, patch)
2011-04-29 19:43 UTC, Mason Wheeler
Details | Diff
Second bugfix patch (1.15 KB, patch)
2011-04-29 20:32 UTC, Mason Wheeler
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mason Wheeler 2011-04-29 19:01:41 UTC
Attached is the first (and probably most extensive) of a series of patches geared towards eliminating the technical barriers between SDL_Mixer's treatment of "sound" and "music".

This patch updates the API such that music no longer plays separately, but uses (and requires) a channel just like any other sound. Among other things, this means that effects can be registered against the music channels.

Theoretically, more than one music channel can be played at once.  This has not been tested, though, and may not work.  Any code changes necessary to support that will need to come in a later patch.  However, playing a single music channel and attaching effects to it has been tested and does work with this patch.
Comment 1 Mason Wheeler 2011-04-29 19:02:40 UTC
Created attachment 606 [details]
Diff patch for 1194
Comment 2 Mason Wheeler 2011-04-29 19:43:21 UTC
Created attachment 607 [details]
Bugfix for first patch

This patch fixes a double-free error in the first patch, and should be applied after it.
Comment 3 Mason Wheeler 2011-04-29 19:47:02 UTC
This has now been tested and will successfully play multiple songs together, at least with libmodplug.  I haven't tested with other music formats yet.  I know from looking at the code that multiple WAV-based songs will not play together; this will need to be fixed in a later patch.  Not sure about other decoders.
Comment 4 Mason Wheeler 2011-04-29 20:32:36 UTC
Created attachment 608 [details]
Second bugfix patch

Fixes an access violation when playing multiple songs sequentially on the same channel.  Should be applied after the first bugfix.
Comment 5 Sam Lantinga 2011-12-31 15:36:03 UTC
Thanks for the patches.  We're likely to merge SDL_sound into SDL_mixer in the next major release, so we can have a unified way to handle all kinds of sound formats.

Please let us know if that's something you'd be interested in tackling!

Cheers!
Comment 6 Nikos Chantziaras 2012-04-25 13:15:25 UTC
I'm reopening this, since I reworked Mason's patches.  (With current Mercurial default and SDL-1.2 branches in mind, of course.)  I've put up a Mercirial repo with all my changes here:

  https://bitbucket.org/realnc/sdl_mixer

I did not break binary or source compatibility; the new, channel-based music streams can be used in parallel with the old single-channel streams.

These backends now support multiple streams simultaneously:

MUS_WAV, MUS_OGG, MUS_FLAC, MUS_MP3, MUS_MP3_MAD, MUS_MID (with FluidSynth), MUS_MODPLUG.

The only ones that don't support multiple streams right now are MikMod and Timidity; they can only play one stream at a time (though they can play in parallel with any other music streams that use the other backends.)

Of course native MIDI cannot be supported since it works externally.  Not sure about MUS_CMD; will need to think about it a bit more.

I don't think this is ready for merging yet; needs testing first.  Hopefully the provided binary and source compatibility will make it easy to test against current applications.  My own tests are done on Linux.  Will also test on OS X and Windows soon.

Hopefully you guys can find a bit of time to review this.
Comment 7 Nikos Chantziaras 2012-04-26 03:07:53 UTC
(In reply to comment #6)
> [...]
> These backends now support multiple streams simultaneously:
> 
> MUS_WAV, MUS_OGG, MUS_FLAC, MUS_MP3, MUS_MP3_MAD, MUS_MID (with FluidSynth),
> MUS_MODPLUG.
> 
> The only ones that don't support multiple streams right now are MikMod and
> Timidity [...] Not sure about MUS_CMD; will need to think about it a bit more.

Turns out MUS_CMD works just fine.  So you can add that to the list of working backends.

After taking a good look at MikMod, it's obvious that it cannot support this.  And this is by design: libmikmod lacks any API that would allow it to play multiple modules.  Fortunately we have ModPlug.  Maybe we should drop MikMod completely, given that ModPlug supports more formats and has better sound quality anyway.
Comment 8 bastien.bouclet 2012-08-20 11:51:02 UTC
Is there any reason this hasn't been merged? Does it need more work? To me, the changes from this patched version are a must have when compared to the original version. My tests using alternatively samples and music on the same channels reveal no outstanding issues.
Comment 9 Nikos Chantziaras 2012-08-20 17:37:56 UTC
Just in case it isn't clear how to merge with mercurial, it's simply a:

  hg pull -u https://bitbucket.org/realnc/sdl_mixer

One thing we're losing with the new API though is gapless music support. I couldn't find a quick way to keep that one working. Previously, if you started a new Mix_Music from inside the Mix_HookMusicFinished() callback, the transition was gapless. Now there's a slight gap there.