More MIDI woes

While playing MIDI files in SDL_Mixer, I found that most MIDIs will load up and start playing immediately, but a few don’t. The attached file, for example, takes approximately 1300 milliseconds from the method call to when I start hearing music.

I’m linking against the latest official version of SDL_Mixer and of SDL, under Win32. At first I thought the problem might be thread-related, so I made sure to call Mix_LoadMUS() and Mix_PlayMusic() from the main thread, but that didn’t change anything.

Anyone know anything about this?

-------------- next part --------------
A non-text attachment was scrubbed…
Name: 20CFox.mid
Type: audio/mid
Size: 7807 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080209/e48313cc/attachment.bin

[…]

The attached file, for example, takes approximately 1300
milliseconds from the method call to when I start hearing music.
[…]

Well… That particular file simply doesn’t have any note events until
right before the end of the first bar. :slight_smile:

One often does that for various reasons. Some synths do stupid things
for a moment after a program change (Roland JV-1080 springs to mind),
and it’s rather awkward to set up a “count in” shorter than one bar
in some sequencers.

Simple fix: Adjust the MIDI files.

You should probably not attempt to “time shift” the whole song,
unless you know your sequencer well, as you need to include any tempo
changes and other “special” events in the shift. Safest way is to
change the first bar to 1/4, 1/8 or something. Some sequencers are
too stupid to move the events following the shortened bar, but it’s
usually doable one way or another. Another trick is to switch to
maximum tempo for the part you want to “skip”, but this is usually
severely limited by the maximum tempo allowed by the sequencer.

Sophisticated fix: Hack the player to “fast forward” to the first
audible event when started.

Note that this isn’t totally safe when dealing with hardware synths.
You may well find that any notes in the first few tens or hundreds of
ms will be delayed or even dropped entirely.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 10 February 2008, Mason Wheeler wrote:

Well…
That
particular
file
simply
doesn’t
have
any
note
events
until
right
before
the
end
of
the
first
bar.
:slight_smile:

One
often
does
that
for
various
reasons.
Some
synths
do
stupid
things
for
a
moment
after
a
program
change
(Roland
JV-1080
springs
to
mind),
and
it’s
rather
awkward
to
set
up
a
"count
in"
shorter
than
one
bar
in
some
sequencers.
…oh wow! I never noticed that until you said it and I checked it out in a different player!

Sophisticated
fix:
Hack
the
player
to
"fast
forward"
to
the
first
audible
event
when
started.

Note
that
this
isn’t
totally
safe
when
dealing
with
hardware
synths.
You
may
well
find
that
any
notes
in
the
first
few
tens
or
hundreds
of
ms
will
be
delayed
or
even
dropped
entirely.
I think this is what the player I’m using is doing. Is there any way to make SDL_Mixer do the same? Perhaps make it a setting that can be toggled, in case having it on would break other stuff? I don’t know the first thing about how MIDIs work under the hood; I just want them to “just work” in my program the same way the rest of SDL does.

Messing around with the MIDI files themselves isn’t an option, because I’m not writing my own game. I’m building a game-designing tool and a general-purpose engine, and it has to be able to play anything that the designers throw at it.>----- Original Message ----

From: David Olofson

[…]

Sophisticated
fix:
Hack
the
player
to
"fast
forward"
to
the
first
audible
event
when
started.

Note
that
this
isn’t
totally
safe
when
dealing
with
hardware
synths.
You
may
well
find
that
any
notes
in
the
first
few
tens
or
hundreds
of
ms
will
be
delayed
or
even
dropped
entirely.

Uhm… Well, that’s one way of quoting, I guess. :smiley:

Your mail client is adding bogus newlines in all quoted text. This
doesn’t matter to HTML, but it obviously breaks the plain text part,
which receives the same treatment.

I think this is what the player I’m using is doing. Is there any
way to make SDL_Mixer do the same?

Well, there’s always The Source. :wink:

The hack should be pretty trivial, theoretically. You should probably
have some “first play” flag to avoid issues with looping tracks, and
then you just drop the delta times until you see the first NoteOn
event.

I wouldn’t think SDL_mixer does that out of the box, but I could be
wrong…

Perhaps make it a setting that can be toggled, in case having it on
would break other stuff?

Yeah, that might work. I’m not a SDL_mixer developer or even a user,
so I have no say in the matter, though. :slight_smile:

Messing around with the MIDI files themselves isn’t an option,
because I’m not writing my own game. I’m building a game-designing
tool and a general-purpose engine, and it has to be able to play
anything that the designers throw at it.

