Mercurial > SDL_sound_CoreAudio
comparison decoders/mp3.c @ 46:6e13fcc178da
No longer grabs non-MP3 streams. Added init() and quit() methods.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 22 Sep 2001 14:41:10 +0000 |
parents | d9e84e857569 |
children | 6df2f69e037e |
comparison
equal
deleted
inserted
replaced
45:f7a792fdf7a4 | 46:6e13fcc178da |
---|---|
44 #if (!defined SOUND_SUPPORTS_MP3) | 44 #if (!defined SOUND_SUPPORTS_MP3) |
45 #error SOUND_SUPPORTS_MP3 must be defined. | 45 #error SOUND_SUPPORTS_MP3 must be defined. |
46 #endif | 46 #endif |
47 | 47 |
48 | 48 |
49 static int MP3_init(void); | |
50 static void MP3_quit(void); | |
49 static int MP3_open(Sound_Sample *sample, const char *ext); | 51 static int MP3_open(Sound_Sample *sample, const char *ext); |
50 static void MP3_close(Sound_Sample *sample); | 52 static void MP3_close(Sound_Sample *sample); |
51 static Uint32 MP3_read(Sound_Sample *sample); | 53 static Uint32 MP3_read(Sound_Sample *sample); |
52 | 54 |
53 const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 = | 55 const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 = |
57 "MPEG-1 Layer 3 audio through SMPEG", | 59 "MPEG-1 Layer 3 audio through SMPEG", |
58 "Ryan C. Gordon <icculus@clutteredmind.org>", | 60 "Ryan C. Gordon <icculus@clutteredmind.org>", |
59 "http://www.icculus.org/SDL_sound/" | 61 "http://www.icculus.org/SDL_sound/" |
60 }, | 62 }, |
61 | 63 |
62 MP3_open, /* open() method */ | 64 MP3_init, /* init() method */ |
63 MP3_close, /* close() method */ | 65 MP3_quit, /* quit() method */ |
64 MP3_read /* read() method */ | 66 MP3_open, /* open() method */ |
67 MP3_close, /* close() method */ | |
68 MP3_read /* read() method */ | |
65 }; | 69 }; |
70 | |
71 | |
72 static int MP3_init(void) | |
73 { | |
74 return(1); /* always succeeds. */ | |
75 } /* MP3_init */ | |
76 | |
77 | |
78 static void MP3_quit(void) | |
79 { | |
80 /* it's a no-op. */ | |
81 } /* MP3_quit */ | |
82 | |
66 | 83 |
67 static __inline__ void output_version(void) | 84 static __inline__ void output_version(void) |
68 { | 85 { |
69 static int first_time = 1; | 86 static int first_time = 1; |
70 | 87 |
84 SMPEG *smpeg; | 101 SMPEG *smpeg; |
85 SMPEG_Info smpeg_info; | 102 SMPEG_Info smpeg_info; |
86 SDL_AudioSpec spec; | 103 SDL_AudioSpec spec; |
87 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | 104 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
88 SDL_RWops *refCounter; | 105 SDL_RWops *refCounter; |
106 Uint8 mp3_magic[2]; | |
89 | 107 |
90 output_version(); | 108 output_version(); |
109 | |
110 /* | |
111 * SMPEG appears to be far too greedy about what it accepts as input. | |
112 * This test was adapted from SDL_mixer. | |
113 */ | |
114 if (SDL_RWread(internal->rw, mp3_magic, sizeof (mp3_magic), 1) != 1) | |
115 { | |
116 Sound_SetError("MP3: Could not read MP3 magic."); | |
117 return(0); | |
118 } | |
119 if (mp3_magic[0] != 0xFF || (mp3_magic[1] & 0xF0) != 0xF0) | |
120 { | |
121 Sound_SetError("MP3: Not an MP3 stream."); | |
122 return(0); | |
123 } | |
124 SDL_RWseek(internal->rw, -sizeof (mp3_magic), SEEK_CUR); | |
91 | 125 |
92 refCounter = RWops_RWRefCounter_new(internal->rw); | 126 refCounter = RWops_RWRefCounter_new(internal->rw); |
93 if (refCounter == NULL) | 127 if (refCounter == NULL) |
94 { | 128 { |
95 _D(("MP3: Failed to create reference counting RWops.\n")); | 129 _D(("MP3: Failed to create reference counting RWops.\n")); |