comparison decoders/skeleton.c @ 16:3efbcaf36fec

Initial add.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 19 Sep 2001 06:24:58 +0000
parents
children d9b9d60cf9a9
comparison
equal deleted inserted replaced
15:4368fdb091b1 16:3efbcaf36fec
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 * FMT decoder for SDL_sound.
22 *
23 * This driver handles FMT audio data. Blahblahblah... The author should
24 * have done a search and replace on "fmt" and "FMT" and changed this
25 * comment. This is the default comment in the skeleton decoder file...
26 *
27 * Please see the file LICENSE in the source's root directory.
28 *
29 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <assert.h>
36 #include "SDL_sound.h"
37
38 #define __SDL_SOUND_INTERNAL__
39 #include "SDL_sound_internal.h"
40
41 #if (!defined SOUND_SUPPORTS_FMT)
42 #error SOUND_SUPPORTS_FMT must be defined.
43 #endif
44
45
46 static int FMT_open(Sound_Sample *sample, const char *ext);
47 static void FMT_close(Sound_Sample *sample);
48 static Uint32 FMT_read(Sound_Sample *sample);
49
50 const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT =
51 {
52 {
53 "FMT",
54 "FMT audio format description",
55 "Ryan C. Gordon <icculus@clutteredmind.org>",
56 "http://www.icculus.org/SDL_sound/"
57 },
58
59 FMT_open, /* open() method */
60 FMT_close, /* close() method */
61 FMT_read /* read() method */
62 };
63
64
65 static int FMT_open(Sound_Sample *sample, const char *ext)
66 {
67 if (can NOT accept the data)
68 {
69 Sound_SetError("FMT: expected X, got Y.");
70 return(0);
71 } /* if */
72
73 _D(("FMT: Accepting data stream.\n"));
74 set up sample->actual;
75 sample->flags = SOUND_SAMPLEFLAG_NONE;
76 return(1); /* we'll handle this data. */
77 } /* FMT_open */
78
79
80 static void FMT_close(Sound_Sample *sample)
81 {
82 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
83 clean up anything you put into internal->decoder_private;
84 } /* FMT_close */
85
86
87 static Uint32 FMT_read(Sound_Sample *sample)
88 {
89 Uint32 retval;
90 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
91
92 /*
93 * We don't actually do any decoding, so we read the fmt data
94 * directly into the internal buffer...
95 */
96 retval = SDL_RWread(internal->rw, internal->buffer,
97 1, internal->buffer_size);
98
99 (or whatever. Do some decoding here...)
100
101 /* Make sure the read went smoothly... */
102 if (retval == 0)
103 sample->flags |= SOUND_SAMPLEFLAG_EOF;
104
105 else if (retval == -1)
106 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
107
108 /* (next call this EAGAIN may turn into an EOF or error.) */
109 else if (retval < internal->buffer_size)
110 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
111
112 (or whatever. retval == number of bytes you put in internal->buffer).
113
114 return(retval);
115 } /* FMT_read */
116
117
118 /* end of fmt.c ... */
119