annotate SDL_sound.c @ 561:f2985e08589c

Fixed spacing on Speex --help text in configure script.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 30 Jan 2009 01:54:03 -0500
parents e9a6286d9243
children 7e08477b0fc1
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 *
552
2e8907ff98e9 Replaced references to COPYING with references to LICENSE.txt ...
Ryan C. Gordon <icculus@icculus.org>
parents: 526
diff changeset
26 * Please see the file LICENSE.txt in the source's root directory.
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 *
526
2df1f5c62d38 Updated my email address.
Ryan C. Gordon <icculus@icculus.org>
parents: 489
diff changeset
28 * This file written by Ryan C. Gordon. (icculus@icculus.org)
4
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 <ctype.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #include "SDL.h"
441
5b00e43ec23c Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents: 432
diff changeset
41 #include "SDL_thread.h"
4
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
554
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
50 /* All these externs may be missing; we check SOUND_SUPPORTS_xxx before use. */
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
51 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SMPEG;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
52 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MPGLIB;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
53 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIKMOD;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
54 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
55 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
56 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
57 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AU;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
58 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
59 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
60 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
61 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
62 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
63 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
64 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_QuickTime;
e9a6286d9243 Tidy up the decoder list code.
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
65 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SPEEX;
450
6d328f00c20d Added Speex decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 445
diff changeset
66
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
67 typedef struct
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
68 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
69 int available;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
70 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
71 } decoder_element;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
72
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
73 static decoder_element decoders[] =
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 {
262
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
75 #if (defined SOUND_SUPPORTS_SMPEG)
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
76 { 0, &__Sound_DecoderFunctions_SMPEG },
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
77 #endif
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
78
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
79 #if (defined SOUND_SUPPORTS_MPGLIB)
6fe6de401b63 mpglib support.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
80 { 0, &__Sound_DecoderFunctions_MPGLIB },
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
81 #endif
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
82
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
83 #if (defined SOUND_SUPPORTS_MODPLUG)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
84 { 0, &__Sound_DecoderFunctions_MODPLUG },
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
85 #endif
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
86
209
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
87 #if (defined SOUND_SUPPORTS_MIKMOD)
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
88 { 0, &__Sound_DecoderFunctions_MIKMOD },
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
89 #endif
e63b9393f6ce Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
90
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
91 #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
92 { 0, &__Sound_DecoderFunctions_WAV },
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
93 #endif
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
94
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
95 #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
96 { 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
97 #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
98
216
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
99 #if (defined SOUND_SUPPORTS_AU)
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
100 { 0, &__Sound_DecoderFunctions_AU },
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
101 #endif
07d0939d40e7 Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents: 209
diff changeset
102
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
103 #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
104 { 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
105 #endif
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
106
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 #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
108 { 0, &__Sound_DecoderFunctions_VOC },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 #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
112 { 0, &__Sound_DecoderFunctions_RAW },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 #endif
102
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
114
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
115 #if (defined SOUND_SUPPORTS_SHN)
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
116 { 0, &__Sound_DecoderFunctions_SHN },
72502bed0aef Added SHN entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
117 #endif
110
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
118
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
119 #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
120 { 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
121 #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
122
110
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
123 #if (defined SOUND_SUPPORTS_MIDI)
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
124 { 0, &__Sound_DecoderFunctions_MIDI },
5e5adbe0f215 Added Midi decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
125 #endif
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
126
322
31cc49d7d0ce MacOS fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 311
diff changeset
127 #if (defined SOUND_SUPPORTS_QUICKTIME)
31cc49d7d0ce MacOS fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 311
diff changeset
128 { 0, &__Sound_DecoderFunctions_QuickTime },
31cc49d7d0ce MacOS fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 311
diff changeset
129 #endif
31cc49d7d0ce MacOS fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 311
diff changeset
130
450
6d328f00c20d Added Speex decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 445
diff changeset
131 #if (defined SOUND_SUPPORTS_SPEEX)
6d328f00c20d Added Speex decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 445
diff changeset
132 { 0, &__Sound_DecoderFunctions_SPEEX },
6d328f00c20d Added Speex decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 445
diff changeset
133 #endif
6d328f00c20d Added Speex decoder.
Ryan C. Gordon <icculus@icculus.org>
parents: 445
diff changeset
134
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
135 { 0, NULL }
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 };
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138
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 /* General SDL_sound state ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
142 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
143 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
144 Uint32 tid;
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
145 int error_available;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
146 char error_string[128];
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
147 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
148 } ErrMsg;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
149
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
150 static ErrMsg *error_msgs = 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
151 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
152
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
153 static Sound_Sample *sample_list = NULL; /* this is a linked list. */
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
154 static SDL_mutex *samplelist_mutex = NULL;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
155
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 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
157 static int initialized = 0;
4
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 /* functions ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 void Sound_GetLinkedVersion(Sound_Version *ver)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 if (ver != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 ver->major = SOUND_VER_MAJOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 ver->minor = SOUND_VER_MINOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 ver->patch = SOUND_VER_PATCH;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 } /* Sound_GetLinkedVersion */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 int Sound_Init(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 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
176 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
177 size_t total = sizeof (decoders) / sizeof (decoders[0]);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 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
179
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
180 sample_list = NULL;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
181 error_msgs = NULL;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 available_decoders = (const Sound_DecoderInfo **)
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
184 malloc((total) * sizeof (Sound_DecoderInfo *));
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186
432
ddce7101673e Call SDL_InitSubSystem instead of SDL_Init, to prevent unwanted initialization
Ryan C. Gordon <icculus@icculus.org>
parents: 400
diff changeset
187 SDL_InitSubSystem(SDL_INIT_AUDIO);
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
188
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
189 errorlist_mutex = SDL_CreateMutex();
445
d0393837bfac Never actually created samplelist_mutex (doh!) ... Thanks, Glenn Maynard!
Ryan C. Gordon <icculus@icculus.org>
parents: 441
diff changeset
190 samplelist_mutex = SDL_CreateMutex();
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
191
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
192 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
193 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
194 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
195 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
196 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
197 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
198 pos++;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
199 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
200 } /* for */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
202 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
203
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 initialized = 1;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 } /* Sound_Init */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 int Sound_Quit(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
211 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
212 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
213 size_t i;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
214
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
217 while (((volatile Sound_Sample *) sample_list) != NULL)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
218 Sound_FreeSample(sample_list);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
220 initialized = 0;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
221
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
222 SDL_DestroyMutex(samplelist_mutex);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
223 samplelist_mutex = NULL;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
224 sample_list = 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
225
118
fd942c1433f8 Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 110
diff changeset
226 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
227 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
228 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
229 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
230 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
231 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
232 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
233 } /* for */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
234
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 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
236 free((void *) available_decoders);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 available_decoders = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
239 /* 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
240 SDL_LockMutex(errorlist_mutex);
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
241 for (err = error_msgs; err != NULL; err = nexterr)
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
242 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
243 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
244 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
245 } /* for */
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
246 error_msgs = 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
247 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
248 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
249 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
250
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 } /* Sound_Quit */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 const Sound_DecoderInfo **Sound_AvailableDecoders(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 return(available_decoders); /* READ. ONLY. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 } /* Sound_AvailableDecoders */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
261 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
262 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
263 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
264 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
265
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
266 if (error_msgs != 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
267 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
268 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
269
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
270 SDL_LockMutex(errorlist_mutex);
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
271 for (i = error_msgs; i != NULL; i = i->next)
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
272 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
273 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
274 {
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
275 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
276 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
277 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
278 } /* for */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
279 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
280 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
281
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
282 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
283 } /* findErrorForCurrentThread */
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
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 const char *Sound_GetError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
288 const char *retval = NULL;
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
289 ErrMsg *err;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
290
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
291 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
292 return(ERR_NOT_INITIALIZED);
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
293
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
294 err = findErrorForCurrentThread();
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
295 if ((err != NULL) && (err->error_available))
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
296 {
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
297 retval = err->error_string;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
298 err->error_available = 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
299 } /* if */
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
300
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
301 return(retval);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 } /* Sound_GetError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 void Sound_ClearError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 {
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
307 ErrMsg *err;
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 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
310 return;
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
311
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
312 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
313 if (err != NULL)
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
314 err->error_available = 0;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 } /* Sound_ClearError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317
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 * This is declared in the internal header.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
321 void __Sound_SetError(const char *str)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
323 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
324
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
325 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
326 return;
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
327
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
328 SNDDBG(("__Sound_SetError(\"%s\");%s\n", str,
226
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
329 (initialized) ? "" : " [NOT INITIALIZED!]"));
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
330
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
331 if (!initialized)
57e16a6d244f Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
332 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
333
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
334 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
335 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
336 {
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
337 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
338 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
339 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
340
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
341 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
342 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
343
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
344 SDL_LockMutex(errorlist_mutex);
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
345 err->next = error_msgs;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
346 error_msgs = err;
219
ca3483f4cfec Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
347 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
348 } /* 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
349
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
350 err->error_available = 1;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
351 strncpy(err->error_string, str, sizeof (err->error_string));
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
352 err->error_string[sizeof (err->error_string) - 1] = '\0';
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
353 } /* __Sound_SetError */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
354
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
355
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
356 Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms)
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
357 {
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
358 /* "frames" == "sample frames" */
441
5b00e43ec23c Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents: 432
diff changeset
359 float frames_per_ms = ((float) info->rate) / 1000.0f;
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
360 Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms));
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
361 Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels;
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
362 return(frame_offset * frame_size);
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
363 } /* __Sound_convertMsToBytePos */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 * 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
369 * platform has "strcasecmp", "stricmp", or
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 * "compare_two_damned_strings_case_insensitive", which I hear is in the
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 * 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
372 * they like.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 int __Sound_strcasecmp(const char *x, const char *y)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 int ux, uy;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377
98
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
378 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
379 return(0);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
380
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
381 if (x == NULL)
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
382 return(-1);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
383
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
384 if (y == NULL)
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
385 return(1);
dfdf7b4e05bd Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 80
diff changeset
386
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 do
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 ux = toupper((int) *x);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 uy = toupper((int) *y);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 if (ux > uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 else if (ux < uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 return(-1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 x++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 y++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 } while ((ux) && (uy));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 } /* __Sound_strcasecmp */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402
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 * 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
405 * 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
406 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 {
485
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
410 /*
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
411 * !!! FIXME: We're going to need to pool samples, since the mixer
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
412 * !!! FIXME: might be allocating tons of these on a regular basis.
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
413 */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 Sound_Sample *retval = malloc(sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 if ((retval == NULL) || (internal == NULL))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
418 __Sound_SetError(ERR_OUT_OF_MEMORY);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 if (retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 if (internal)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 memset(retval, '\0', sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 memset(internal, '\0', sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 assert(bufferSize > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 retval->buffer = malloc(bufferSize); /* pure ugly. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 if (!retval->buffer)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
434 __Sound_SetError(ERR_OUT_OF_MEMORY);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 memset(retval->buffer, '\0', bufferSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 retval->buffer_size = bufferSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 if (desired != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 internal->rw = rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 retval->opaque = internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 return(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 } /* alloc_sample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
451 #if (defined DEBUG_CHATTER)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
452 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
453 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
454 switch(fmt)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
455 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
456 case AUDIO_U8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
457 return("U8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
458 case AUDIO_S8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
459 return("S8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
460 case AUDIO_U16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
461 return("U16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
462 case AUDIO_S16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
463 return("S16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
464 case AUDIO_U16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
465 return("U16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
466 case AUDIO_S16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
467 return("S16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
468 } /* switch */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
469
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
470 return("Unknown");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
471 } /* fmt_to_str */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
472 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
473
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
474
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 * The bulk of the Sound_NewSample() work is done here...
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 * Ask the specified decoder to handle the data in (rw), and if
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 * back to where it was, and return false.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 static int init_sample(const Sound_DecoderFunctions *funcs,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482 Sound_Sample *sample, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 Sound_AudioInfo *_desired)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 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
486 Sound_AudioInfo desired;
400
9d0b5ec9cc26 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
487 int pos = SDL_RWtell(internal->rw);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 /* fill in the funcs for this decoder... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 sample->decoder = &funcs->info;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491 internal->funcs = funcs;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 if (!funcs->open(sample, ext))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 /* success; we've got a decoder! */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500 /* Now we need to set up the conversion buffer... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504
340
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
505 if (desired.format == 0)
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
506 desired.format = sample->actual.format;
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
507 if (desired.channels == 0)
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
508 desired.channels = sample->actual.channels;
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
509 if (desired.rate == 0)
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
510 desired.rate = sample->actual.rate;
5a72981b8cba Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
511
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
512 if (Sound_BuildAudioCVT(&internal->sdlcvt,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
513 sample->actual.format,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
514 sample->actual.channels,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
515 sample->actual.rate,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
516 desired.format,
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
517 desired.channels,
382
ce998ee6194f Sync'd with latest altcvt.
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
518 desired.rate,
ce998ee6194f Sync'd with latest altcvt.
Ryan C. Gordon <icculus@icculus.org>
parents: 377
diff changeset
519 sample->buffer_size) == -1)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
521 __Sound_SetError(SDL_GetError());
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 if (internal->sdlcvt.len_mult > 1)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 void *rc = realloc(sample->buffer,
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
530 sample->buffer_size * internal->sdlcvt.len_mult);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 if (rc == NULL)
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 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 sample->buffer = rc;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 /* these pointers are all one and the same. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 internal->sdlcvt.buf = internal->buffer = sample->buffer;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 internal->buffer_size = sample->buffer_size / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545 internal->sdlcvt.len = internal->buffer_size;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
547 /* Prepend our new Sound_Sample to the sample_list... */
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
548 SDL_LockMutex(samplelist_mutex);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
549 internal->next = sample_list;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
550 if (sample_list != NULL)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
551 ((Sound_SampleInternal *) sample_list->opaque)->prev = sample;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
552 sample_list = sample;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
553 SDL_UnlockMutex(samplelist_mutex);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
555 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
556 fmt_to_str(sample->desired.format),
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
557 sample->desired.rate,
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
558 sample->desired.channels));
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
559
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
560 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
561 fmt_to_str(sample->actual.format),
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
562 sample->actual.rate,
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
563 sample->actual.channels));
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
564
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
565 SNDDBG(("On-the-fly conversion: %s.\n",
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
566 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
567
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 } /* init_sample */
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
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 Sound_AudioInfo *desired, Uint32 bSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 Sound_Sample *retval;
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
576 decoder_element *decoder;
4
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 /* sanity checks. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL);
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 retval = alloc_sample(rw, desired, bSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 if (!retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 return(NULL); /* alloc_sample() sets error message... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 if (ext != NULL)
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 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
590 if (decoder->available)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
592 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
593 while (*decoderExt)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
594 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
595 if (__Sound_strcasecmp(*decoderExt, ext) == 0)
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
596 {
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
597 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
598 return(retval);
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
599 break; /* done with this decoder either way. */
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
600 } /* if */
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
601 decoderExt++;
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
602 } /* while */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
606
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607 /* 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
608 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
609 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 143
diff changeset
610 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
611 {
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
612 int should_try = 1;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
613 const char **decoderExt = decoder->funcs->info.extensions;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
614
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
615 /* skip if we would have tried decoder above... */
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
616 while (*decoderExt)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
617 {
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
618 if (__Sound_strcasecmp(*decoderExt, ext) == 0)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
619 {
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
620 should_try = 0;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
621 break;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
622 } /* if */
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
623 decoderExt++;
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
624 } /* while */
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
625
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
626 if (should_try)
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
627 {
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
628 if (init_sample(decoder->funcs, retval, ext, desired))
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
629 return(retval);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
630 } /* if */
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
631 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
633
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
634 /* nothing could handle the sound data... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
635 free(retval->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
636 if (retval->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
637 free(retval->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
638 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
639 SDL_RWclose(rw);
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
640 __Sound_SetError(ERR_UNSUPPORTED_FORMAT);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
641 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
642 } /* Sound_NewSample */
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
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
645 Sound_Sample *Sound_NewSampleFromFile(const char *filename,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646 Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 const char *ext;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
650 SDL_RWops *rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
653 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
654
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
655 ext = strrchr(filename, '.');
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 rw = SDL_RWFromFile(filename, "rb");
485
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
657 /* !!! FIXME: rw = RWops_FromFile(filename, "rb");*/
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
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 if (ext != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
661 ext++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
662
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
663 return(Sound_NewSample(rw, ext, desired, bufferSize));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
664 } /* Sound_NewSampleFromFile */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
665
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
666
485
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
667 Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data,
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
668 Uint32 size,
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
669 const char *ext,
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
670 Sound_AudioInfo *desired,
489
c00e26a7e0b6 Patched compile error.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
671 Uint32 bufferSize)
485
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
672 {
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
673 SDL_RWops *rw;
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
674
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
675 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
676 BAIL_IF_MACRO(data == NULL, ERR_INVALID_ARGUMENT, NULL);
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
677 BAIL_IF_MACRO(size == 0, ERR_INVALID_ARGUMENT, NULL);
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
678
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
679 rw = SDL_RWFromMem(data, size);
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
680 /* !!! FIXME: rw = RWops_FromMem(data, size);*/
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
681 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
682
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
683 return(Sound_NewSample(rw, ext, desired, bufferSize));
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
684 } /* Sound_NewSampleFromMem */
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
685
137c0b00ea4c Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
686
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
687 void Sound_FreeSample(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
688 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
689 Sound_SampleInternal *internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
690
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
691 if (!initialized)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
692 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
693 __Sound_SetError(ERR_NOT_INITIALIZED);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
694 return;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
695 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
696
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
697 if (sample == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
698 {
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
699 __Sound_SetError(ERR_INVALID_ARGUMENT);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
700 return;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
701 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
702
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
703 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
704
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
705 SDL_LockMutex(samplelist_mutex);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
706
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
707 /* update the sample_list... */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
708 if (internal->prev != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
709 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
710 Sound_SampleInternal *prevInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
711 prevInternal = (Sound_SampleInternal *) internal->prev->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
712 prevInternal->next = internal->next;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
713 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
714 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
715 {
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
716 assert(sample_list == sample);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
717 sample_list = internal->next;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
718 } /* else */
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 if (internal->next != NULL)
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 *nextInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
723 nextInternal = (Sound_SampleInternal *) internal->next->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
724 nextInternal->prev = internal->prev;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
725 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
726
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
727 SDL_UnlockMutex(samplelist_mutex);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
728
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
729 /* nuke it... */
237
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
730 internal->funcs->close(sample);
ceadd952319a Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
731
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
732 if (internal->rw != NULL) /* this condition is a "just in case" thing. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
733 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
734
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
735 if ((internal->buffer != NULL) && (internal->buffer != sample->buffer))
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
736 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
737
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
738 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
739
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
740 if (sample->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
741 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
742
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
743 free(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
744 } /* Sound_FreeSample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
745
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
746
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
747 int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
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 void *newBuf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750 Sound_SampleInternal *internal = NULL;
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 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
753 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
754 internal = ((Sound_SampleInternal *) sample->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
755 newBuf = realloc(sample->buffer, newSize * internal->sdlcvt.len_mult);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
756 BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
757
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
758 internal->sdlcvt.buf = internal->buffer = sample->buffer = newBuf;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
759 sample->buffer_size = newSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
760 internal->buffer_size = newSize / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
761 internal->sdlcvt.len = internal->buffer_size;
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 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
764 } /* Sound_SetBufferSize */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
765
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
766
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
767 Uint32 Sound_Decode(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
768 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
769 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
770 Uint32 retval = 0;
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 /* a boatload of sanity checks... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
773 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
774 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
775 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
776 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
777
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
778 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
779
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
780 assert(sample->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
781 assert(sample->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
782 assert(internal->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
783 assert(internal->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
784
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
785 /* reset EAGAIN. Decoder can flip it back on if it needs to. */
311
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
786 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
787 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
788
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
789 if (retval > 0 && internal->sdlcvt.needed)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
790 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
791 internal->sdlcvt.len = retval;
143
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
792 Sound_ConvertAudio(&internal->sdlcvt);
3e60862fbd76 Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents: 118
diff changeset
793 retval = internal->sdlcvt.len_cvt;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
794 } /* if */
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(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
797 } /* Sound_Decode */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
798
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
799
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
800 Uint32 Sound_DecodeAll(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
801 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
802 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
803 void *buf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
804 Uint32 newBufSize = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
805
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
806 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
807 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
808 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
809
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
810 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
811
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
812 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) &&
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
813 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) )
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
814 {
172
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
815 Uint32 br = Sound_Decode(sample);
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
816 void *ptr = realloc(buf, newBufSize + br);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
817 if (ptr == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
818 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
819 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
387
fb519e6028e3 Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents: 382
diff changeset
820 __Sound_SetError(ERR_OUT_OF_MEMORY);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
821 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
822 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
823 {
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
824 buf = ptr;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
825 memcpy( ((char *) buf) + newBufSize, sample->buffer, br );
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
826 newBufSize += br;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
827 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
828 } /* while */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
829
172
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
830 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
831 return(sample->buffer_size);
705dcbf94639 Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
832
167
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
833 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
834 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
835
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
836 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
837
82acaa7107c2 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
838 internal->sdlcvt.buf = internal->buffer = sample->buffer = buf;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
839 sample->buffer_size = newBufSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
840 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
841 internal->sdlcvt.len = internal->buffer_size;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
842
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
843 return(newBufSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
844 } /* Sound_DecodeAll */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
845
223
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
846
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
847 int Sound_Rewind(Sound_Sample *sample)
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
848 {
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
849 Sound_SampleInternal *internal;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
850 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
851
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
852 internal = (Sound_SampleInternal *) sample->opaque;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
853 if (!internal->funcs->rewind(sample))
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
854 {
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
855 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
856 return(0);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
857 } /* if */
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
858
311
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
859 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
860 sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
861 sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
862
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
863 return(1);
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
864 } /* Sound_Rewind */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
865
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
866
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
867 int Sound_Seek(Sound_Sample *sample, Uint32 ms)
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
868 {
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
869 Sound_SampleInternal *internal;
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
870
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
871 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
872 if (!(sample->flags & SOUND_SAMPLEFLAG_CANSEEK))
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
873 BAIL_MACRO(ERR_CANNOT_SEEK, 0);
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
874
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
875 internal = (Sound_SampleInternal *) sample->opaque;
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
876 BAIL_IF_MACRO(!internal->funcs->seek(sample, ms), NULL, 0);
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
877
311
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
878 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
879 sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
d62c05322a3e Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
880 sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
881
223
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
882 return(1);
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
883 } /* Sound_Rewind */
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
884
249186e31431 Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
885
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
886 Sint32 Sound_GetDuration(Sound_Sample *sample)
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
887 {
553
5ec7f4e5e20b Fixed compilation on pre-C99 compilers (gcc2, msvc, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
888 Sound_SampleInternal *internal;
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
889 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, -1);
553
5ec7f4e5e20b Fixed compilation on pre-C99 compilers (gcc2, msvc, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
890 internal = (Sound_SampleInternal *) sample->opaque;
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
891 return(internal->total_time);
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
892 } /* Sound_GetDuration */
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
893
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
894 /* end of SDL_sound.c ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
895