feeder.c (52713) | feeder.c (53205) |
---|---|
1/* 2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/dev/sound/pcm/feeder.c 52713 1999-10-31 08:58:51Z tanimura $ | 26 * $FreeBSD: head/sys/dev/sound/pcm/feeder.c 53205 1999-11-15 23:57:33Z cg $ |
27 */ 28 29#include <dev/pcm/sound.h> 30 31static int chn_addfeeder(pcm_channel *c, pcm_feeder *f); 32static int chn_removefeeder(pcm_channel *c); 33 34#define FEEDBUFSZ 8192 --- 66 unchanged lines hidden (view full) --- 101 133, 133, 133, 133, 132, 132, 132, 132, 102 131, 131, 131, 131, 130, 130, 130, 130, 103 129, 129, 129, 129, 128, 128, 128, 128, 104}; 105 106/*****************************************************************************/ 107 108static int | 27 */ 28 29#include <dev/pcm/sound.h> 30 31static int chn_addfeeder(pcm_channel *c, pcm_feeder *f); 32static int chn_removefeeder(pcm_channel *c); 33 34#define FEEDBUFSZ 8192 --- 66 unchanged lines hidden (view full) --- 101 133, 133, 133, 133, 132, 132, 132, 132, 102 131, 131, 131, 131, 130, 130, 130, 130, 103 129, 129, 129, 129, 128, 128, 128, 128, 104}; 105 106/*****************************************************************************/ 107 108static int |
109feed_root(pcm_feeder *feeder, u_int8_t *buffer, u_int32_t count, struct uio *stream) | 109feed_root(pcm_feeder *feeder, pcm_channel *ch, u_int8_t *buffer, u_int32_t count, struct uio *stream) |
110{ 111 int ret, tmp = 0, c = 0; 112 if (!count) panic("feed_root: count == 0"); | 110{ 111 int ret, tmp = 0, c = 0; 112 if (!count) panic("feed_root: count == 0"); |
113 count &= ~((1 << ch->align) - 1); 114 if (!count) panic("feed_root: aligned count == 0"); 115 if (ch->smegcnt > 0) { 116 c = min(ch->smegcnt, count); 117 bcopy(ch->smegbuf, buffer, c); 118 ch->smegcnt -= c; 119 } |
|
113 while ((stream->uio_resid > 0) && (c < count)) { 114 tmp = stream->uio_resid; 115 ret = uiomove(buffer + c, count - c, stream); 116 if (ret) panic("feed_root: uiomove failed"); 117 tmp -= stream->uio_resid; 118 c += tmp; 119 } 120 if (!c) panic("feed_root: uiomove didn't"); 121 return c; 122} 123pcm_feeder feeder_root = { "root", 0, NULL, NULL, feed_root }; 124 125/*****************************************************************************/ 126 127static int | 120 while ((stream->uio_resid > 0) && (c < count)) { 121 tmp = stream->uio_resid; 122 ret = uiomove(buffer + c, count - c, stream); 123 if (ret) panic("feed_root: uiomove failed"); 124 tmp -= stream->uio_resid; 125 c += tmp; 126 } 127 if (!c) panic("feed_root: uiomove didn't"); 128 return c; 129} 130pcm_feeder feeder_root = { "root", 0, NULL, NULL, feed_root }; 131 132/*****************************************************************************/ 133 134static int |
128feed_8to16(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 135feed_8to16(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
129{ 130 int i, j, k; | 136{ 137 int i, j, k; |
131 k = f->source->feed(f->source, b, count / 2, stream); | 138 k = f->source->feed(f->source, c, b, count / 2, stream); |
132 j = k - 1; 133 i = j * 2 + 1; 134 while (i > 0 && j >= 0) { 135 b[i--] = b[j--]; 136 b[i--] = 0; 137 } 138 return k * 2; 139} --- 12 unchanged lines hidden (view full) --- 152feed_16to8_free(pcm_feeder *f) 153{ 154 if (f->data) free(f->data, M_DEVBUF); 155 f->data = NULL; 156 return 0; 157} 158 159static int | 139 j = k - 1; 140 i = j * 2 + 1; 141 while (i > 0 && j >= 0) { 142 b[i--] = b[j--]; 143 b[i--] = 0; 144 } 145 return k * 2; 146} --- 12 unchanged lines hidden (view full) --- 159feed_16to8_free(pcm_feeder *f) 160{ 161 if (f->data) free(f->data, M_DEVBUF); 162 f->data = NULL; 163 return 0; 164} 165 166static int |
160feed_16to8le(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 167feed_16to8le(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
161{ 162 u_int32_t i = 0, toget = count * 2; 163 int j = 1, k; | 168{ 169 u_int32_t i = 0, toget = count * 2; 170 int j = 1, k; |
164 k = f->source->feed(f->source, f->data, min(toget, FEEDBUFSZ), stream); | 171 k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); |
165 while (j < k) { 166 b[i++] = ((u_int8_t *)f->data)[j]; 167 j += 2; 168 } 169 return i; 170} 171static pcm_feeder feeder_16to8le = 172 { "16to8le", 1, feed_16to8_init, feed_16to8_free, feed_16to8le }; 173 174/*****************************************************************************/ 175 176static int | 172 while (j < k) { 173 b[i++] = ((u_int8_t *)f->data)[j]; 174 j += 2; 175 } 176 return i; 177} 178static pcm_feeder feeder_16to8le = 179 { "16to8le", 1, feed_16to8_init, feed_16to8_free, feed_16to8le }; 180 181/*****************************************************************************/ 182 183static int |
177feed_monotostereo8(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 184feed_monotostereo8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
178{ | 185{ |
179 int i, j, k = f->source->feed(f->source, b, count / 2, stream); | 186 int i, j, k = f->source->feed(f->source, c, b, count / 2, stream); |
180 j = k - 1; 181 i = j * 2 + 1; 182 while (i > 0 && j >= 0) { 183 b[i--] = b[j]; 184 b[i--] = b[j]; 185 j--; 186 } 187 return k * 2; --- 14 unchanged lines hidden (view full) --- 202feed_stereotomono8_free(pcm_feeder *f) 203{ 204 if (f->data) free(f->data, M_DEVBUF); 205 f->data = NULL; 206 return 0; 207} 208 209static int | 187 j = k - 1; 188 i = j * 2 + 1; 189 while (i > 0 && j >= 0) { 190 b[i--] = b[j]; 191 b[i--] = b[j]; 192 j--; 193 } 194 return k * 2; --- 14 unchanged lines hidden (view full) --- 209feed_stereotomono8_free(pcm_feeder *f) 210{ 211 if (f->data) free(f->data, M_DEVBUF); 212 f->data = NULL; 213 return 0; 214} 215 216static int |
210feed_stereotomono8(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 217feed_stereotomono8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
211{ 212 u_int32_t i = 0, toget = count * 2; 213 int j = 0, k; | 218{ 219 u_int32_t i = 0, toget = count * 2; 220 int j = 0, k; |
214 k = f->source->feed(f->source, f->data, min(toget, FEEDBUFSZ), stream); | 221 k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); |
215 while (j < k) { 216 b[i++] = ((u_int8_t *)f->data)[j]; 217 j += 2; 218 } 219 return i; 220} 221static pcm_feeder feeder_stereotomono8 = 222 { "stereotomono8", 1, feed_stereotomono8_init, feed_stereotomono8_free, 223 feed_stereotomono8 }; 224 225/*****************************************************************************/ 226 227static int | 222 while (j < k) { 223 b[i++] = ((u_int8_t *)f->data)[j]; 224 j += 2; 225 } 226 return i; 227} 228static pcm_feeder feeder_stereotomono8 = 229 { "stereotomono8", 1, feed_stereotomono8_init, feed_stereotomono8_free, 230 feed_stereotomono8 }; 231 232/*****************************************************************************/ 233 234static int |
228feed_endian(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 235feed_endian(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
229{ 230 u_int8_t t; | 236{ 237 u_int8_t t; |
231 int i = 0, j = f->source->feed(f->source, b, count, stream); | 238 int i = 0, j = f->source->feed(f->source, c, b, count, stream); |
232 while (i < j) { 233 t = b[i]; 234 b[i] = b[i + 1]; 235 b[i + 1] = t; 236 i += 2; 237 } 238 return i; 239} 240static pcm_feeder feeder_endian = { "endian", -1, NULL, NULL, feed_endian }; 241 242/*****************************************************************************/ 243 244static int | 239 while (i < j) { 240 t = b[i]; 241 b[i] = b[i + 1]; 242 b[i + 1] = t; 243 i += 2; 244 } 245 return i; 246} 247static pcm_feeder feeder_endian = { "endian", -1, NULL, NULL, feed_endian }; 248 249/*****************************************************************************/ 250 251static int |
245feed_sign(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 252feed_sign(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
246{ | 253{ |
247 int i = 0, j = f->source->feed(f->source, b, count, stream); | 254 int i = 0, j = f->source->feed(f->source, c, b, count, stream); |
248 int ssz = (int)f->data, ofs = ssz - 1; 249 while (i < j) { 250 b[i + ofs] ^= 0x80; 251 i += ssz; 252 } 253 return i; 254} 255static pcm_feeder feeder_sign8 = 256 { "sign8", 0, NULL, NULL, feed_sign, (void *)1 }; 257static pcm_feeder feeder_sign16 = 258 { "sign16", -1, NULL, NULL, feed_sign, (void *)2 }; 259 260/*****************************************************************************/ 261 262static int | 255 int ssz = (int)f->data, ofs = ssz - 1; 256 while (i < j) { 257 b[i + ofs] ^= 0x80; 258 i += ssz; 259 } 260 return i; 261} 262static pcm_feeder feeder_sign8 = 263 { "sign8", 0, NULL, NULL, feed_sign, (void *)1 }; 264static pcm_feeder feeder_sign16 = 265 { "sign16", -1, NULL, NULL, feed_sign, (void *)2 }; 266 267/*****************************************************************************/ 268 269static int |
263feed_table(pcm_feeder *f, u_int8_t *b, u_int32_t count, struct uio *stream) | 270feed_table(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) |
264{ | 271{ |
265 int i = 0, j = f->source->feed(f->source, b, count, stream); | 272 int i = 0, j = f->source->feed(f->source, c, b, count, stream); |
266 while (i < j) { 267 b[i] = ((u_int8_t *)f->data)[b[i]]; 268 i++; 269 } 270 return i; 271} 272static pcm_feeder feeder_ulawtou8 = 273 { "ulawtou8", 0, NULL, NULL, feed_table, ulaw_to_u8 }; --- 136 unchanged lines hidden --- | 273 while (i < j) { 274 b[i] = ((u_int8_t *)f->data)[b[i]]; 275 i++; 276 } 277 return i; 278} 279static pcm_feeder feeder_ulawtou8 = 280 { "ulawtou8", 0, NULL, NULL, feed_table, ulaw_to_u8 }; --- 136 unchanged lines hidden --- |