Mercurial > SDL_sound_CoreAudio
annotate decoders/midi.c @ 474:c66080364dff
Most decoders now report total sample play time, now. Technically, this
breaks binary compatibility with the 1.0 branch, since it extends the
Sound_Sample struct, but most (all?) programs are just passing pointers
allocated by SDL_sound around, and might be okay.
Source-level compatibility is not broken...yet! :)
--ryan.
-------- Original Message --------
Subject: SDL_sound patch: Finding total length of time of sound file.
Date: Sun, 26 Jan 2003 09:31:17 -0800 (PST)
Hi Ryan,
I am working with Eric Wing and helping him modify
SDL_sound. AS part of our efforts in improving and
enhancing SDL_sound, we like to submit this patch. We
modified the codecs to find the total time of a sound
file. Below is the explanation of the patch. The
patch is appended as an attachment to this email.
* MOTIVATION:
We needed the ability to get the total play time of a
sample (And we noticed that we're not the only ones).
Since SDL_sound blocks direct access to the specific
decoders, there is no way for a user to know this
information short of decoding the whole thing.
Because of this, we believe this will be a useful
addition, even though the accuracy may not be perfect
(subject to each decoder) or the information may not
always be available.
* CONTRIBUTORS:
Wesley Leong (modified the majority of the codecs and
verified the results)
Eric Wing (showed everyone how to do modify codec,
modified mikmod)
Wang Lam (modified a handful of codecs, researched
into specs and int overflow)
Ahilan Anantha (modified a few codecs and helped with
integer math)
* GENERAL ISSUES:
We chose the value to be milliseconds as an Sint32.
Milliseconds because that's what Sound_Seek takes as a
parameter and -1 to allow for instances/codecs where
the value could not be determined. We are
not sure if this is the final convention you want, so
we are willing to work with you on this.
We also expect the total_time field to be set on open
and never again modified by SDL_sound. Users may
access it directly much like the sample buffer and
buffer_size. We thought about recomputing the time
on DecodeAll, but since users may seek or decode small
chunks first, not all the data may be there. So this
is better done by the user. This may be good
information to document.
Currently, all the main codecs are implemented except
for QuickTime.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 08 May 2004 08:19:50 +0000 |
parents | cbb15ecf423a |
children | 3e705c9180e5 |
rev | line source |
---|---|
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 * SDL_sound -- An abstract sound format decoding API. |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 * Copyright (C) 2001 Ryan C. Gordon. |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 * |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 * |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 * |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 /* |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
21 * MIDI decoder for SDL_sound. |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 * |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
23 * This driver handles MIDI data through a stripped-down version of TiMidity. |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
24 * See the documentation in the timidity subdirectory. |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 * |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
26 * Please see the file COPYING in the source's root directory. |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 * |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 * This file written by Torbjörn Andersson. (d91tan@Update.UU.SE) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 #if HAVE_CONFIG_H |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 # include <config.h> |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 #endif |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 #ifdef SOUND_SUPPORTS_MIDI |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 #include <stdio.h> |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 #include <stdlib.h> |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 #include <string.h> |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
40 |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 #include "SDL_sound.h" |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 #define __SDL_SOUND_INTERNAL__ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 #include "SDL_sound_internal.h" |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
46 #include "timidity.h" |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
47 |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 static int MIDI_init(void); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 static void MIDI_quit(void); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 static int MIDI_open(Sound_Sample *sample, const char *ext); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 static void MIDI_close(Sound_Sample *sample); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 static Uint32 MIDI_read(Sound_Sample *sample); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
54 static int MIDI_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
55 static int MIDI_seek(Sound_Sample *sample, Uint32 ms); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
57 static const char *extensions_midi[] = { "MIDI", "MID", NULL }; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI = |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 { |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
138
diff
changeset
|
61 extensions_midi, |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
62 "MIDI decoder, using a subset of TiMidity", |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 "Torbjörn Andersson <d91tan@Update.UU.SE>", |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
64 "http://www.icculus.org/SDL_sound/" |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 }, |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
67 MIDI_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
68 MIDI_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
69 MIDI_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
70 MIDI_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
71 MIDI_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
72 MIDI_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
73 MIDI_seek /* seek() method */ |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 }; |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 static int MIDI_init(void) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 { |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
79 BAIL_IF_MACRO(Timidity_Init() < 0, "MIDI: Could not initialise", 0); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 return(1); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 } /* MIDI_init */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 static void MIDI_quit(void) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 { |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
86 Timidity_Exit(); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 } /* MIDI_quit */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 static int MIDI_open(Sound_Sample *sample, const char *ext) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 { |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 SDL_RWops *rw = internal->rw; |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
94 SDL_AudioSpec spec; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
95 MidiSong *song; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
97 spec.channels = 2; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
98 spec.format = AUDIO_S16SYS; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
99 spec.freq = 44100; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
100 spec.samples = 4096; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
101 |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
102 song = Timidity_LoadSong(rw, &spec); |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
103 BAIL_IF_MACRO(song == NULL, "MIDI: Not a MIDI file.", 0); |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
104 Timidity_SetVolume(song, 100); |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
105 Timidity_Start(song); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 SNDDBG(("MIDI: Accepting data stream.\n")); |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
108 |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
109 internal->decoder_private = (void *) song; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
110 |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
111 sample->actual.channels = 2; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
112 sample->actual.rate = 44100; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
113 sample->actual.format = AUDIO_S16SYS; |
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
114 |
474
c66080364dff
Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
115 sample->total_time = Timidity_GetSongLength(song); |
312 | 116 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 return(1); /* we'll handle this data. */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 } /* MIDI_open */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 static void MIDI_close(Sound_Sample *sample) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 { |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
124 MidiSong *song = (MidiSong *) internal->decoder_private; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
126 Timidity_FreeSong(song); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 } /* MIDI_close */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 static Uint32 MIDI_read(Sound_Sample *sample) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 { |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
132 Uint32 retval; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
134 MidiSong *song = (MidiSong *) internal->decoder_private; |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
136 retval = Timidity_PlaySome(song, internal->buffer, internal->buffer_size); |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 /* Make sure the read went smoothly... */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 if (retval == 0) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 else if (retval == -1) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 /* (next call this EAGAIN may turn into an EOF or error.) */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 else if (retval < internal->buffer_size) |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 return(retval); |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 } /* MIDI_read */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
152 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
153 static int MIDI_rewind(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
154 { |
231
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
155 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
156 MidiSong *song = (MidiSong *) internal->decoder_private; |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
157 |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
158 Timidity_Start(song); |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
159 return(1); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
160 } /* MIDI_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
200
diff
changeset
|
161 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
162 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
163 static int MIDI_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
164 { |
312 | 165 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
166 MidiSong *song = (MidiSong *) internal->decoder_private; | |
167 | |
168 Timidity_Seek(song, ms); | |
169 return(1); | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
170 } /* MIDI_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
171 |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 #endif /* SOUND_SUPPORTS_MIDI */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
200
f75ed2d72238
Rewrite to call an included, patched version of Timidity routines directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
174 |
108
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 /* end of midi.c ... */ |
803ba4dabbce
Initial add, from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |