annotate decoders/skeleton.c @ 68:0b53ace8b875

Initial add.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 25 Sep 2001 15:46:48 +0000
parents 40006625142a
children 6d9fdec2f708
rev   line source
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
3efbcaf36fec 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.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * FMT decoder for SDL_sound.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles FMT audio data. Blahblahblah... The author should
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * have done a search and replace on "fmt" and "FMT" and changed this
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * comment. This is the default comment in the skeleton decoder file...
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * Please see the file LICENSE in the source's root directory.
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 *
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
64
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
32 #ifdef SOUND_SUPPORTS_FMT
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
33
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <stdio.h>
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <stdlib.h>
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <string.h>
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <assert.h>
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include "SDL_sound.h"
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #define __SDL_SOUND_INTERNAL__
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include "SDL_sound_internal.h"
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
44 static int FMT_init(void);
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
45 static void FMT_quit(void);
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 static int FMT_open(Sound_Sample *sample, const char *ext);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 static void FMT_close(Sound_Sample *sample);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 static Uint32 FMT_read(Sound_Sample *sample);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT =
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 {
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 {
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 "FMT",
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 "FMT audio format description",
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 "Ryan C. Gordon <icculus@clutteredmind.org>",
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 "http://www.icculus.org/SDL_sound/"
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 },
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
59 FMT_init, /* init() method */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
60 FMT_quit, /* quit() method */
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 FMT_open, /* open() method */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 FMT_close, /* close() method */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 FMT_read /* read() method */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 };
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
67 static int FMT_init(void)
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
68 {
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
69 /* do any global decoder/library initialization you need here. */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
70
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
71 return(1); /* initialization successful. */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
72 } /* FMT_init */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
73
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
74
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
75 static void FMT_quit(void)
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
76 {
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
77 /* do any global decoder/library cleanup you need here. */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
78 } /* FMT_quit */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
79
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
80
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 static int FMT_open(Sound_Sample *sample, const char *ext)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 {
21
d9b9d60cf9a9 Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents: 16
diff changeset
83 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
d9b9d60cf9a9 Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents: 16
diff changeset
84 SDL_RWops *rw = internal->rw;
d9b9d60cf9a9 Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents: 16
diff changeset
85
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 if (can NOT accept the data)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 {
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 Sound_SetError("FMT: expected X, got Y.");
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 return(0);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 } /* if */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
92 SNDDBG(("FMT: Accepting data stream.\n"));
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 set up sample->actual;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 sample->flags = SOUND_SAMPLEFLAG_NONE;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 return(1); /* we'll handle this data. */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 } /* FMT_open */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 static void FMT_close(Sound_Sample *sample)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 {
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 clean up anything you put into internal->decoder_private;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 } /* FMT_close */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 static Uint32 FMT_read(Sound_Sample *sample)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 {
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 Uint32 retval;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 /*
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 * We don't actually do any decoding, so we read the fmt data
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 * directly into the internal buffer...
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 retval = SDL_RWread(internal->rw, internal->buffer,
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 1, internal->buffer_size);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 (or whatever. Do some decoding here...)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 /* Make sure the read went smoothly... */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 if (retval == 0)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 sample->flags |= SOUND_SAMPLEFLAG_EOF;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 else if (retval == -1)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 /* (next call this EAGAIN may turn into an EOF or error.) */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 else if (retval < internal->buffer_size)
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 (or whatever. retval == number of bytes you put in internal->buffer).
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 return(retval);
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 } /* FMT_read */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
64
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
136 #endif /* SOUND_SUPPORTS_FMT */
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
137
16
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 /* end of fmt.c ... */
3efbcaf36fec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140