annotate decoders/smpeg.c @ 517:0f5888f9aef7 stable-1.0

Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 29 Oct 2006 07:14:48 +0000
parents 45614e2c1c81
children 50bb9a6cebfe
rev   line source
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * MPEG-1 Layer 3, or simply, "MP3", decoder for SDL_sound.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles all those highly compressed songs you stole through
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * Napster. :) It depends on the SMPEG library for decoding, which can
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * be grabbed from: http://www.lokigames.com/development/smpeg.php3
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * This should also be able to extract the audio stream from an MPEG movie.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * There is an alternative MP3 decoder available, called "mpglib", which
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 * doesn't depend on external libraries (the decoder itself is part of
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 * SDL_sound), and may be more efficient, but less flexible than SMPEG. YMMV.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 * Please see the file COPYING in the source's root directory.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #if HAVE_CONFIG_H
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 # include <config.h>
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #endif
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #ifdef SOUND_SUPPORTS_SMPEG
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include <stdio.h>
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #include <stdlib.h>
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #include <string.h>
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 #include "SDL_sound.h"
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #define __SDL_SOUND_INTERNAL__
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 #include "SDL_sound_internal.h"
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include "smpeg.h"
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #include "extra_rwops.h"
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static int _SMPEG_init(void);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static void _SMPEG_quit(void);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static int _SMPEG_open(Sound_Sample *sample, const char *ext);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 static void _SMPEG_close(Sound_Sample *sample);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 static Uint32 _SMPEG_read(Sound_Sample *sample);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 static int _SMPEG_rewind(Sound_Sample *sample);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
63 static int _SMPEG_seek(Sound_Sample *sample, Uint32 ms);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 static const char *extensions_smpeg[] = { "MP3", "MPEG", "MPG", NULL };
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 const Sound_DecoderFunctions __Sound_DecoderFunctions_SMPEG =
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 extensions_smpeg,
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 "MPEG-1 Layer 3 audio through SMPEG",
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 "Ryan C. Gordon <icculus@clutteredmind.org>",
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 "http://icculus.org/smpeg/"
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 },
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 _SMPEG_init, /* init() method */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 _SMPEG_quit, /* quit() method */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 _SMPEG_open, /* open() method */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 _SMPEG_close, /* close() method */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 _SMPEG_read, /* read() method */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
80 _SMPEG_rewind, /* rewind() method */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
81 _SMPEG_seek /* seek() method */
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 };
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 static int _SMPEG_init(void)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 return(1); /* always succeeds. */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 } /* _SMPEG_init */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 static void _SMPEG_quit(void)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 /* it's a no-op. */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 } /* _SMPEG_quit */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96
401
c42ac9ee2ce4 Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
97 static __inline__ void output_version(void)
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 static int first_time = 1;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 if (first_time)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 SMPEG_version v;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 SMPEG_VERSION(&v);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 SNDDBG(("SMPEG: Compiled against SMPEG v%d.%d.%d.\n",
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 v.major, v.minor, v.patch));
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 first_time = 0;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 } /* if */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 } /* output_version */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 static int _SMPEG_open(Sound_Sample *sample, const char *ext)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 SMPEG *smpeg;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 SMPEG_Info smpeg_info;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 SDL_AudioSpec spec;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 SDL_RWops *refCounter;
517
0f5888f9aef7 Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
119 const char *err = NULL;
260
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 output_version();
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 * 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
125 * 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
126 * 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
127 * playing from there.
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 * 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
130 * 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
131 * 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
132 * 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
133 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 * 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
135 * 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
136 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 * 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
138 * 01 - reserved
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 * 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
140 * 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
141 *
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 * 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
143 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 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
145 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 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
147
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 if (SDL_RWread(internal->rw, mp3_magic, sizeof (mp3_magic), 1) != 1)
358
f11c10ffa31a Fixed some debug messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 351
diff changeset
149 BAIL_MACRO("SMPEG: Could not read MP3 magic.", 0);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 if (mp3_magic[0] != 0xFF || (mp3_magic[1] & 0xF0) != 0xF0)
358
f11c10ffa31a Fixed some debug messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 351
diff changeset
152 BAIL_MACRO("SMPEG: Not an MP3 stream.", 0);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153
351
069ce624d6cf FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 326
diff changeset
154 /* If the seek fails, we'll probably miss a frame, but oh well */
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 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
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 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
159 if (refCounter == NULL)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 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
162 return(0);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 } /* if */
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 /* 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
166 internal->rw = refCounter;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 * 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
170 * 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
171 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 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
173 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
174
517
0f5888f9aef7 Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
175 err = SMPEG_error(smpeg);
0f5888f9aef7 Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
176 if (err != NULL)
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 {
517
0f5888f9aef7 Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
178 __Sound_SetError(err); /* make a copy before SMPEG_delete()... */
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 SMPEG_delete(smpeg);
517
0f5888f9aef7 Fixed bogus memory deference when SMPEG fails init (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
180 return(0);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 } /* if */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 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
184 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 SMPEG_delete(smpeg);
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
186 BAIL_MACRO("SMPEG: No audio stream found in data.", 0);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 } /* if */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 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
204 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
205 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
206
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 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
208
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 * 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
211 * 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
212 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 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
214 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
215 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
216 sample->actual.channels = spec.channels;
326
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
217 sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 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
219
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 SMPEG_play(smpeg);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 return(1);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 } /* _SMPEG_open */
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
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 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
226 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 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
228 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
229 } /* _SMPEG_close */
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
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 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
233 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 Uint32 retval;
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 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
236 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
237
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 * 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
240 * 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
241 */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 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
243 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
244 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
245 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 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
247 if (errMsg == NULL)
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 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
249 else
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
251 __Sound_SetError(errMsg);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 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
253 } /* else */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 } /* if */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 return(retval);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 } /* _SMPEG_read */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258
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 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
261 {
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 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
263 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
264 SMPEGstatus status;
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 /*
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 * 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
268 * restart it afterwards.
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 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
271 SMPEG_rewind(smpeg);
436
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
272 /* EW: I think SMPEG_play() has an independent and unrelated meaning
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
273 * to the flag, "SMPEG_PLAYING". This is why the SMPEG_play() call
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
274 * is done in the open() function even though the file is not yet
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
275 * technically playing. I believe SMPEG_play() must always be active
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
276 * because this seems to be what's causing the:
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
277 * "Can't rewind after the file has finished playing once" problem,
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
278 * because always recalling it here seems to make the problem go away.
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
279 */
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
280 /*
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 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
282 SMPEG_play(smpeg);
436
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
283 */
45614e2c1c81 Patch to fix rewinding code by Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
284 SMPEG_play(smpeg);
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 return(1);
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 } /* _SMPEG_rewind */
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
288
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
289 static int _SMPEG_seek(Sound_Sample *sample, Uint32 ms)
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
290 {
326
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
291 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
292 SMPEG *smpeg = (SMPEG *) internal->decoder_private;
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
293 SMPEGstatus status;
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
294
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
295 /*
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
296 * SMPEG_rewind() really means "stop and rewind", so we may have to
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
297 * restart it afterwards.
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
298 */
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
299 status = SMPEG_status(smpeg);
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
300 SMPEG_rewind(smpeg);
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
301 SMPEG_skip(smpeg, ((float) ms) / 1000.0);
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
302 if (status == SMPEG_PLAYING)
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
303 SMPEG_play(smpeg);
1b33baef9bf9 Added seek method.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
304 return(1);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
305 } /* _SMPEG_seek */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 301
diff changeset
306
260
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 #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
308
44a4730a1e6f Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 /* 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
310