annotate decoders/mpglib.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
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * MPGLIB decoder for SDL_sound. This is a very lightweight MP3 decoder,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 * which is included with the SDL_sound source, so that it doesn't rely on
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * unnecessary external libraries.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * The SMPEG decoder plays back more forms of MPEGs, and may behave better or
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * worse under various conditions. mpglib is (apparently) more efficient than
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * SMPEG, and, again, doesn't need an external library. You should test both
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * decoders and use what you find works best for you.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 *
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
30 * mpglib is an LGPL'd portion of mpg123, which can be found in its original
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
31 * form at: http://www.mpg123.de/
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 * Please see the file COPYING in the source's root directory. The included
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 * source code for mpglib falls under the LGPL, which is the same license as
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 * SDL_sound (so you can consider it a single work).
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #if HAVE_CONFIG_H
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 # include <config.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #endif
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #ifdef SOUND_SUPPORTS_MPGLIB
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #include <stdio.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #include <stdlib.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 #include <string.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #include "mpglib/mpg123_sdlsound.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #include "mpglib/mpglib_sdlsound.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #include "SDL_sound.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #define __SDL_SOUND_INTERNAL__
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 #include "SDL_sound_internal.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static int MPGLIB_init(void);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static void MPGLIB_quit(void);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static int MPGLIB_open(Sound_Sample *sample, const char *ext);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 static void MPGLIB_close(Sound_Sample *sample);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 static Uint32 MPGLIB_read(Sound_Sample *sample);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 static int MPGLIB_rewind(Sound_Sample *sample);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
63 static int MPGLIB_seek(Sound_Sample *sample, Uint32 ms);
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 static const char *extensions_mpglib[] = { "MP3", NULL };
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 const Sound_DecoderFunctions __Sound_DecoderFunctions_MPGLIB =
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 extensions_mpglib,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 "MP3 decoding via internal mpglib",
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 "Ryan C. Gordon <icculus@clutteredmind.org>",
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 "http://www.icculus.org/SDL_sound/"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 },
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 MPGLIB_init, /* init() method */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 MPGLIB_quit, /* quit() method */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 MPGLIB_open, /* open() method */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 MPGLIB_close, /* close() method */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 MPGLIB_read, /* read() method */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
80 MPGLIB_rewind, /* rewind() method */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
81 MPGLIB_seek /* seek() method */
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 };
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 /* this is what we store in our internal->decoder_private field... */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 typedef struct
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 struct mpstr mp;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 Uint8 inbuf[16384];
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 Uint8 outbuf[8192];
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 int outleft;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 int outpos;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 } mpglib_t;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 static int MPGLIB_init(void)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 return(1); /* always succeeds. */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 } /* MPGLIB_init */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 static void MPGLIB_quit(void)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 /* it's a no-op. */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 } /* MPGLIB_quit */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 static int MPGLIB_open(Sound_Sample *sample, const char *ext)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 mpglib_t *mpg = NULL;
293
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
113 int rc;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 /*
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 * If I understand things correctly, MP3 files don't really have any
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 * magic header we can check for. The MP3 player is expected to just
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 * pick the first thing that looks like a valid frame and start
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 * playing from there.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 * So here's what we do: If the caller insists that this is really
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 * MP3 we'll take his word for it. Otherwise, use the same test as
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 * SDL_mixer does and check if the stream starts with something that
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 * looks like a frame.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 * A frame begins with 11 bits of frame sync (all bits must be set),
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 * followed by a two-bit MPEG Audio version ID:
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 * 00 - MPEG Version 2.5 (later extension of MPEG 2)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 * 01 - reserved
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 * 10 - MPEG Version 2 (ISO/IEC 13818-3)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 * 11 - MPEG Version 1 (ISO/IEC 11172-3)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 *
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 * Apparently we don't handle MPEG Version 2.5.
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 if (__Sound_strcasecmp(ext, "MP3") != 0)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 Uint8 mp3_magic[2];
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 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
141 BAIL_MACRO("MPGLIB: Could not read MP3 magic.", 0);
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 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
144 BAIL_MACRO("MPGLIB: Not an MP3 stream.", 0);
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
351
069ce624d6cf FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
146 /* If the seek fails, we'll probably miss a frame, but oh well. */
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 SDL_RWseek(internal->rw, -sizeof (mp3_magic), SEEK_CUR);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 } /* if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 mpg = (mpglib_t *) malloc(sizeof (mpglib_t));
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 BAIL_IF_MACRO(mpg == NULL, ERR_OUT_OF_MEMORY, 0);
293
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
152 memset(mpg, '\0', sizeof (mpglib_t));
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 InitMP3(&mpg->mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154
293
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
155 rc = SDL_RWread(internal->rw, mpg->inbuf, 1, sizeof (mpg->inbuf));
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
156 if (rc <= 0)
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
157 {
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
158 free(mpg);
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
159 BAIL_MACRO("MPGLIB: Failed to read any data at all", 0);
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
160 } /* if */
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
161
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
162 if (decodeMP3(&mpg->mp, mpg->inbuf, rc,
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
163 mpg->outbuf, sizeof (mpg->outbuf),
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
164 &mpg->outleft) == MP3_ERR)
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
165 {
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
166 free(mpg);
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
167 BAIL_MACRO("MPGLIB: Not an MP3 stream?", 0);
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
168 } /* if */
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
169
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 SNDDBG(("MPGLIB: Accepting data stream.\n"));
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 internal->decoder_private = mpg;
293
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
173 sample->actual.rate = mpglib_freqs[mpg->mp.fr.sampling_frequency];
ee6e1f8bfae9 Can determine audio format correctly (mostly correctly?) now. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 271
diff changeset
174 sample->actual.channels = mpg->mp.fr.stereo;
351
069ce624d6cf FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
175 sample->actual.format = AUDIO_S16SYS;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 sample->flags = SOUND_SAMPLEFLAG_NONE;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
178 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
179 /* Finds approximate length of the song. */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
180 Uint32 pos, total_byte_size;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
181 char tag_buffer[4];
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
182 memset(tag_buffer, '\0', sizeof(tag_buffer));
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
183
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
184 /* Get size of file first */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
185 pos = SDL_RWtell(internal->rw);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
186 total_byte_size = SDL_RWseek(internal->rw, -128, SEEK_END);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
187 if( total_byte_size <= 0 ) {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
188 BAIL_MACRO("MPGLIB: Not an MP3 stream.", 0);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
189 }
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
190 if ( SDL_RWread(internal->rw, tag_buffer, 1, 3) != 3) {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
191 BAIL_MACRO("MPGLIB: Cannot identify TAG section.", 0);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
192 }
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
193 if ( strncmp(tag_buffer, "TAG", 3) != 0 ) {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
194 /* ENDING TAG NOT FOUND */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
195 total_byte_size = SDL_RWseek(internal->rw,0, SEEK_END);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
196 }
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
197 if (SDL_RWseek(internal->rw, pos, SEEK_SET) != pos) {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
198 BAIL_MACRO("MPGLIB: Cannot go back to save spot in file.", 0);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
199 }
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
200 sample->total_time = total_byte_size / mpg->mp.fr.bitrate * 8.0;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
201 sample->total_time += (total_byte_size % mpg->mp.fr.bitrate) * 8.0
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
202 / mpg->mp.fr.bitrate;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
203 }
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
204
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 return(1); /* we'll handle this data. */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 } /* MPGLIB_open */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 static void MPGLIB_close(Sound_Sample *sample)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 mpglib_t *mpg = ((mpglib_t *) internal->decoder_private);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 ExitMP3(&mpg->mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 free(mpg);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 } /* MPGLIB_close */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 static Uint32 MPGLIB_read(Sound_Sample *sample)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 mpglib_t *mpg = ((mpglib_t *) internal->decoder_private);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 Uint32 bw = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 int rc;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 while (bw < internal->buffer_size)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 if (mpg->outleft > 0)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 Uint16 cpysize = internal->buffer_size - bw;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 if (cpysize > mpg->outleft)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 cpysize = mpg->outleft;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 memcpy(((Uint8 *) internal->buffer) + bw,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 mpg->outbuf + mpg->outpos, cpysize);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 bw += cpysize;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 mpg->outpos += cpysize;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 mpg->outleft -= cpysize;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 continue;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 } /* if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 /* need to decode more from the MP3 stream... */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 mpg->outpos = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 rc = decodeMP3(&mpg->mp, NULL, 0, mpg->outbuf,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 sizeof (mpg->outbuf), &mpg->outleft);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 if (rc == MP3_ERR)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 return(bw);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 } /* if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 else if (rc == MP3_NEED_MORE)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 rc = SDL_RWread(internal->rw, mpg->inbuf, 1, sizeof (mpg->inbuf));
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 if (rc == -1)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 return(bw);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 } /* if */
268
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
258
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 else if (rc == 0)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 sample->flags |= SOUND_SAMPLEFLAG_EOF;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 return(bw);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 } /* else if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264
268
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
265 /* make sure there isn't an ID3 tag. */
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
266 /*
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
267 * !!! FIXME: This can fail under the following circumstances:
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
268 * First, if there's the sequence "TAG" 128 bytes from the end
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
269 * of a read that isn't the EOF. This is unlikely.
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
270 * Second, if the TAG sequence is split between two reads (ie,
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
271 * the last byte of a read is 'T', and the next read is the
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
272 * final 127 bytes of the stream, being the rest of the ID3 tag).
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
273 * While this is more likely, it's still not very likely at all.
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
274 * Still, something SHOULD be done about this.
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
275 * ID3v2 tags are more complex, too, not to mention LYRICS tags,
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
276 * etc, which aren't handled, either. Hey, this IS meant to be
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
277 * a lightweight decoder. Use SMPEG if you need an all-purpose
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
278 * decoder. mpglib really assumes you control all your assets.
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
279 */
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
280 if (rc >= 128)
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
281 {
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
282 Uint8 *ptr = &mpg->inbuf[rc - 128];
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
283 if ((ptr[0] == 'T') && (ptr[1] == 'A') && (ptr[2] == 'G'))
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
284 rc -= 128; /* disregard it. */
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
285 } /* if */
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
286
263
cde06af563f7 Fix for EOF.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
287 rc = decodeMP3(&mpg->mp, mpg->inbuf, rc,
268
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
288 mpg->outbuf, sizeof (mpg->outbuf),
9b89bb587f8f Detect and discard ID3 tags.
Ryan C. Gordon <icculus@icculus.org>
parents: 263
diff changeset
289 &mpg->outleft);
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 if (rc == MP3_ERR)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 return(bw);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 } /* if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 } /* else if */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 } /* while */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 return(bw);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 } /* MPGLIB_read */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 static int MPGLIB_rewind(Sound_Sample *sample)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 mpglib_t *mpg = ((mpglib_t *) internal->decoder_private);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 /* this is just resetting some fields in a structure; it's very fast. */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 ExitMP3(&mpg->mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 InitMP3(&mpg->mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 mpg->outpos = mpg->outleft = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 return(1);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 } /* MPGLIB_rewind */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
316 static int MPGLIB_seek(Sound_Sample *sample, Uint32 ms)
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
317 {
351
069ce624d6cf FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
318 BAIL_MACRO("MPGLIB: Seeking not implemented", 0);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
319 } /* MPGLIB_seek */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 293
diff changeset
320
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 #endif /* SOUND_SUPPORTS_MPGLIB */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 /* end of mpglib.c ... */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325