Skip to content

Latest commit

 

History

History
524 lines (459 loc) · 12.7 KB

wavestream.c

File metadata and controls

524 lines (459 loc) · 12.7 KB
 
Oct 21, 1999
Oct 21, 1999
1
/*
Dec 31, 2011
Dec 31, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SDL_mixer: An audio mixer library based on the SDL library
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Oct 21, 1999
Oct 21, 1999
20
21
*/
Dec 14, 2001
Dec 14, 2001
22
/* $Id$ */
Dec 14, 2001
Dec 14, 2001
23
Oct 21, 1999
Oct 21, 1999
24
25
26
27
28
/* This file supports streaming WAV files, without volume adjustment */
#include <stdlib.h>
#include <string.h>
Dec 21, 1999
Dec 21, 1999
29
30
31
32
#include "SDL_audio.h"
#include "SDL_mutex.h"
#include "SDL_rwops.h"
#include "SDL_endian.h"
Oct 21, 1999
Oct 21, 1999
33
Nov 30, 2001
Nov 30, 2001
34
#include "SDL_mixer.h"
Oct 21, 1999
Oct 21, 1999
35
36
#include "wavestream.h"
Sep 11, 2001
Sep 11, 2001
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Taken with permission from SDL_wave.h, part of the SDL library,
available at: http://www.libsdl.org/
and placed under the same license as this mixer library.
*/
/* WAVE files are little-endian */
/*******************************************/
/* Define values for Microsoft WAVE format */
/*******************************************/
#define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */
#define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */
#define PCM_CODE 1
#define ADPCM_CODE 2
#define WAVE_MONO 1
#define WAVE_STEREO 2
/* Normally, these three chunks come consecutively in a WAVE file */
typedef struct WaveFMT {
/* Not saved in the chunk we read:
Uint32 FMTchunk;
Uint32 fmtlen;
*/
Uint16 encoding;
Uint16 channels; /* 1 = mono, 2 = stereo */
Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */
Uint32 byterate; /* Average bytes per second */
Uint16 blockalign; /* Bytes per sample block */
Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */
} WaveFMT;
/* The general chunk found in the WAVE file */
typedef struct Chunk {
Uint32 magic;
Uint32 length;
Uint8 *data; /* Data includes magic and length */
} Chunk;
/*********************************************/
/* Define values for AIFF (IFF audio) format */
/*********************************************/
#define FORM 0x4d524f46 /* "FORM" */
#define AIFF 0x46464941 /* "AIFF" */
#define SSND 0x444e5353 /* "SSND" */
#define COMM 0x4d4d4f43 /* "COMM" */
Jul 3, 2000
Jul 3, 2000
89
/* Currently we only support a single stream at a time */
May 16, 2002
May 16, 2002
90
static WAVStream *music = NULL;
Jul 3, 2000
Jul 3, 2000
91
Oct 21, 1999
Oct 21, 1999
92
93
/* This is the format of the audio mixer data */
static SDL_AudioSpec mixer;
Feb 12, 2003
Feb 12, 2003
94
static int wavestream_volume = MIX_MAX_VOLUME;
Oct 21, 1999
Oct 21, 1999
95
96
/* Function to load the WAV/AIFF stream */
Feb 26, 2008
Feb 26, 2008
97
static SDL_RWops *LoadWAVStream (SDL_RWops *rw, SDL_AudioSpec *spec,
Oct 21, 1999
Oct 21, 1999
98
long *start, long *stop);
Feb 26, 2008
Feb 26, 2008
99
static SDL_RWops *LoadAIFFStream (SDL_RWops *rw, SDL_AudioSpec *spec,
Oct 21, 1999
Oct 21, 1999
100
101
102
103
104
105
106
107
108
109
110
long *start, long *stop);
/* Initialize the WAVStream player, with the given mixer settings
This function returns 0, or -1 if there was an error.
*/
int WAVStream_Init(SDL_AudioSpec *mixerfmt)
{
mixer = *mixerfmt;
return(0);
}
Feb 12, 2003
Feb 12, 2003
111
void WAVStream_SetVolume(int volume)
Oct 21, 1999
Oct 21, 1999
112
{
Feb 12, 2003
Feb 12, 2003
113
wavestream_volume = volume;
Oct 21, 1999
Oct 21, 1999
114
115
}
Jan 4, 2012
Jan 4, 2012
116
/* Load a WAV stream from the given RWops object */
Dec 31, 2011
Dec 31, 2011
117
WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic, int freerw)
Oct 21, 1999
Oct 21, 1999
118
119
120
121
122
{
WAVStream *wave;
SDL_AudioSpec wavespec;
if ( ! mixer.format ) {
Nov 30, 2001
Nov 30, 2001
123
Mix_SetError("WAV music output not started");
Dec 31, 2011
Dec 31, 2011
124
125
126
if ( freerw ) {
SDL_RWclose(rw);
}
Oct 21, 1999
Oct 21, 1999
127
128
return(NULL);
}
Jan 13, 2012
Jan 13, 2012
129
wave = (WAVStream *)SDL_malloc(sizeof *wave);
Oct 21, 1999
Oct 21, 1999
130
131
if ( wave ) {
memset(wave, 0, (sizeof *wave));
Dec 31, 2011
Dec 31, 2011
132
wave->freerw = freerw;
Oct 21, 1999
Oct 21, 1999
133
if ( strcmp(magic, "RIFF") == 0 ) {
Feb 26, 2008
Feb 26, 2008
134
wave->rw = LoadWAVStream(rw, &wavespec,
Oct 21, 1999
Oct 21, 1999
135
136
137
&wave->start, &wave->stop);
} else
if ( strcmp(magic, "FORM") == 0 ) {
Feb 26, 2008
Feb 26, 2008
138
wave->rw = LoadAIFFStream(rw, &wavespec,
Oct 21, 1999
Oct 21, 1999
139
&wave->start, &wave->stop);
Nov 30, 2001
Nov 30, 2001
140
141
} else {
Mix_SetError("Unknown WAVE format");
Oct 21, 1999
Oct 21, 1999
142
}
Feb 26, 2008
Feb 26, 2008
143
if ( wave->rw == NULL ) {
Jan 13, 2012
Jan 13, 2012
144
SDL_free(wave);
Dec 31, 2011
Dec 31, 2011
145
146
147
if ( freerw ) {
SDL_RWclose(rw);
}
Oct 21, 1999
Oct 21, 1999
148
149
150
151
152
return(NULL);
}
SDL_BuildAudioCVT(&wave->cvt,
wavespec.format, wavespec.channels, wavespec.freq,
mixer.format, mixer.channels, mixer.freq);
Dec 31, 2011
Dec 31, 2011
153
154
155
156
157
158
} else {
SDL_OutOfMemory();
if ( freerw ) {
SDL_RWclose(rw);
}
return(NULL);
Oct 21, 1999
Oct 21, 1999
159
160
161
162
163
}
return(wave);
}
/* Start playback of a given WAV stream */
Feb 12, 2003
Feb 12, 2003
164
void WAVStream_Start(WAVStream *wave)
Oct 21, 1999
Oct 21, 1999
165
{
Nov 8, 2009
Nov 8, 2009
166
SDL_RWseek (wave->rw, wave->start, RW_SEEK_SET);
May 16, 2002
May 16, 2002
167
music = wave;
Oct 21, 1999
Oct 21, 1999
168
169
}
May 16, 2002
May 16, 2002
170
/* Play some of a stream previously started with WAVStream_Start() */
Oct 2, 2009
Oct 2, 2009
171
int WAVStream_PlaySome(Uint8 *stream, int len)
Oct 21, 1999
Oct 21, 1999
172
173
{
long pos;
Oct 2, 2009
Oct 2, 2009
174
int left = 0;
Oct 21, 1999
Oct 21, 1999
175
Feb 26, 2008
Feb 26, 2008
176
if ( music && ((pos=SDL_RWtell(music->rw)) < music->stop) ) {
May 16, 2002
May 16, 2002
177
if ( music->cvt.needed ) {
Oct 21, 1999
Oct 21, 1999
178
179
int original_len;
May 16, 2002
May 16, 2002
180
181
original_len=(int)((double)len/music->cvt.len_ratio);
if ( music->cvt.len != original_len ) {
Oct 21, 1999
Oct 21, 1999
182
int worksize;
May 16, 2002
May 16, 2002
183
if ( music->cvt.buf != NULL ) {
Jan 13, 2012
Jan 13, 2012
184
SDL_free(music->cvt.buf);
Oct 21, 1999
Oct 21, 1999
185
}
May 16, 2002
May 16, 2002
186
worksize = original_len*music->cvt.len_mult;
Jan 13, 2012
Jan 13, 2012
187
music->cvt.buf=(Uint8 *)SDL_malloc(worksize);
May 16, 2002
May 16, 2002
188
if ( music->cvt.buf == NULL ) {
Oct 3, 2009
Oct 3, 2009
189
return 0;
Oct 21, 1999
Oct 21, 1999
190
}
May 16, 2002
May 16, 2002
191
music->cvt.len = original_len;
Oct 21, 1999
Oct 21, 1999
192
}
May 16, 2002
May 16, 2002
193
if ( (music->stop - pos) < original_len ) {
Oct 2, 2009
Oct 2, 2009
194
195
196
left = (original_len - (music->stop - pos));
original_len -= left;
left = (int)((double)left*music->cvt.len_ratio);
Oct 21, 1999
Oct 21, 1999
197
}
Feb 26, 2008
Feb 26, 2008
198
original_len = SDL_RWread(music->rw, music->cvt.buf,1,original_len);
Sep 6, 2001
Sep 6, 2001
199
200
201
202
203
204
/* At least at the time of writing, SDL_ConvertAudio()
does byte-order swapping starting at the end of the
buffer. Thus, if we are reading 16-bit samples, we
had better make damn sure that we get an even
number of bytes, or we'll get garbage.
*/
May 16, 2002
May 16, 2002
205
if ( (music->cvt.src_format & 0x0010) && (original_len & 1) ) {
Sep 6, 2001
Sep 6, 2001
206
207
original_len--;
}
May 16, 2002
May 16, 2002
208
209
music->cvt.len = original_len;
SDL_ConvertAudio(&music->cvt);
Feb 12, 2003
Feb 12, 2003
210
SDL_MixAudio(stream, music->cvt.buf, music->cvt.len_cvt, wavestream_volume);
Oct 21, 1999
Oct 21, 1999
211
} else {
May 9, 2006
May 9, 2006
212
Uint8 *data;
May 16, 2002
May 16, 2002
213
if ( (music->stop - pos) < len ) {
Oct 2, 2009
Oct 2, 2009
214
215
left = (len - (music->stop - pos));
len -= left;
Oct 21, 1999
Oct 21, 1999
216
}
May 9, 2006
May 9, 2006
217
218
219
data = SDL_stack_alloc(Uint8, len);
if (data)
{
Feb 26, 2008
Feb 26, 2008
220
SDL_RWread(music->rw, data, len, 1);
May 9, 2006
May 9, 2006
221
222
223
SDL_MixAudio(stream, data, len, wavestream_volume);
SDL_stack_free(data);
}
Oct 21, 1999
Oct 21, 1999
224
225
}
}
Oct 2, 2009
Oct 2, 2009
226
return left;
Oct 21, 1999
Oct 21, 1999
227
228
229
}
/* Stop playback of a stream previously started with WAVStream_Start() */
Feb 12, 2003
Feb 12, 2003
230
void WAVStream_Stop(void)
Oct 21, 1999
Oct 21, 1999
231
{
May 16, 2002
May 16, 2002
232
music = NULL;
Oct 21, 1999
Oct 21, 1999
233
234
235
}
/* Close the given WAV stream */
Feb 12, 2003
Feb 12, 2003
236
void WAVStream_FreeSong(WAVStream *wave)
Oct 21, 1999
Oct 21, 1999
237
238
239
240
{
if ( wave ) {
/* Clean up associated data */
if ( wave->cvt.buf ) {
Jan 13, 2012
Jan 13, 2012
241
SDL_free(wave->cvt.buf);
Oct 21, 1999
Oct 21, 1999
242
}
Dec 31, 2011
Dec 31, 2011
243
244
245
if ( wave->freerw ) {
SDL_RWclose(wave->rw);
}
Jan 13, 2012
Jan 13, 2012
246
SDL_free(wave);
Oct 21, 1999
Oct 21, 1999
247
248
249
250
}
}
/* Return non-zero if a stream is currently playing */
Feb 12, 2003
Feb 12, 2003
251
int WAVStream_Active(void)
Oct 21, 1999
Oct 21, 1999
252
253
254
255
{
int active;
active = 0;
Feb 26, 2008
Feb 26, 2008
256
if ( music && (SDL_RWtell(music->rw) < music->stop) ) {
Oct 21, 1999
Oct 21, 1999
257
258
259
260
261
262
263
264
265
266
active = 1;
}
return(active);
}
static int ReadChunk(SDL_RWops *src, Chunk *chunk, int read_data)
{
chunk->magic = SDL_ReadLE32(src);
chunk->length = SDL_ReadLE32(src);
if ( read_data ) {
Jan 13, 2012
Jan 13, 2012
267
chunk->data = (Uint8 *)SDL_malloc(chunk->length);
Oct 21, 1999
Oct 21, 1999
268
if ( chunk->data == NULL ) {
Nov 30, 2001
Nov 30, 2001
269
Mix_SetError("Out of memory");
Oct 21, 1999
Oct 21, 1999
270
271
272
return(-1);
}
if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) {
Nov 30, 2001
Nov 30, 2001
273
Mix_SetError("Couldn't read chunk");
Jan 13, 2012
Jan 13, 2012
274
SDL_free(chunk->data);
Oct 21, 1999
Oct 21, 1999
275
276
277
return(-1);
}
} else {
Nov 8, 2009
Nov 8, 2009
278
SDL_RWseek(src, chunk->length, RW_SEEK_CUR);
Oct 21, 1999
Oct 21, 1999
279
280
281
282
}
return(chunk->length);
}
Feb 26, 2008
Feb 26, 2008
283
static SDL_RWops *LoadWAVStream (SDL_RWops *src, SDL_AudioSpec *spec,
Oct 21, 1999
Oct 21, 1999
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
long *start, long *stop)
{
int was_error;
Chunk chunk;
int lenread;
/* WAV magic header */
Uint32 RIFFchunk;
Uint32 wavelen;
Uint32 WAVEmagic;
/* FMT chunk */
WaveFMT *format = NULL;
was_error = 0;
Dec 27, 1999
Dec 27, 1999
299
Oct 21, 1999
Oct 21, 1999
300
301
302
303
304
/* Check the magic header */
RIFFchunk = SDL_ReadLE32(src);
wavelen = SDL_ReadLE32(src);
WAVEmagic = SDL_ReadLE32(src);
if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) {
Nov 30, 2001
Nov 30, 2001
305
Mix_SetError("Unrecognized file type (not WAVE)");
Oct 21, 1999
Oct 21, 1999
306
307
308
309
310
311
312
313
314
was_error = 1;
goto done;
}
/* Read the audio data format chunk */
chunk.data = NULL;
do {
/* FIXME! Add this logic to SDL_LoadWAV_RW() */
if ( chunk.data ) {
Jan 13, 2012
Jan 13, 2012
315
SDL_free(chunk.data);
Oct 21, 1999
Oct 21, 1999
316
317
318
319
320
321
322
323
324
325
326
}
lenread = ReadChunk(src, &chunk, 1);
if ( lenread < 0 ) {
was_error = 1;
goto done;
}
} while ( (chunk.magic == FACT) || (chunk.magic == LIST) );
/* Decode the audio data format */
format = (WaveFMT *)chunk.data;
if ( chunk.magic != FMT ) {
Jan 13, 2012
Jan 13, 2012
327
SDL_free(chunk.data);
Nov 30, 2001
Nov 30, 2001
328
Mix_SetError("Complex WAVE files not supported");
Oct 21, 1999
Oct 21, 1999
329
330
331
332
333
334
335
336
was_error = 1;
goto done;
}
switch (SDL_SwapLE16(format->encoding)) {
case PCM_CODE:
/* We can understand this */
break;
default:
Nov 30, 2001
Nov 30, 2001
337
Mix_SetError("Unknown WAVE data format");
Oct 21, 1999
Oct 21, 1999
338
339
340
341
342
343
344
345
346
347
348
349
350
was_error = 1;
goto done;
}
memset(spec, 0, (sizeof *spec));
spec->freq = SDL_SwapLE32(format->frequency);
switch (SDL_SwapLE16(format->bitspersample)) {
case 8:
spec->format = AUDIO_U8;
break;
case 16:
spec->format = AUDIO_S16;
break;
default:
Nov 30, 2001
Nov 30, 2001
351
Mix_SetError("Unknown PCM data format");
Oct 21, 1999
Oct 21, 1999
352
353
354
was_error = 1;
goto done;
}
Feb 1, 2000
Feb 1, 2000
355
spec->channels = (Uint8) SDL_SwapLE16(format->channels);
Oct 21, 1999
Oct 21, 1999
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
spec->samples = 4096; /* Good default buffer size */
/* Set the file offset to the DATA chunk data */
chunk.data = NULL;
do {
*start = SDL_RWtell(src) + 2*sizeof(Uint32);
lenread = ReadChunk(src, &chunk, 0);
if ( lenread < 0 ) {
was_error = 1;
goto done;
}
} while ( chunk.magic != DATA );
*stop = SDL_RWtell(src);
done:
if ( format != NULL ) {
Jan 13, 2012
Jan 13, 2012
372
SDL_free(format);
Oct 21, 1999
Oct 21, 1999
373
374
}
if ( was_error ) {
Feb 26, 2008
Feb 26, 2008
375
return NULL;
Oct 21, 1999
Oct 21, 1999
376
}
Feb 26, 2008
Feb 26, 2008
377
return(src);
Oct 21, 1999
Oct 21, 1999
378
379
}
Aug 19, 2001
Aug 19, 2001
380
381
382
383
384
/* I couldn't get SANE_to_double() to work, so I stole this from libsndfile.
* I don't pretend to fully understand it.
*/
static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
Oct 21, 1999
Oct 21, 1999
385
{
Aug 19, 2001
Aug 19, 2001
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/* Negative number? */
if (sanebuf[0] & 0x80)
return 0;
/* Less than 1? */
if (sanebuf[0] <= 0x3F)
return 1;
/* Way too big? */
if (sanebuf[0] > 0x40)
return 0x4000000;
/* Still too big? */
if (sanebuf[0] == 0x40 && sanebuf[1] > 0x1C)
return 800000000;
return ((sanebuf[2] << 23) | (sanebuf[3] << 15) | (sanebuf[4] << 7)
| (sanebuf[5] >> 1)) >> (29 - sanebuf[1]);
Oct 21, 1999
Oct 21, 1999
404
405
}
Feb 26, 2008
Feb 26, 2008
406
static SDL_RWops *LoadAIFFStream (SDL_RWops *src, SDL_AudioSpec *spec,
Oct 21, 1999
Oct 21, 1999
407
408
409
long *start, long *stop)
{
int was_error;
Aug 19, 2001
Aug 19, 2001
410
411
int found_SSND;
int found_COMM;
Oct 21, 1999
Oct 21, 1999
412
Aug 19, 2001
Aug 19, 2001
413
414
415
416
Uint32 chunk_type;
Uint32 chunk_length;
long next_chunk;
Oct 21, 1999
Oct 21, 1999
417
418
419
420
421
422
423
/* AIFF magic header */
Uint32 FORMchunk;
Uint32 AIFFmagic;
/* SSND chunk */
Uint32 offset;
Uint32 blocksize;
/* COMM format chunk */
Dec 17, 2001
Dec 17, 2001
424
425
426
Uint16 channels = 0;
Uint32 numsamples = 0;
Uint16 samplesize = 0;
Aug 19, 2001
Aug 19, 2001
427
Uint8 sane_freq[10];
Dec 17, 2001
Dec 17, 2001
428
Uint32 frequency = 0;
Oct 21, 1999
Oct 21, 1999
429
430
was_error = 0;
Dec 27, 1999
Dec 27, 1999
431
Oct 21, 1999
Oct 21, 1999
432
433
/* Check the magic header */
FORMchunk = SDL_ReadLE32(src);
Aug 19, 2001
Aug 19, 2001
434
chunk_length = SDL_ReadBE32(src);
Oct 21, 1999
Oct 21, 1999
435
436
AIFFmagic = SDL_ReadLE32(src);
if ( (FORMchunk != FORM) || (AIFFmagic != AIFF) ) {
Nov 30, 2001
Nov 30, 2001
437
Mix_SetError("Unrecognized file type (not AIFF)");
Oct 21, 1999
Oct 21, 1999
438
439
440
441
was_error = 1;
goto done;
}
Aug 19, 2001
Aug 19, 2001
442
443
/* From what I understand of the specification, chunks may appear in
* any order, and we should just ignore unknown ones.
Sep 6, 2001
Sep 6, 2001
444
445
446
*
* TODO: Better sanity-checking. E.g. what happens if the AIFF file
* contains compressed sound data?
Aug 19, 2001
Aug 19, 2001
447
*/
Oct 21, 1999
Oct 21, 1999
448
Aug 19, 2001
Aug 19, 2001
449
450
found_SSND = 0;
found_COMM = 0;
Oct 21, 1999
Oct 21, 1999
451
Aug 19, 2001
Aug 19, 2001
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
do {
chunk_type = SDL_ReadLE32(src);
chunk_length = SDL_ReadBE32(src);
next_chunk = SDL_RWtell(src) + chunk_length;
/* Paranoia to avoid infinite loops */
if (chunk_length == 0)
break;
switch (chunk_type) {
case SSND:
found_SSND = 1;
offset = SDL_ReadBE32(src);
blocksize = SDL_ReadBE32(src);
*start = SDL_RWtell(src) + offset;
break;
case COMM:
found_COMM = 1;
/* Read the audio data format chunk */
channels = SDL_ReadBE16(src);
numsamples = SDL_ReadBE32(src);
samplesize = SDL_ReadBE16(src);
SDL_RWread(src, sane_freq, sizeof(sane_freq), 1);
frequency = SANE_to_Uint32(sane_freq);
break;
default:
break;
}
} while ((!found_SSND || !found_COMM)
Nov 8, 2009
Nov 8, 2009
484
&& SDL_RWseek(src, next_chunk, RW_SEEK_SET) != -1);
Aug 19, 2001
Aug 19, 2001
485
486
if (!found_SSND) {
Nov 30, 2001
Nov 30, 2001
487
Mix_SetError("Bad AIFF file (no SSND chunk)");
Aug 19, 2001
Aug 19, 2001
488
489
490
491
492
was_error = 1;
goto done;
}
if (!found_COMM) {
Nov 30, 2001
Nov 30, 2001
493
Mix_SetError("Bad AIFF file (no COMM chunk)");
Aug 19, 2001
Aug 19, 2001
494
495
was_error = 1;
goto done;
Oct 21, 1999
Oct 21, 1999
496
}
Aug 19, 2001
Aug 19, 2001
497
Sep 6, 2001
Sep 6, 2001
498
*stop = *start + channels * numsamples * (samplesize / 8);
Oct 21, 1999
Oct 21, 1999
499
500
501
502
503
504
/* Decode the audio data format */
memset(spec, 0, (sizeof *spec));
spec->freq = frequency;
switch (samplesize) {
case 8:
Sep 6, 2001
Sep 6, 2001
505
spec->format = AUDIO_S8;
Oct 21, 1999
Oct 21, 1999
506
507
break;
case 16:
Aug 19, 2001
Aug 19, 2001
508
spec->format = AUDIO_S16MSB;
Oct 21, 1999
Oct 21, 1999
509
510
break;
default:
Nov 30, 2001
Nov 30, 2001
511
Mix_SetError("Unknown samplesize in data format");
Oct 21, 1999
Oct 21, 1999
512
513
514
was_error = 1;
goto done;
}
Feb 1, 2000
Feb 1, 2000
515
spec->channels = (Uint8) channels;
Oct 21, 1999
Oct 21, 1999
516
517
518
519
spec->samples = 4096; /* Good default buffer size */
done:
if ( was_error ) {
Feb 26, 2008
Feb 26, 2008
520
return NULL;
Oct 21, 1999
Oct 21, 1999
521
}
Feb 26, 2008
Feb 26, 2008
522
return(src);
Oct 21, 1999
Oct 21, 1999
523
}