4
|
1 /*
|
|
2 * SDL_sound -- An abstract sound format decoding API.
|
|
3 * Copyright (C) 2001 Ryan C. Gordon.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2.1 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 */
|
|
19
|
|
20 /*
|
|
21 * RAW decoder for SDL_sound. This is as simple as it gets.
|
|
22 *
|
|
23 * This driver handles raw audio data. You must, regardless of where the
|
|
24 * data is actually coming from, specify the string "RAW" in the extension
|
|
25 * parameter of Sound_NewSample() (or, alternately, open a file with the
|
|
26 * extension ".raw" in Sound_NewSampleFromFile()). The string is checked
|
|
27 * case-insensitive. We need this check, because raw data, being raw, has
|
|
28 * no headers or magic number we can use to determine if we should handle a
|
|
29 * given file, so we needed some way to have this "decoder" discriminate.
|
|
30 *
|
|
31 * When calling Sound_NewSample*(), you must also specify a "desired"
|
|
32 * audio format. The "actual" format will always match what you specify, so
|
|
33 * there will be no conversion overhead, but these routines need to know how
|
|
34 * to treat the bits, since it's all random garbage otherwise.
|
|
35 *
|
|
36 * Please see the file LICENSE in the source's root directory.
|
|
37 *
|
|
38 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
|
|
39 */
|
|
40
|
|
41 #include <stdio.h>
|
|
42 #include <stdlib.h>
|
|
43 #include <string.h>
|
|
44 #include <assert.h>
|
|
45 #include "SDL_sound.h"
|
|
46
|
|
47 #define __SDL_SOUND_INTERNAL__
|
|
48 #include "SDL_sound_internal.h"
|
|
49
|
|
50 #if (!defined SOUND_SUPPORTS_RAW)
|
|
51 #error SOUND_SUPPORTS_RAW must be defined.
|
|
52 #endif
|
|
53
|
|
54
|
|
55 static int RAW_open(Sound_Sample *sample, const char *ext);
|
|
56 static void RAW_close(Sound_Sample *sample);
|
|
57 static int RAW_read(Sound_Sample *sample);
|
|
58
|
|
59 const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
|
|
60 {
|
|
61 {
|
|
62 "RAW",
|
|
63 "Raw audio",
|
|
64 "Ryan C. Gordon <icculus@clutteredmind.org>",
|
|
65 "http://www.icculus.org/SDL_sound/"
|
|
66 },
|
|
67
|
|
68 RAW_open, /* open() method */
|
|
69 RAW_close, /* close() method */
|
|
70 RAW_read /* read() method */
|
|
71 };
|
|
72
|
|
73
|
|
74 static int RAW_open(Sound_Sample *sample, const char *ext)
|
|
75 {
|
|
76 if (__Sound_strcasecmp(ext, "RAW") != 0)
|
|
77 return(0);
|
|
78
|
|
79 if ( (sample->desired.channels < 1) ||
|
|
80 (sample->desired.channels > 2) ||
|
|
81 (sample->desired.rate == 0) ||
|
|
82 (sample->desired.format == 0) )
|
|
83 {
|
|
84 return(0);
|
|
85 } /* if */
|
|
86
|
|
87 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
|
|
88 sample->flags = SOUND_SAMPLEFLAG_NONE;
|
|
89 return(1);
|
|
90 } /* RAW_open */
|
|
91
|
|
92
|
|
93 static void RAW_close(Sound_Sample *sample)
|
|
94 {
|
|
95 /* we don't allocate anything. That's easy, eh? */
|
|
96 } /* RAW_close */
|
|
97
|
|
98
|
|
99 static int RAW_read(Sound_Sample *sample)
|
|
100 {
|
|
101 int retval;
|
|
102 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
|
103 retval = SDL_RWread(internal->rw, internal->buffer,
|
|
104 1, internal->buffer_size);
|
|
105
|
|
106 if (retval == 0)
|
|
107 sample->flags |= SOUND_SAMPLEFLAG_EOF;
|
|
108
|
|
109 else if (retval == -1)
|
|
110 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
|
111
|
|
112 /* next call this may be a EOF or error... */
|
|
113 else if (retval < internal->buffer_size)
|
|
114 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
|
|
115
|
|
116 return(retval);
|
|
117 } /* RAW_read */
|
|
118
|
|
119
|
|
120 /* end of raw.c ... */
|
|
121
|