comparison decoders/raw.c @ 7:29313c20963d

Updated a lot of comments, and changed read() method's return type.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 18 Sep 2001 10:52:48 +0000
parents 341cea3e13c6
children ea58bc3b15d7
comparison
equal deleted inserted replaced
6:3f214fe4a82f 7:29313c20963d
52 #endif 52 #endif
53 53
54 54
55 static int RAW_open(Sound_Sample *sample, const char *ext); 55 static int RAW_open(Sound_Sample *sample, const char *ext);
56 static void RAW_close(Sound_Sample *sample); 56 static void RAW_close(Sound_Sample *sample);
57 static int RAW_read(Sound_Sample *sample); 57 static Uint32 RAW_read(Sound_Sample *sample);
58 58
59 const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW = 59 const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
60 { 60 {
61 { 61 {
62 "RAW", 62 "RAW",
71 }; 71 };
72 72
73 73
74 static int RAW_open(Sound_Sample *sample, const char *ext) 74 static int RAW_open(Sound_Sample *sample, const char *ext)
75 { 75 {
76 /*
77 * We check this explicitly, since we have no other way to
78 * determine whether we should handle this data or not.
79 */
76 if (__Sound_strcasecmp(ext, "RAW") != 0) 80 if (__Sound_strcasecmp(ext, "RAW") != 0)
81 {
82 Sound_SetError("RAW: extension isn't explicitly \"RAW\".");
77 return(0); 83 return(0);
84 } /* if */
78 85
86 /*
87 * You must also specify a desired format, so we know how to
88 * treat the bits that are otherwise binary garbage.
89 */
79 if ( (sample->desired.channels < 1) || 90 if ( (sample->desired.channels < 1) ||
80 (sample->desired.channels > 2) || 91 (sample->desired.channels > 2) ||
81 (sample->desired.rate == 0) || 92 (sample->desired.rate == 0) ||
82 (sample->desired.format == 0) ) 93 (sample->desired.format == 0) )
83 { 94 {
95 Sound_SetError("RAW: invalid desired format.");
84 return(0); 96 return(0);
85 } /* if */ 97 } /* if */
86 98
99 _D(("RAW: Accepting data stream.\n"));
100
101 /*
102 * We never convert raw samples; what you ask for is what you get.
103 */
87 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); 104 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
88 sample->flags = SOUND_SAMPLEFLAG_NONE; 105 sample->flags = SOUND_SAMPLEFLAG_NONE;
89 return(1); 106
107 return(1); /* we'll handle this data. */
90 } /* RAW_open */ 108 } /* RAW_open */
91 109
92 110
93 static void RAW_close(Sound_Sample *sample) 111 static void RAW_close(Sound_Sample *sample)
94 { 112 {
95 /* we don't allocate anything. That's easy, eh? */ 113 /* we don't allocate anything that we need to free. That's easy, eh? */
96 } /* RAW_close */ 114 } /* RAW_close */
97 115
98 116
99 static int RAW_read(Sound_Sample *sample) 117 static Uint32 RAW_read(Sound_Sample *sample)
100 { 118 {
101 int retval; 119 Uint32 retval;
102 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; 120 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
121
122 /*
123 * We don't actually do any decoding, so we read the raw data
124 * directly into the internal buffer...
125 */
103 retval = SDL_RWread(internal->rw, internal->buffer, 126 retval = SDL_RWread(internal->rw, internal->buffer,
104 1, internal->buffer_size); 127 1, internal->buffer_size);
105 128
129 /* Make sure the read went smoothly... */
106 if (retval == 0) 130 if (retval == 0)
107 sample->flags |= SOUND_SAMPLEFLAG_EOF; 131 sample->flags |= SOUND_SAMPLEFLAG_EOF;
108 132
109 else if (retval == -1) 133 else if (retval == -1)
110 sample->flags |= SOUND_SAMPLEFLAG_ERROR; 134 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
111 135
112 /* next call this may be a EOF or error... */ 136 /* (next call this EAGAIN may turn into an EOF or error.) */
113 else if (retval < internal->buffer_size) 137 else if (retval < internal->buffer_size)
114 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; 138 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
115 139
116 return(retval); 140 return(retval);
117 } /* RAW_read */ 141 } /* RAW_read */