Mercurial > SDL_sound_CoreAudio
annotate decoders/smpeg.c @ 403:b1e511c879d1
More altcvt updates and fixes from Frank.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 13 Jul 2002 23:41:08 +0000 |
parents | c42ac9ee2ce4 |
children | 45614e2c1c81 |
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; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 output_version(); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 * 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
|
124 * 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
|
125 * 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
|
126 * playing from there. |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 * 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
|
129 * 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
|
130 * 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
|
131 * 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
|
132 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 * 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
|
134 * 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
|
135 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 * 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
|
137 * 01 - reserved |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 * 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
|
139 * 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
|
140 * |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 * 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
|
142 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 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
|
144 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 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
|
146 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 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
|
148 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
|
149 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 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
|
151 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
|
152 |
351 | 153 /* 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
|
154 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
|
155 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 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
|
158 if (refCounter == NULL) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 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
|
161 return(0); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 /* 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
|
165 internal->rw = refCounter; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
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 * 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
|
169 * 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
|
170 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 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
|
172 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
|
173 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 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
|
175 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 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
|
177 BAIL_MACRO(SMPEG_error(smpeg), 0); |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 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
|
181 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 SMPEG_delete(smpeg); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
183 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
|
184 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 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
|
205 |
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 * 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
|
208 * 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
|
209 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 sample->actual.channels = spec.channels; |
326 | 214 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
|
215 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
|
216 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 SMPEG_play(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 return(1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 } /* _SMPEG_open */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 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
|
223 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 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
|
225 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
|
226 } /* _SMPEG_close */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 static 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
|
230 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 Uint32 retval; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 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
|
233 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
|
234 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 * 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
|
237 * 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
|
238 */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 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
|
244 if (errMsg == NULL) |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 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
|
246 else |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 { |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
248 __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
|
249 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
|
250 } /* else */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 } /* if */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 return(retval); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 } /* _SMPEG_read */ |
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 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 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
|
258 { |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 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
|
260 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
|
261 SMPEGstatus status; |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 /* |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 * 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
|
265 * restart it afterwards. |
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 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
|
268 SMPEG_rewind(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 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
|
270 SMPEG_play(smpeg); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 return(1); |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 } /* _SMPEG_rewind */ |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
274 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
275 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
|
276 { |
326 | 277 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
278 SMPEG *smpeg = (SMPEG *) internal->decoder_private; | |
279 SMPEGstatus status; | |
280 | |
281 /* | |
282 * SMPEG_rewind() really means "stop and rewind", so we may have to | |
283 * restart it afterwards. | |
284 */ | |
285 status = SMPEG_status(smpeg); | |
286 SMPEG_rewind(smpeg); | |
287 SMPEG_skip(smpeg, ((float) ms) / 1000.0); | |
288 if (status == SMPEG_PLAYING) | |
289 SMPEG_play(smpeg); | |
290 return(1); | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
291 } /* _SMPEG_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
292 |
260
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 #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
|
294 |
44a4730a1e6f
Renamed from mp3.c, some minor changes to avoid symbol clash.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 /* 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
|
296 |