annotate decoders/smpeg.c @ 274:9e7f9e09ea0e

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