annotate SDL_sound.c @ 235:2b9131a7653c

Took out some whitespace.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 19 Jan 2002 20:13:42 +0000
parents 57e16a6d244f
children ceadd952319a
rev   line source
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /**
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * This file implements the core API, which is relatively simple.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 * The real meat of SDL_sound is in the decoders directory.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * Documentation is in SDL_sound.h ... It's verbose, honest. :)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 *
184
47cc2de2ae36 Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents: 172
diff changeset
26 * Please see the file COPYING in the source's root directory.
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
107
427541211bfd config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 102
diff changeset
31 #if HAVE_CONFIG_H
427541211bfd config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 102
diff changeset
32 # include <config.h>
427541211bfd config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 102
diff changeset
33 #endif
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <stdio.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <stdlib.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <string.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include <assert.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include <ctype.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include "SDL.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #define __SDL_SOUND_INTERNAL__
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #include "SDL_sound_internal.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 /* The various decoder drivers... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
50 #if (defined SOUND_SUPPORTS_MP3)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
51 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3;
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
52 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
53
209
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
54 #if (defined SOUND_SUPPORTS_MIKMOD)
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
55 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIKMOD;
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
56 #endif
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
57
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
58 #if (defined SOUND_SUPPORTS_MODPLUG)
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
59 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG;
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
60 #endif
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
61
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
62 #if (defined SOUND_SUPPORTS_WAV)
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
63 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV;
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
64 #endif
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
65
37
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
66 #if (defined SOUND_SUPPORTS_AIFF)
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
67 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF;
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
68 #endif
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
69
216
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
70 #if (defined SOUND_SUPPORTS_AU)
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
71 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AU;
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
72 #endif
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
73
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
74 #if (defined SOUND_SUPPORTS_OGG)
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
75 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG;
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
76 #endif
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
77
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 #if (defined SOUND_SUPPORTS_VOC)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 #if (defined SOUND_SUPPORTS_RAW)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
102
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
86 #if (defined SOUND_SUPPORTS_SHN)
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
87 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN;
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
88 #endif
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
89
110
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
90 #if (defined SOUND_SUPPORTS_MIDI)
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
91 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI;
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
92 #endif
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
93
157
fa3e593b6a5e FLAC decoder added.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
94 #if (defined SOUND_SUPPORTS_FLAC)
fa3e593b6a5e FLAC decoder added.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
95 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC;
fa3e593b6a5e FLAC decoder added.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
96 #endif
fa3e593b6a5e FLAC decoder added.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
97
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
98
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
99
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
100 typedef struct
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
101 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
102 int available;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
103 const Sound_DecoderFunctions *funcs;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
104 } decoder_element;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
105
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
106 static decoder_element decoders[] =
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 {
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
108 #if (defined SOUND_SUPPORTS_MP3)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
109 { 0, &__Sound_DecoderFunctions_MP3 },
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
110 #endif
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
111
209
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
112 #if (defined SOUND_SUPPORTS_MIKMOD)
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
113 { 0, &__Sound_DecoderFunctions_MIKMOD },
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
114 #endif
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
115
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
116 #if (defined SOUND_SUPPORTS_MODPLUG)
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
117 { 0, &__Sound_DecoderFunctions_MODPLUG },
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
118 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
119
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
120 #if (defined SOUND_SUPPORTS_WAV)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
121 { 0, &__Sound_DecoderFunctions_WAV },
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
122 #endif
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
123
37
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
124 #if (defined SOUND_SUPPORTS_AIFF)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
125 { 0, &__Sound_DecoderFunctions_AIFF },
37
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
126 #endif
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
127
216
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
128 #if (defined SOUND_SUPPORTS_AU)
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
129 { 0, &__Sound_DecoderFunctions_AU },
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
130 #endif
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
131
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
132 #if (defined SOUND_SUPPORTS_OGG)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
133 { 0, &__Sound_DecoderFunctions_OGG },
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
134 #endif
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
135
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 #if (defined SOUND_SUPPORTS_VOC)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
137 { 0, &__Sound_DecoderFunctions_VOC },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 #if (defined SOUND_SUPPORTS_RAW)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
141 { 0, &__Sound_DecoderFunctions_RAW },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 #endif
102
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
143
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
144 #if (defined SOUND_SUPPORTS_SHN)
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
145 { 0, &__Sound_DecoderFunctions_SHN },
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
146 #endif
110
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
147
163
b6d6f994e970 Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
148 #if (defined SOUND_SUPPORTS_FLAC)
b6d6f994e970 Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
149 { 0, &__Sound_DecoderFunctions_FLAC },
b6d6f994e970 Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
150 #endif
b6d6f994e970 Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
151
110
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
152 #if (defined SOUND_SUPPORTS_MIDI)
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
153 { 0, &__Sound_DecoderFunctions_MIDI },
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
154 #endif
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
155
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
156 { 0, NULL }
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 };
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 /* General SDL_sound state ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
163 typedef struct __SOUND_ERRMSGTYPE__
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
164 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
165 Uint32 tid;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
166 int errorAvailable;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
167 char errorString[128];
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
168 struct __SOUND_ERRMSGTYPE__ *next;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
169 } ErrMsg;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
170
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
171 static ErrMsg *errorMessages = NULL;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
172 static SDL_mutex *errorlist_mutex = NULL;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
173
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
174 /* !!! FIXME: This needs a mutex. */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 static Sound_Sample *samplesList = NULL; /* this is a linked list. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 static const Sound_DecoderInfo **available_decoders = NULL;
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
177 static int initialized = 0;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 /* functions ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 void Sound_GetLinkedVersion(Sound_Version *ver)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 if (ver != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 ver->major = SOUND_VER_MAJOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 ver->minor = SOUND_VER_MINOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 ver->patch = SOUND_VER_PATCH;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 } /* Sound_GetLinkedVersion */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 int Sound_Init(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 size_t i;
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
196 size_t pos = 0;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
197 size_t total = sizeof (decoders) / sizeof (decoders[0]);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
199
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 samplesList = NULL;
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
201 errorMessages = NULL;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 available_decoders = (const Sound_DecoderInfo **)
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
204 malloc((total) * sizeof (Sound_DecoderInfo *));
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
207 SDL_Init(SDL_INIT_AUDIO);
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
208 errorlist_mutex = SDL_CreateMutex();
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
209
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
210 for (i = 0; decoders[i].funcs != NULL; i++)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
211 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
212 decoders[i].available = decoders[i].funcs->init();
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
213 if (decoders[i].available)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
214 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
215 available_decoders[pos] = &(decoders[i].funcs->info);
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
216 pos++;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
217 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
218 } /* for */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
220 available_decoders[pos] = NULL;
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
221
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 initialized = 1;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 } /* Sound_Init */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 int Sound_Quit(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
229 ErrMsg *err;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
230 ErrMsg *nexterr = NULL;
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
231 size_t i;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
232
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 while (((volatile Sound_Sample *) samplesList) != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 Sound_FreeSample(samplesList);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
238 samplesList = NULL;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
239
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
240 for (i = 0; decoders[i].funcs != NULL; i++)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
241 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
242 if (decoders[i].available)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
243 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
244 decoders[i].funcs->quit();
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
245 decoders[i].available = 0;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
246 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
247 } /* for */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
248
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 if (available_decoders != NULL)
80
25ee62c6b333 Fixed a const complaint from Visual C++ 6.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
250 free((void *) available_decoders);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 available_decoders = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
253 /* clean up error state for each thread... */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
254 SDL_LockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
255 for (err = errorMessages; err != NULL; err = nexterr)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
256 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
257 nexterr = err->next;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
258 free(err);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
259 } /* for */
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
260 errorMessages = NULL;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
261 initialized = 0;
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
262 SDL_UnlockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
263 SDL_DestroyMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
264 errorlist_mutex = NULL;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
265
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 } /* Sound_Quit */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 const Sound_DecoderInfo **Sound_AvailableDecoders(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 return(available_decoders); /* READ. ONLY. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 } /* Sound_AvailableDecoders */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
276 static ErrMsg *findErrorForCurrentThread(void)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
277 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
278 ErrMsg *i;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
279 Uint32 tid;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
280
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
281 if (errorMessages != NULL)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
282 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
283 tid = SDL_ThreadID();
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
284
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
285 SDL_LockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
286 for (i = errorMessages; i != NULL; i = i->next)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
287 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
288 if (i->tid == tid)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
289 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
290 SDL_UnlockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
291 return(i);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
292 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
293 } /* for */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
294 SDL_UnlockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
295 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
296
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
297 return(NULL); /* no error available. */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
298 } /* findErrorForCurrentThread */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
299
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
300
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 const char *Sound_GetError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
303 const char *retval = NULL;
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
304 ErrMsg *err;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
305
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
306 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
307 return(ERR_NOT_INITIALIZED);
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
308
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
309 err = findErrorForCurrentThread();
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
310 if ((err != NULL) && (err->errorAvailable))
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
311 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
312 retval = err->errorString;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
313 err->errorAvailable = 0;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
314 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
315
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
316 return(retval);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 } /* Sound_GetError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 void Sound_ClearError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 {
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
322 ErrMsg *err;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
323
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
324 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
325 return;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
326
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
327 err = findErrorForCurrentThread();
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
328 if (err != NULL)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
329 err->errorAvailable = 0;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 } /* Sound_ClearError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 * This is declared in the internal header.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 */
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
336 void Sound_SetError(const char *str)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
338 ErrMsg *err;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
339
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
340 if (str == NULL)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
341 return;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
342
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
343 SNDDBG(("Sound_SetError(\"%s\");%s\n", str,
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
344 (initialized) ? "" : " [NOT INITIALIZED!]"));
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
345
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
346 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
347 return;
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
348
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
349 err = findErrorForCurrentThread();
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
350 if (err == NULL)
165
9b26ed9eaf04 Whoops; I should read the code before I change it next time; regressing
Ryan C. Gordon <icculus@icculus.org>
parents: 163
diff changeset
351 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
352 err = (ErrMsg *) malloc(sizeof (ErrMsg));
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
353 if (err == NULL)
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
354 return; /* uhh...? */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
355
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
356 memset((void *) err, '\0', sizeof (ErrMsg));
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
357 err->tid = SDL_ThreadID();
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
358
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
359 SDL_LockMutex(errorlist_mutex);
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
360 err->next = errorMessages;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
361 errorMessages = err;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
362 SDL_UnlockMutex(errorlist_mutex);
165
9b26ed9eaf04 Whoops; I should read the code before I change it next time; regressing
Ryan C. Gordon <icculus@icculus.org>
parents: 163
diff changeset
363 } /* if */
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
364
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
365 err->errorAvailable = 1;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
366 strncpy(err->errorString, str, sizeof (err->errorString));
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
367 err->errorString[sizeof (err->errorString) - 1] = '\0';
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 } /* Sound_SetError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 * I honestly don't want to mess around with figuring out if a given
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 * platform has "strcasecmp", "stricmp", or
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 * "compare_two_damned_strings_case_insensitive", which I hear is in the
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 * next release of Carbon. :) This is exported so decoders may use it if
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 * they like.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379 int __Sound_strcasecmp(const char *x, const char *y)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 int ux, uy;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382
98
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
383 if (x == y) /* same pointer? Both NULL? */
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
384 return(0);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
385
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
386 if (x == NULL)
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
387 return(-1);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
388
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
389 if (y == NULL)
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
390 return(1);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
391
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 do
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 ux = toupper((int) *x);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 uy = toupper((int) *y);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 if (ux > uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 else if (ux < uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 return(-1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 x++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 y++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 } while ((ux) && (uy));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 } /* __Sound_strcasecmp */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 * Allocate a Sound_Sample, and fill in most of its fields. Those that need
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 * to be filled in later, by a decoder, will be initialized to zero.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 Sound_Sample *retval = malloc(sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 if ((retval == NULL) || (internal == NULL))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 if (retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 if (internal)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 memset(retval, '\0', sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 memset(internal, '\0', sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 assert(bufferSize > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 retval->buffer = malloc(bufferSize); /* pure ugly. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 if (!retval->buffer)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 memset(retval->buffer, '\0', bufferSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 retval->buffer_size = bufferSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 if (desired != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 internal->rw = rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 retval->opaque = internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 return(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449 } /* alloc_sample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
452 #if (defined DEBUG_CHATTER)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
453 static __inline__ const char *fmt_to_str(Uint16 fmt)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
454 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
455 switch(fmt)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
456 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
457 case AUDIO_U8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
458 return("U8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
459 case AUDIO_S8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
460 return("S8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
461 case AUDIO_U16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
462 return("U16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
463 case AUDIO_S16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
464 return("S16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
465 case AUDIO_U16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
466 return("U16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
467 case AUDIO_S16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
468 return("S16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
469 } /* switch */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
470
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
471 return("Unknown");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
472 } /* fmt_to_str */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
473 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
474
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
475
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 * The bulk of the Sound_NewSample() work is done here...
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 * Ask the specified decoder to handle the data in (rw), and if
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 * back to where it was, and return false.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482 * !!! FIXME: This is big, ugly, nasty, and smelly.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 static int init_sample(const Sound_DecoderFunctions *funcs,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 Sound_Sample *sample, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 Sound_AudioInfo *_desired)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
37
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
489 Sound_AudioInfo desired;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 int pos = SDL_RWtell(internal->rw); /* !!! FIXME: Int? Really? */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 /* fill in the funcs for this decoder... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 sample->decoder = &funcs->info;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 internal->funcs = funcs;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 if (!funcs->open(sample, ext))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 /* success; we've got a decoder! */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 /* Now we need to set up the conversion buffer... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
508 if (Sound_BuildAudioCVT(&internal->sdlcvt,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
509 sample->actual.format,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
510 sample->actual.channels,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
511 sample->actual.rate,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
512 desired.format,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
513 desired.channels,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
514 desired.rate) == -1)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 Sound_SetError(SDL_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 if (internal->sdlcvt.len_mult > 1)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524 void *rc = realloc(sample->buffer,
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
525 sample->buffer_size * internal->sdlcvt.len_mult);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526 if (rc == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 sample->buffer = rc;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 /* these pointers are all one and the same. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 internal->sdlcvt.buf = internal->buffer = sample->buffer;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 internal->buffer_size = sample->buffer_size / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 internal->sdlcvt.len = internal->buffer_size;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 /* Prepend our new Sound_Sample to the samplesList... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 if (samplesList != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545 internal->next = samplesList;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546 if (samplesList != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 internal->prev = sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 samplesList = sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
551 SNDDBG(("New sample DESIRED format: %s format, %d rate, %d channels.\n",
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
552 fmt_to_str(sample->desired.format),
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
553 sample->desired.rate,
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
554 sample->desired.channels));
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
555
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
556 SNDDBG(("New sample ACTUAL format: %s format, %d rate, %d channels.\n",
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
557 fmt_to_str(sample->actual.format),
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
558 sample->actual.rate,
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
559 sample->actual.channels));
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
560
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
561 SNDDBG(("On-the-fly conversion: %s.\n",
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
562 internal->sdlcvt.needed ? "ENABLED" : "DISABLED"));
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
563
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565 } /* init_sample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 Sound_AudioInfo *desired, Uint32 bSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571 Sound_Sample *retval;
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
572 decoder_element *decoder;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 /* sanity checks. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 retval = alloc_sample(rw, desired, bSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579 if (!retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 return(NULL); /* alloc_sample() sets error message... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582 if (ext != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
584 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
586 if (decoder->available)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
588 const char **decoderExt = decoder->funcs->info.extensions;
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
589 while (*decoderExt)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
590 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
591 if (__Sound_strcasecmp(*decoderExt, ext) == 0)
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
592 {
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
593 if (init_sample(decoder->funcs, retval, ext, desired))
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
594 return(retval);
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
595 } /* if */
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
596 decoderExt++;
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
597 } /* while */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
602 /* no direct extension match? Try everything we've got... */
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
603 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
605 if (decoder->available)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
606 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
607 if (init_sample(decoder->funcs, retval, ext, desired))
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
608 return(retval);
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
609 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612 /* nothing could handle the sound data... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613 free(retval->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614 if (retval->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
615 free(retval->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
616 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
617 SDL_RWclose(rw);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
618 Sound_SetError(ERR_UNSUPPORTED_FORMAT);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620 } /* Sound_NewSample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
621
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
622
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623 Sound_Sample *Sound_NewSampleFromFile(const char *filename,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
626 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
627 const char *ext;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 SDL_RWops *rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
630 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
633 ext = strrchr(filename, '.');
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
634 rw = SDL_RWFromFile(filename, "rb");
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
635 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
636
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
637 if (ext != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
638 ext++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
639
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
640 return(Sound_NewSample(rw, ext, desired, bufferSize));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
641 } /* Sound_NewSampleFromFile */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
642
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
643
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
644 void Sound_FreeSample(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
645 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646 Sound_SampleInternal *internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 if (!initialized)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
650 Sound_SetError(ERR_NOT_INITIALIZED);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651 return;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
653
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
654 if (sample == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
655 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 Sound_SetError(ERR_INVALID_ARGUMENT);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
657 return;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
659
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
660 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
661
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
662 internal->funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
663
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
664 /* update the samplesList... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
665 if (internal->prev != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
666 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
667 Sound_SampleInternal *prevInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
668 prevInternal = (Sound_SampleInternal *) internal->prev->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
669 prevInternal->next = internal->next;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
670 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
671 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
672 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
673 assert(samplesList == sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
674 samplesList = internal->next;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
675 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
676
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
677 if (internal->next != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
678 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
679 Sound_SampleInternal *nextInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
680 nextInternal = (Sound_SampleInternal *) internal->next->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
681 nextInternal->prev = internal->prev;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
682 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
683
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
684 /* nuke it... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
685 if (internal->rw != NULL) /* this condition is a "just in case" thing. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
686 SDL_RWclose(internal->rw);
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
687
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
688 if ((internal->buffer != NULL) && (internal->buffer != sample->buffer))
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
689 free(internal->buffer);
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
690
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
691 free(internal);
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
692
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
693 if (sample->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
694 free(sample->buffer);
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
695
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
696 free(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
697 } /* Sound_FreeSample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
698
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
699
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
700 int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
701 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
702 void *newBuf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
703 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
704
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
705 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
706 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
707 internal = ((Sound_SampleInternal *) sample->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
708 newBuf = realloc(sample->buffer, newSize * internal->sdlcvt.len_mult);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
709 BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
710
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
711 internal->sdlcvt.buf = internal->buffer = sample->buffer = newBuf;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
712 sample->buffer_size = newSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
713 internal->buffer_size = newSize / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
714 internal->sdlcvt.len = internal->buffer_size;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
715
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
716 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
717 } /* Sound_SetBufferSize */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
718
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
719
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
720 Uint32 Sound_Decode(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
721 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
722 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
723 Uint32 retval = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
724
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
725 /* a boatload of sanity checks... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
726 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
727 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
728 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
729 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
730
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
731 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
732
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
733 assert(sample->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
734 assert(sample->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
735 assert(internal->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
736 assert(internal->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
737
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
738 /* reset EAGAIN. Decoder can flip it back on if it needs to. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
739 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
740 retval = internal->funcs->read(sample);
37
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
741
163
b6d6f994e970 Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
742 if (retval > 0 && internal->sdlcvt.needed)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
743 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
744 internal->sdlcvt.len = retval;
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
745 Sound_ConvertAudio(&internal->sdlcvt);
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
746 retval = internal->sdlcvt.len_cvt;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
747 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
748
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
749 return(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750 } /* Sound_Decode */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
751
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
752
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
753 Uint32 Sound_DecodeAll(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
754 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
755 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
756 void *buf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
757 Uint32 newBufSize = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
758
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
759 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
172
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
760 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0);
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
761 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
762
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
763 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
764
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
765 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) &&
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
766 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) )
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
767 {
172
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
768 Uint32 br = Sound_Decode(sample);
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
769 void *ptr = realloc(buf, newBufSize + br);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
770 if (ptr == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
771 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
772 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
773 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
774 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
775 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
776 {
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
777 buf = ptr;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
778 memcpy( ((char *) buf) + newBufSize, sample->buffer, br );
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
779 newBufSize += br;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
780 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
781 } /* while */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
782
172
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
783 if (buf == NULL) /* ...in case first call to realloc() fails... */
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
784 return(sample->buffer_size);
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
785
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
786 if (internal->buffer != sample->buffer)
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
787 free(internal->buffer);
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
788
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
789 free(sample->buffer);
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
790
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
791 internal->sdlcvt.buf = internal->buffer = sample->buffer = buf;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
792 sample->buffer_size = newBufSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
793 internal->buffer_size = newBufSize / internal->sdlcvt.len_mult;
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
794 internal->sdlcvt.len = internal->buffer_size;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
795
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
796 return(newBufSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
797 } /* Sound_DecodeAll */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
798
223
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
799
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
800 int Sound_Rewind(Sound_Sample *sample)
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
801 {
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
802 Sound_SampleInternal *internal;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
803 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
804
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
805 internal = (Sound_SampleInternal *) sample->opaque;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
806 if (!internal->funcs->rewind(sample))
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
807 {
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
808 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
809 return(0);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
810 } /* if */
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
811
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
812 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
813 sample->flags &= !SOUND_SAMPLEFLAG_ERROR;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
814 sample->flags &= !SOUND_SAMPLEFLAG_EOF;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
815 return(1);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
816 } /* Sound_Rewind */
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
817
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
818
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
819 /* end of SDL_sound.c ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
820