annotate SDL_sound.c @ 61:7d3a6ea7f1f0

Updated.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 24 Sep 2001 15:31:03 +0000
parents c4b8c39a9798
children b13fafb976be
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 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * Please see the file LICENSE in the source's root directory.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #include <stdio.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <stdlib.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <string.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <assert.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <ctype.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include "SDL.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "SDL_sound.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #define __SDL_SOUND_INTERNAL__
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound_internal.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
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 /* The various decoder drivers... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
47 #if (defined SOUND_SUPPORTS_MP3)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
48 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3;
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
49 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
50
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
51 #if (defined SOUND_SUPPORTS_MOD)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
52 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MOD;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
53 #endif
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
54
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
55 #if (defined SOUND_SUPPORTS_WAV)
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
56 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV;
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
57 #endif
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
58
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
59 #if (defined SOUND_SUPPORTS_AIFF)
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
60 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF;
f27bcbcaeab1 Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
61 #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
62
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
63 #if (defined SOUND_SUPPORTS_OGG)
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
64 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG;
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
65 #endif
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
66
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 #if (defined SOUND_SUPPORTS_VOC)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 #if (defined SOUND_SUPPORTS_RAW)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
75
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
76
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
77 typedef struct
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
78 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
79 int available;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
80 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
81 } decoder_element;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
82
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
83 static decoder_element decoders[] =
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 {
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
85 #if (defined SOUND_SUPPORTS_MP3)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
86 { 0, &__Sound_DecoderFunctions_MP3 },
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
87 #endif
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
88
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
89 #if (defined SOUND_SUPPORTS_MOD)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
90 { 0, &__Sound_DecoderFunctions_MOD },
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
91 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
92
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
93 #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
94 { 0, &__Sound_DecoderFunctions_WAV },
20
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
95 #endif
d4ac6ce1360e Added WAV entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
96
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 #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
98 { 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
99 #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
100
26
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
101 #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
102 { 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
103 #endif
ddc3614c9042 Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
104
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 #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
106 { 0, &__Sound_DecoderFunctions_VOC },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 #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
110 { 0, &__Sound_DecoderFunctions_RAW },
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 #endif
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 };
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 /* General SDL_sound state ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 static int initialized = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 static Sound_Sample *samplesList = NULL; /* this is a linked list. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 static const Sound_DecoderInfo **available_decoders = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 /* functions ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 void Sound_GetLinkedVersion(Sound_Version *ver)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 if (ver != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 ver->major = SOUND_VER_MAJOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 ver->minor = SOUND_VER_MINOR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 ver->patch = SOUND_VER_PATCH;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 } /* Sound_GetLinkedVersion */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 int Sound_Init(void)
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 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
139 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
140 size_t total = sizeof (decoders) / sizeof (decoders[0]);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 samplesList = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 SDL_Init(SDL_INIT_AUDIO);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 available_decoders = (const Sound_DecoderInfo **)
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
147 malloc((total + 1) * sizeof (Sound_DecoderInfo *));
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
150 for (i = 0; i < total; i++)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
151 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
152 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
153 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
154 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
155 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
156 pos++;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
157 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
158 } /* for */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
160 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
161
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 initialized = 1;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 } /* Sound_Init */
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
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 int Sound_Quit(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
169 size_t total = sizeof (decoders) / sizeof (decoders[0]);
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
170 size_t i;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
171
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 while (((volatile Sound_Sample *) samplesList) != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 Sound_FreeSample(samplesList);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
177 for (i = 0; i < total; i++)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
178 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
179 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
180 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
181 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
182 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
183 } /* if */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
184 } /* for */
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
185
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 if (available_decoders != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 free(available_decoders);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 available_decoders = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 initialized = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 } /* Sound_Quit */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 const Sound_DecoderInfo **Sound_AvailableDecoders(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 return(available_decoders); /* READ. ONLY. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 } /* Sound_AvailableDecoders */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 const char *Sound_GetError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 return(SDL_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 } /* Sound_GetError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206
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 void Sound_ClearError(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 SDL_ClearError();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 } /* Sound_ClearError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 * This is declared in the internal header.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 void Sound_SetError(const char *err)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 if (err != NULL)
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
220 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
221 _D(("Sound_SetError(\"%s\");\n", err));
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 SDL_SetError(err);
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
223 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 } /* Sound_SetError */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 * 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
230 * platform has "strcasecmp", "stricmp", or
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 * "compare_two_damned_strings_case_insensitive", which I hear is in the
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 * 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
233 * they like.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 int __Sound_strcasecmp(const char *x, const char *y)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 int ux, uy;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 do
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 ux = toupper((int) *x);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 uy = toupper((int) *y);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 if (ux > uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 else if (ux < uy)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 return(-1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 x++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 y++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 } while ((ux) && (uy));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 } /* __Sound_strcasecmp */
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 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 * 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
257 * 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
258 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 Sound_Sample *retval = malloc(sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 if ((retval == NULL) || (internal == NULL))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 if (retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 if (internal)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 memset(retval, '\0', sizeof (Sound_Sample));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 memset(internal, '\0', sizeof (Sound_SampleInternal));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 assert(bufferSize > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 retval->buffer = malloc(bufferSize); /* pure ugly. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 if (!retval->buffer)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 memset(retval->buffer, '\0', bufferSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 retval->buffer_size = bufferSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 if (desired != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 internal->rw = rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 retval->opaque = internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 return(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 } /* alloc_sample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
299 #if (defined DEBUG_CHATTER)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
300 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
301 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
302 switch(fmt)
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
303 {
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
304 case AUDIO_U8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
305 return("U8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
306 case AUDIO_S8:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
307 return("S8");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
308 case AUDIO_U16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
309 return("U16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
310 case AUDIO_S16LSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
311 return("S16LSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
312 case AUDIO_U16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
313 return("U16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
314 case AUDIO_S16MSB:
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
315 return("S16MSB");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
316 } /* switch */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
317
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
318 return("Unknown");
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
319 } /* fmt_to_str */
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
320 #endif
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
321
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
322
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 * The bulk of the Sound_NewSample() work is done here...
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 * Ask the specified decoder to handle the data in (rw), and if
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 * back to where it was, and return false.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 * !!! FIXME: This is big, ugly, nasty, and smelly.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331 static int init_sample(const Sound_DecoderFunctions *funcs,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 Sound_Sample *sample, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 Sound_AudioInfo *_desired)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 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
336 Sound_AudioInfo desired;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 int pos = SDL_RWtell(internal->rw); /* !!! FIXME: Int? Really? */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 /* fill in the funcs for this decoder... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 sample->decoder = &funcs->info;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341 internal->funcs = funcs;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 if (!funcs->open(sample, ext))
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 /* success; we've got a decoder! */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 /* Now we need to set up the conversion buffer... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 if (SDL_BuildAudioCVT(&internal->sdlcvt,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 sample->actual.format,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 sample->actual.channels,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 (int) sample->actual.rate, /* !!! FIXME: Int? Really? */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 desired.format,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 desired.channels,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 (int) desired.rate) == -1) /* !!! FIXME: Int? Really? */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 Sound_SetError(SDL_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 if (internal->sdlcvt.len_mult > 1)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 void *rc = realloc(sample->buffer,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 sample->buffer_size * internal->sdlcvt.len_mult);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 if (rc == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 sample->buffer = rc;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 /* these pointers are all one and the same. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 internal->sdlcvt.buf = internal->buffer = sample->buffer;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 internal->buffer_size = sample->buffer_size / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 internal->sdlcvt.len = internal->buffer_size;
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 /* Prepend our new Sound_Sample to the samplesList... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 if (samplesList != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 internal->next = samplesList;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 if (samplesList != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 internal->prev = sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 samplesList = sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397
10
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
398 _D(("New sample DESIRED format: %s format, %d rate, %d channels.\n",
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
399 fmt_to_str(sample->desired.format),
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
400 sample->desired.rate,
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
401 sample->desired.channels));
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
402
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
403 _D(("New sample ACTUAL format: %s format, %d rate, %d channels.\n",
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
404 fmt_to_str(sample->actual.format),
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
405 sample->actual.rate,
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
406 sample->actual.channels));
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
407
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
408 _D(("On-the-fly conversion: %s.\n",
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
409 internal->sdlcvt.needed ? "ENABLED" : "DISABLED"));
cc2c32349380 Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
410
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 } /* init_sample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 Sound_AudioInfo *desired, Uint32 bSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
418 size_t total = sizeof (decoders) / sizeof (decoders[0]);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 size_t i;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 Sound_Sample *retval;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 /* sanity checks. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 retval = alloc_sample(rw, desired, bSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 if (!retval)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 return(NULL); /* alloc_sample() sets error message... */
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 if (ext != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
432 for (i = 0; i < total; i++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
434 if (decoders[i].available)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
436 const char *decoderExt = decoders[i].funcs->info.extension;
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
437 if (__Sound_strcasecmp(decoderExt, ext) == 0)
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
438 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
439 if (init_sample(decoders[i].funcs, retval, ext, desired))
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
440 return(retval);
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
441 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 /* no direct extension match? Try everything we've got... */
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
447 for (i = 0; i < total; i++)
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 {
48
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
449 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
450 {
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
451 if (init_sample(decoders[i].funcs, retval, ext, desired))
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
452 return(retval);
c4b8c39a9798 Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
453 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 /* nothing could handle the sound data... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 free(retval->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458 if (retval->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 free(retval->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 free(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 SDL_RWclose(rw);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 Sound_SetError(ERR_UNSUPPORTED_FORMAT);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 return(NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464 } /* Sound_NewSample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 Sound_Sample *Sound_NewSampleFromFile(const char *filename,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468 Sound_AudioInfo *desired,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 Uint32 bufferSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 const char *ext;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472 SDL_RWops *rw;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 ext = strrchr(filename, '.');
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 rw = SDL_RWFromFile(filename, "rb");
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
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 if (ext != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482 ext++;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 return(Sound_NewSample(rw, ext, desired, bufferSize));
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 } /* Sound_NewSampleFromFile */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 void Sound_FreeSample(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 Sound_SampleInternal *internal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 if (!initialized)
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 Sound_SetError(ERR_NOT_INITIALIZED);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 return;
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 if (sample == NULL)
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 Sound_SetError(ERR_INVALID_ARGUMENT);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 return;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 internal->funcs->close(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 /* update the samplesList... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 if (internal->prev != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 Sound_SampleInternal *prevInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512 prevInternal = (Sound_SampleInternal *) internal->prev->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513 prevInternal->next = internal->next;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 assert(samplesList == sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 samplesList = internal->next;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 if (internal->next != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 Sound_SampleInternal *nextInternal;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524 nextInternal = (Sound_SampleInternal *) internal->next->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 nextInternal->prev = internal->prev;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 /* nuke it... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 if (internal->rw != NULL) /* this condition is a "just in case" thing. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 SDL_RWclose(internal->rw);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 assert(internal->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532 if (internal->buffer != sample->buffer)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 free(internal->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 free(internal);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 if (sample->buffer != NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 free(sample->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 free(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 } /* Sound_FreeSample */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539
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 int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 void *newBuf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 internal = ((Sound_SampleInternal *) sample->opaque);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 newBuf = realloc(sample->buffer, newSize * internal->sdlcvt.len_mult);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550 BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552 internal->sdlcvt.buf = internal->buffer = sample->buffer = newBuf;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553 sample->buffer_size = newSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 internal->buffer_size = newSize / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 internal->sdlcvt.len = internal->buffer_size;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 return(1);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558 } /* Sound_SetBufferSize */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 Uint32 Sound_Decode(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 Uint32 retval = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566 /* a boatload of sanity checks... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0);
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 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 assert(sample->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 assert(sample->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 assert(internal->buffer != NULL);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577 assert(internal->buffer_size > 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579 /* reset EAGAIN. Decoder can flip it back on if it needs to. */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581 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
582
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 if (internal->sdlcvt.needed)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 internal->sdlcvt.len = retval;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 SDL_ConvertAudio(&internal->sdlcvt);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 retval *= internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
590 return(retval);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 } /* Sound_Decode */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
594 Uint32 Sound_DecodeAll(Sound_Sample *sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596 Sound_SampleInternal *internal = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597 void *buf = NULL;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 Uint32 newBufSize = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
602 internal = (Sound_SampleInternal *) sample->opaque;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) &&
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) )
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 void *ptr = realloc(buf, newBufSize + sample->buffer_size);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608 if (ptr == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
609 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 Sound_SetError(ERR_OUT_OF_MEMORY);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
615 Uint32 br = Sound_Decode(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
616 memcpy( ((char *) buf) + newBufSize, sample->buffer, br );
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
617 newBufSize += br;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
618 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 } /* while */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
621 free(sample->buffer);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
622 sample->buffer = internal->buffer = internal->sdlcvt.buf = buf;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623 sample->buffer_size = newBufSize;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 internal->buffer_size = newBufSize / internal->sdlcvt.len_mult;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 internal->sdlcvt.len_mult = internal->buffer_size;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
626
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
627 return(newBufSize);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 } /* Sound_DecodeAll */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
630
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631 /* end of SDL_sound.c ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632