Well, what you’re seeing now isn’t really a bug. It’s not really any
different from .WAV files that start with a moment of silence - that
is, it’s a bug in the media. Or, it’s actually intended, in which
case skipping initial silence would be a bug in the code. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 10 February 2008, Mason Wheeler wrote:

Your
mail
client
is
adding
bogus
newlines
in
all
quoted
text.
This
doesn’t
matter
to
HTML,
but
it
obviously
breaks
the
plain
text
part,
which
receives
the
same
treatment.
Very strange. When [SDL] forwarded my own message back to me, it didn’t look like that. Anyone else get it all munged like that?

I
think
this
is
what
the
player
I’m
using
is
doing.
Is
there
any

way
to
make
SDL_Mixer
do
the
same?

Well,
there’s
always
The
Source.
:wink:
Lo siento, se?or. No hablo C muy bien. :stuck_out_tongue: (I’m a Delphi programmer who’s incredibly grateful to the SDL and JEDI-SDL people for doing what I couldn’t have done.)

Well,
what
you’re
seeing
now
isn’t
really
a
bug.
It’s
not
really
any
different
from
.WAV
files
that
start
with
a
moment
of
silence-
that
is,
it’s
a
bug
in
the
media.
Or,
it’s
actually
intended,
in
which
case
skipping
initial
silence
would
be
a
bug
in
the
code.
:slight_smile:

Perhaps. But I’m writing my program to be compatible with another program of a similar nature, and it has games written with it that use the timing issue as it is, in scenes where events are synchronized with the music. Maintaining compatibility is a higher priority than dealing with issues that may or may not technically be bugs. (Besides, lead-in silence makes looping music rather awkward.) I’d rather see an option to skip it.

Thanks for your help!

Your
mail
client
is
adding
bogus
newlines
[…]
Very strange. When [SDL] forwarded my own message back to me, it
didn’t look like that. Anyone else get it all munged like that?

It looks ok when I view the HTML part in HTML mode. Looking at the
source, it turns out that both text and HTML parts are formatted like
this - it’s just that HTML normally translates any amount and kind of
whitespace into a single space.

[…]

The
Source.
:wink:
Lo siento, se?or. No hablo C muy bien. :stuck_out_tongue: (I’m a Delphi programmer
who’s incredibly grateful to the SDL and JEDI-SDL people for doing
what I couldn’t have done.)

Oh, well. At least it’s theoretically possible. :wink:

[…]

Perhaps. But I’m writing my program to be compatible with another
program of a similar nature, and it has games written with it that
use the timing issue as it is, in scenes where events are
synchronized with the music. Maintaining compatibility is a higher
priority than dealing with issues that may or may not technically be
bugs.

Well, yeah; if that’s the “specification”, one would assume the
content authors are aware of it and expect that behavior.

(Besides, lead-in silence makes looping music rather
awkward.)

Actually, it’s pretty much futile to try to implement looping outside
the player anyway. It just can’t work reliably, unless you can do it
from within a callback that runs in the context of the MIDI player.
(That is, real time for h/w MIDI, or in between the "MIDI tick"
fragments for custom software synthesis such as Timidity.)

Just so you don’t lose too much hair trying. :slight_smile:

I’d rather see an option to skip it.

Is this Timidity (software integrated in SDL_mixer) or one of the
native MIDI drivers you’re using? (Didn’t find any “skip initial
silence” logic in either version, but anyway…)

Thanks for your help!

No problem. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 10 February 2008, Mason Wheeler wrote:

It
looks
ok
when
I
view
the
HTML
part
in
HTML
mode.
Looking
at
the source,
it
turns
out
that
both
text
and
HTML
parts
are
formatted
like this-
it’s
just
that
HTML
normally
translates
any
amount
and

kind
of whitespace
into
a
single
space.
I’m using Yahoo!Mail. Trying something new here. Let’s see if this fixes it…

Actually,
it’s
pretty
much
futile
to
try
to
implement
looping
outside the
player
anyway.
It
just
can’t
work
reliably,
unless
you
can
do
it from
within
a
callback
that
runs
in
the
context
of
the
MIDI
player.
That’s precisely how I’m doing it, and it works fine. Thankfully, SDL_Mixer has a hook that makes this easy.

Is
this
Timidity
(software
integrated
in
SDL_mixer)
or
one
of
the native
MIDI
drivers
you’re
using?
(Didn’t
find
any
"skip
initial silence"
logic
in
either
version,
but
anyway…)
I don’t have Timidity installed, so I assume it’s talking directly to the Windows driver.