Mercurial > SDL_sound_CoreAudio
annotate decoders/smpeg.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 | 45614e2c1c81 |
children | 3e705c9180e5 |
rev | line source |
---|---|
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 * SDL_sound -- An abstract sound format decoding API. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 * Copyright (C) 2001 Ryan C. Gordon. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 * MPEG-1 Layer 3, or simply, "MP3", decoder for SDL_sound. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 * This driver handles all those highly compressed songs you stole through |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 * Napster. :) It depends on the SMPEG library for decoding, which can |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 * be grabbed from: http://www.lokigames.com/development/smpeg.php3 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 * This should also be able to extract the audio stream from an MPEG movie. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 * There is an alternative MP3 decoder available, called "mpglib", which |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 * doesn't depend on external libraries (the decoder itself is part of |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 * SDL_sound), and may be more efficient, but less flexible than SMPEG. YMMV. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 * Please see the file COPYING in the source's root directory. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 #if HAVE_CONFIG_H |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 # include <config.h> |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 #endif |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 #ifdef SOUND_SUPPORTS_SMPEG |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 #include <stdio.h> |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 #include <stdlib.h> |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 #include <string.h> |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 #include "SDL_sound.h" |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 #define __SDL_SOUND_INTERNAL__ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 #include "SDL_sound_internal.h" |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 #include "smpeg.h" |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 #include "extra_rwops.h" |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 static int _SMPEG_init(void); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 static void _SMPEG_quit(void); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 static int _SMPEG_open(Sound_Sample *sample, const char *ext); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 static void _SMPEG_close(Sound_Sample *sample); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 static Uint32 _SMPEG_read(Sound_Sample *sample); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 static int _SMPEG_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
63 static int _SMPEG_seek(Sound_Sample *sample, Uint32 ms); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 static const char *extensions_smpeg[] = { "MP3", "MPEG", "MPG", NULL }; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 const Sound_DecoderFunctions __Sound_DecoderFunctions_SMPEG = |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 extensions_smpeg, |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 "MPEG-1 Layer 3 audio through SMPEG", |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 "Ryan C. Gordon <icculus@clutteredmind.org>", |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 "http://icculus.org/smpeg/" |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 }, |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 _SMPEG_init, /* init() method */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 _SMPEG_quit, /* quit() method */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 _SMPEG_open, /* open() method */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 _SMPEG_close, /* close() method */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 _SMPEG_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
80 _SMPEG_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
81 _SMPEG_seek /* seek() method */ |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 }; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 static int _SMPEG_init(void) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 return(1); /* always succeeds. */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 } /* _SMPEG_init */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 static void _SMPEG_quit(void) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 /* it's a no-op. */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 } /* _SMPEG_quit */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
401
c42ac9ee2ce4
Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
387
diff
changeset
|
97 static __inline__ void output_version(void) |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 static int first_time = 1; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 if (first_time) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 SMPEG_version v; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 SMPEG_VERSION(&v); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 SNDDBG(("SMPEG: Compiled against SMPEG v%d.%d.%d.\n", |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 v.major, v.minor, v.patch)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 first_time = 0; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 } /* output_version */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 static int _SMPEG_open(Sound_Sample *sample, const char *ext) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 SMPEG *smpeg; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 SMPEG_Info smpeg_info; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 SDL_AudioSpec spec; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 SDL_RWops *refCounter; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 output_version(); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 * If I understand things correctly, MP3 files don't really have any |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 * magic header we can check for. The MP3 player is expected to just |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 * pick the first thing that looks like a valid frame and start |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 * playing from there. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 * So here's what we do: If the caller insists that this is really |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 * MP3 we'll take his word for it. Otherwise, use the same test as |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 * SDL_mixer does and check if the stream starts with something that |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 * looks like a frame. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 * A frame begins with 11 bits of frame sync (all bits must be set), |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 * followed by a two-bit MPEG Audio version ID: |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 * 00 - MPEG Version 2.5 (later extension of MPEG 2) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 * 01 - reserved |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 * 10 - MPEG Version 2 (ISO/IEC 13818-3) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 * 11 - MPEG Version 1 (ISO/IEC 11172-3) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 * Apparently we don't handle MPEG Version 2.5. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 if (__Sound_strcasecmp(ext, "MP3") != 0) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 Uint8 mp3_magic[2]; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 if (SDL_RWread(internal->rw, mp3_magic, sizeof (mp3_magic), 1) != 1) |
358
f11c10ffa31a
Fixed some debug messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
148 BAIL_MACRO("SMPEG: Could not read MP3 magic.", 0); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 if (mp3_magic[0] != 0xFF || (mp3_magic[1] & 0xF0) != 0xF0) |
358
f11c10ffa31a
Fixed some debug messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
151 BAIL_MACRO("SMPEG: Not an MP3 stream.", 0); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
351 | 153 /* If the seek fails, we'll probably miss a frame, but oh well */ |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 SDL_RWseek(internal->rw, -sizeof (mp3_magic), SEEK_CUR); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 refCounter = RWops_RWRefCounter_new(internal->rw); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 if (refCounter == NULL) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 SNDDBG(("SMPEG: Failed to create reference counting RWops.\n")); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 return(0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 /* replace original RWops. This is safe. Honest. :) */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 internal->rw = refCounter; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 * increment the refcount, since SMPEG will nuke the RWops if it can't |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 * accept the contained data... |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 RWops_RWRefCounter_addRef(refCounter); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 smpeg = SMPEG_new_rwops(refCounter, &smpeg_info, 0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 if (SMPEG_error(smpeg)) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 SMPEG_delete(smpeg); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
177 BAIL_MACRO(SMPEG_error(smpeg), 0); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 if (!smpeg_info.has_audio) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 SMPEG_delete(smpeg); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
183 BAIL_MACRO("SMPEG: No audio stream found in data.", 0); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 SNDDBG(("SMPEG: Accepting data stream.\n")); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 SNDDBG(("SMPEG: has_audio == {%s}.\n", smpeg_info.has_audio ? "TRUE" : "FALSE")); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 SNDDBG(("SMPEG: has_video == {%s}.\n", smpeg_info.has_video ? "TRUE" : "FALSE")); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 SNDDBG(("SMPEG: width == (%d).\n", smpeg_info.width)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 SNDDBG(("SMPEG: height == (%d).\n", smpeg_info.height)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 SNDDBG(("SMPEG: current_frame == (%d).\n", smpeg_info.current_frame)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 SNDDBG(("SMPEG: current_fps == (%f).\n", smpeg_info.current_fps)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 SNDDBG(("SMPEG: audio_string == [%s].\n", smpeg_info.audio_string)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 SNDDBG(("SMPEG: audio_current_frame == (%d).\n", smpeg_info.audio_current_frame)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 SNDDBG(("SMPEG: current_offset == (%d).\n", smpeg_info.current_offset)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 SNDDBG(("SMPEG: total_size == (%d).\n", smpeg_info.total_size)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 SNDDBG(("SMPEG: current_time == (%f).\n", smpeg_info.current_time)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 SNDDBG(("SMPEG: total_time == (%f).\n", smpeg_info.total_time)); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 SMPEG_enablevideo(smpeg, 0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 SMPEG_enableaudio(smpeg, 1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 SMPEG_loop(smpeg, 0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 SMPEG_wantedSpec(smpeg, &spec); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 * One of the MP3s I tried wouldn't work unless I added this line |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 * to tell SMPEG that yes, it may have the spec it wants. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 SMPEG_actualSpec(smpeg, &spec); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 sample->actual.format = spec.format; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 sample->actual.rate = spec.freq; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 sample->actual.channels = spec.channels; |
326 | 214 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
474
c66080364dff
Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents:
436
diff
changeset
|
215 sample->total_time = smpeg_info.total_time * 1000; |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 internal->decoder_private = smpeg; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 SMPEG_play(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 return(1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 } /* _SMPEG_open */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 static void _SMPEG_close(Sound_Sample *sample) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 SMPEG_delete((SMPEG *) internal->decoder_private); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 } /* _SMPEG_close */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 static Uint32 _SMPEG_read(Sound_Sample *sample) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 Uint32 retval; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 SMPEG *smpeg = (SMPEG *) internal->decoder_private; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 * We have to clear the buffer because apparently SMPEG_playAudio() |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 * will mix the decoded audio with whatever's already in it. Nasty. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 memset(internal->buffer, '\0', internal->buffer_size); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 retval = SMPEG_playAudio(smpeg, internal->buffer, internal->buffer_size); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 if (retval < internal->buffer_size) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 char *errMsg = SMPEG_error(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 if (errMsg == NULL) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 else |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 { |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
249 __Sound_SetError(errMsg); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 } /* else */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 return(retval); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 } /* _SMPEG_read */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 static int _SMPEG_rewind(Sound_Sample *sample) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 SMPEG *smpeg = (SMPEG *) internal->decoder_private; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 SMPEGstatus status; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 * SMPEG_rewind() really means "stop and rewind", so we may have to |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 * restart it afterwards. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 status = SMPEG_status(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 SMPEG_rewind(smpeg); |
436
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
270 /* EW: I think SMPEG_play() has an independent and unrelated meaning |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
271 * to the flag, "SMPEG_PLAYING". This is why the SMPEG_play() call |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
272 * is done in the open() function even though the file is not yet |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
273 * technically playing. I believe SMPEG_play() must always be active |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
274 * because this seems to be what's causing the: |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
275 * "Can't rewind after the file has finished playing once" problem, |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
276 * because always recalling it here seems to make the problem go away. |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
277 */ |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
278 /* |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 if (status == SMPEG_PLAYING) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 SMPEG_play(smpeg); |
436
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
281 */ |
45614e2c1c81
Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
282 SMPEG_play(smpeg); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 return(1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 } /* _SMPEG_rewind */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
286 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
287 static int _SMPEG_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
288 { |
326 | 289 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
290 SMPEG *smpeg = (SMPEG *) internal->decoder_private; | |
291 SMPEGstatus status; | |
292 | |
293 /* | |
294 * SMPEG_rewind() really means "stop and rewind", so we may have to | |
295 * restart it afterwards. | |
296 */ | |
297 status = SMPEG_status(smpeg); | |
298 SMPEG_rewind(smpeg); | |
299 SMPEG_skip(smpeg, ((float) ms) / 1000.0); | |
300 if (status == SMPEG_PLAYING) | |
301 SMPEG_play(smpeg); | |
302 return(1); | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
303 } /* _SMPEG_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
304 |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 #endif /* SOUND_SUPPORTS_SMPEG */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 /* end of smpeg.c ... */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |