Mercurial > SDL_sound_CoreAudio
annotate decoders/smpeg.c @ 358:f11c10ffa31a
Fixed some debug messages.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 11 Jun 2002 23:33:02 +0000 |
parents | 069ce624d6cf |
children | cbb15ecf423a |
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); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
64 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
|
65 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 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
|
67 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
|
68 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 extensions_smpeg, |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 "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
|
72 "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
|
73 "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
|
74 }, |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 _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
|
77 _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
|
78 _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
|
79 _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
|
80 _SMPEG_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
81 _SMPEG_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
82 _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
|
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 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 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
|
87 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 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
|
89 } /* _SMPEG_init */ |
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 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 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
|
93 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 /* 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
|
95 } /* _SMPEG_quit */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
301 | 98 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
|
99 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 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
|
101 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 if (first_time) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 { |
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 SMPEG_VERSION(&v); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 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
|
107 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
|
108 first_time = 0; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 } /* output_version */ |
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 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 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
|
114 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 SMPEG *smpeg; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 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
|
117 SDL_AudioSpec spec; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 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
|
119 SDL_RWops *refCounter; |
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 | 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 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 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
|
176 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 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
|
178 SMPEG_delete(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 return(0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 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
|
183 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 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
|
185 SMPEG_delete(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 return(0); |
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 | 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 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 Sound_SetError(errMsg); |
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); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 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
|
273 SMPEG_play(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 return(1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 } /* _SMPEG_rewind */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
277 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
278 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
|
279 { |
326 | 280 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
281 SMPEG *smpeg = (SMPEG *) internal->decoder_private; | |
282 SMPEGstatus status; | |
283 | |
284 /* | |
285 * SMPEG_rewind() really means "stop and rewind", so we may have to | |
286 * restart it afterwards. | |
287 */ | |
288 status = SMPEG_status(smpeg); | |
289 SMPEG_rewind(smpeg); | |
290 SMPEG_skip(smpeg, ((float) ms) / 1000.0); | |
291 if (status == SMPEG_PLAYING) | |
292 SMPEG_play(smpeg); | |
293 return(1); | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
294 } /* _SMPEG_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
295 |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 #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
|
297 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 /* 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
|
299 |