annotate decoders/mp3.c @ 34:938ef560c7bf

Initial add. Thanks, Torbj�rn!
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 20 Sep 2001 07:51:42 +0000
parents d9e84e857569
children 6e13fcc178da
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
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 static int MP3_open(Sound_Sample *sample, const char *ext);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 static void MP3_close(Sound_Sample *sample);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 static Uint32 MP3_read(Sound_Sample *sample);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
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 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 "MP3",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 "MPEG-1 Layer 3 audio through SMPEG",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 "Ryan C. Gordon <icculus@clutteredmind.org>",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 "http://www.icculus.org/SDL_sound/"
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 },
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 MP3_open, /* open() method */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 MP3_close, /* close() method */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 MP3_read /* read() method */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 };
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 static __inline__ void output_version(void)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 static int first_time = 1;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 if (first_time)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 SMPEG_version v;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 SMPEG_VERSION(&v);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 _D(("MP3: Compiled against SMPEG v%d.%d.%d.\n",
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 v.major, v.minor, v.patch));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 first_time = 0;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 } /* output_version */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 static int MP3_open(Sound_Sample *sample, const char *ext)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 SMPEG *smpeg;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 SMPEG_Info smpeg_info;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 SDL_AudioSpec spec;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 SDL_RWops *refCounter;
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 output_version();
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 refCounter = RWops_RWRefCounter_new(internal->rw);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 if (refCounter == NULL)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 _D(("MP3: Failed to create reference counting RWops.\n"));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 } /* if */
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 /* replace original RWops. This is safe. Honest. :) */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 internal->rw = refCounter;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 /*
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 * 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
104 * accept the contained data...
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 RWops_RWRefCounter_addRef(refCounter);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 smpeg = SMPEG_new_rwops(refCounter, &smpeg_info, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 if (SMPEG_error(smpeg))
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Sound_SetError(SMPEG_error(smpeg));
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 SMPEG_delete(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 if (!smpeg_info.has_audio)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 Sound_SetError("MP3: No audio stream found in data.");
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 SMPEG_delete(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 return(0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 _D(("MP3: Accepting data stream.\n"));
28
d9e84e857569 Changed some debug output. Still broken.
Ryan C. Gordon <icculus@icculus.org>
parents: 14
diff changeset
124 _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
125 _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
126 _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
127 _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
128 _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
129 _D(("MP3: current_fps == (%f).\n", smpeg_info.current_fps));
14
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 _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
131 _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
132 _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
133 _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
134 _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
135 _D(("MP3: total_time == (%f).\n", smpeg_info.total_time));
14
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 SMPEG_enablevideo(smpeg, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 SMPEG_enableaudio(smpeg, 1);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 SMPEG_loop(smpeg, 0);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 SMPEG_wantedSpec(smpeg, &spec);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 sample->actual.format = spec.format;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 sample->actual.rate = spec.freq;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 sample->actual.channels = spec.channels;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 sample->flags = SOUND_SAMPLEFLAG_NONE;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 internal->decoder_private = smpeg;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 SMPEG_play(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 return(1);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 } /* MP3_open */
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
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 static void MP3_close(Sound_Sample *sample)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 SMPEG_delete((SMPEG *) internal->decoder_private);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 } /* MP3_close */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 static Uint32 MP3_read(Sound_Sample *sample)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 Uint32 retval;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 SMPEG *smpeg = (SMPEG *) internal->decoder_private;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 retval = SMPEG_playAudio(smpeg, internal->buffer, internal->buffer_size);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 if (retval < internal->buffer_size)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 char *errMsg = SMPEG_error(smpeg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 if (errMsg == NULL)
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 sample->flags |= SOUND_SAMPLEFLAG_EOF;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 else
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 {
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 Sound_SetError(errMsg);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 } /* else */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 } /* if */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 return(retval);
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 } /* MP3_read */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 /* end of mp3.c ... */
41e5e07c5fed Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183