annotate decoders/mp3.c @ 61:7d3a6ea7f1f0

Updated.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 24 Sep 2001 15:31:03 +0000
parents 6df2f69e037e
children b13fafb976be
rev   line source
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
41e5e07c5fed 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.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * MPEG-1 Layer 3, or simply, "MP3", decoder for SDL_sound.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles all those highly compressed songs you stole through
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * Napster. :) It depends on the SMPEG library for decoding, which can
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * be grabbed from: http://www.lokigames.com/development/smpeg.php3
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * Please see the file LICENSE in the source's root directory.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 *
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #include <stdio.h>
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <stdlib.h>
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <string.h>
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <assert.h>
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include "smpeg.h"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include "SDL_sound.h"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "extra_rwops.h"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #define __SDL_SOUND_INTERNAL__
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound_internal.h"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #if (!defined SOUND_SUPPORTS_MP3)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #error SOUND_SUPPORTS_MP3 must be defined.
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #endif
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
46
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
49 static int MP3_init(void);
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
50 static void MP3_quit(void);
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 static int MP3_open(Sound_Sample *sample, const char *ext);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 static void MP3_close(Sound_Sample *sample);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 static Uint32 MP3_read(Sound_Sample *sample);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 "MP3",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 "MPEG-1 Layer 3 audio through SMPEG",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 "Ryan C. Gordon <icculus@clutteredmind.org>",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 "http://www.icculus.org/SDL_sound/"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 },
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63
46
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
64 MP3_init, /* init() method */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
65 MP3_quit, /* quit() method */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
66 MP3_open, /* open() method */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
67 MP3_close, /* close() method */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
68 MP3_read /* read() method */
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 };
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
46
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
71
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
72 static int MP3_init(void)
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
73 {
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
74 return(1); /* always succeeds. */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
75 } /* MP3_init */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
76
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
77
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
78 static void MP3_quit(void)
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
79 {
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
80 /* it's a no-op. */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
81 } /* MP3_quit */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
82
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
83
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 static __inline__ void output_version(void)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 static int first_time = 1;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 if (first_time)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 SMPEG_version v;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 SMPEG_VERSION(&v);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 _D(("MP3: Compiled against SMPEG v%d.%d.%d.\n",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 v.major, v.minor, v.patch));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 first_time = 0;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 } /* output_version */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 static int MP3_open(Sound_Sample *sample, const char *ext)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 SMPEG *smpeg;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 SMPEG_Info smpeg_info;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 SDL_AudioSpec spec;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 SDL_RWops *refCounter;
46
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
106 Uint8 mp3_magic[2];
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 output_version();
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109
46
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
110 /*
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
111 * SMPEG appears to be far too greedy about what it accepts as input.
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
112 * This test was adapted from SDL_mixer.
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
113 */
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
114 if (SDL_RWread(internal->rw, mp3_magic, sizeof (mp3_magic), 1) != 1)
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
115 {
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
116 Sound_SetError("MP3: Could not read MP3 magic.");
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
117 return(0);
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
118 }
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
119 if (mp3_magic[0] != 0xFF || (mp3_magic[1] & 0xF0) != 0xF0)
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
120 {
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
121 Sound_SetError("MP3: Not an MP3 stream.");
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
122 return(0);
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
123 }
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
124 SDL_RWseek(internal->rw, -sizeof (mp3_magic), SEEK_CUR);
6e13fcc178da No longer grabs non-MP3 streams. Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
125
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 refCounter = RWops_RWRefCounter_new(internal->rw);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 if (refCounter == NULL)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 _D(("MP3: Failed to create reference counting RWops.\n"));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 /* replace original RWops. This is safe. Honest. :) */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 internal->rw = refCounter;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 /*
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 * increment the refcount, since SMPEG will nuke the RWops if it can't
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 * accept the contained data...
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 RWops_RWRefCounter_addRef(refCounter);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 smpeg = SMPEG_new_rwops(refCounter, &smpeg_info, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 if (SMPEG_error(smpeg))
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 Sound_SetError(SMPEG_error(smpeg));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 SMPEG_delete(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 if (!smpeg_info.has_audio)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 Sound_SetError("MP3: No audio stream found in data.");
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 SMPEG_delete(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 _D(("MP3: Accepting data stream.\n"));
28
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
158 _D(("MP3: has_audio == {%s}.\n", smpeg_info.has_audio ? "TRUE" : "FALSE"));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
159 _D(("MP3: has_video == {%s}.\n", smpeg_info.has_video ? "TRUE" : "FALSE"));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
160 _D(("MP3: width == (%d).\n", smpeg_info.width));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
161 _D(("MP3: height == (%d).\n", smpeg_info.height));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
162 _D(("MP3: current_frame == (%d).\n", smpeg_info.current_frame));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
163 _D(("MP3: current_fps == (%f).\n", smpeg_info.current_fps));
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 _D(("MP3: audio_string == [%s].\n", smpeg_info.audio_string));
28
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
165 _D(("MP3: audio_current_frame == (%d).\n", smpeg_info.audio_current_frame));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
166 _D(("MP3: current_offset == (%d).\n", smpeg_info.current_offset));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
167 _D(("MP3: total_size == (%d).\n", smpeg_info.total_size));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
168 _D(("MP3: current_time == (%f).\n", smpeg_info.current_time));
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
169 _D(("MP3: total_time == (%f).\n", smpeg_info.total_time));
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 SMPEG_enablevideo(smpeg, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 SMPEG_enableaudio(smpeg, 1);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 SMPEG_loop(smpeg, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 SMPEG_wantedSpec(smpeg, &spec);
54
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
176 /*
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
177 * One of the MP3:s I tried wouldn't work unless I added this line
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
178 * to tell SMPEG that yes, it may have the spec it wants.
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
179 */
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
180 SMPEG_actualSpec(smpeg, &spec);
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 sample->actual.format = spec.format;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 sample->actual.rate = spec.freq;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 sample->actual.channels = spec.channels;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 sample->flags = SOUND_SAMPLEFLAG_NONE;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 internal->decoder_private = smpeg;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 SMPEG_play(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 return(1);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 } /* MP3_open */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 static void MP3_close(Sound_Sample *sample)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 SMPEG_delete((SMPEG *) internal->decoder_private);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 } /* MP3_close */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 static Uint32 MP3_read(Sound_Sample *sample)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 Uint32 retval;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 SMPEG *smpeg = (SMPEG *) internal->decoder_private;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204
54
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
205 /*
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
206 * We have to clear the buffer because apparently SMPEG_playAudio()
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
207 * will mix the decoded audio with whatever's already in it. Nasty.
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
208 */
6df2f69e037e Fixes by Torbj�rn...now the thing actually works! :) See the CHANGELOG
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
209 memset(internal->buffer, 0, internal->buffer_size);
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 retval = SMPEG_playAudio(smpeg, internal->buffer, internal->buffer_size);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 if (retval < internal->buffer_size)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 char *errMsg = SMPEG_error(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 if (errMsg == NULL)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 sample->flags |= SOUND_SAMPLEFLAG_EOF;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 else
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 Sound_SetError(errMsg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 } /* else */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 return(retval);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 } /* MP3_read */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 /* end of mp3.c ... */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227