Deleted Added
full compact
feeder_rate.c (110108) feeder_rate.c (110466)
1/*
2 * Copyright (c) 2003 Orion Hodson <orion@freebsd.org>
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

--- 34 unchanged lines hidden (view full) ---

43 * testing revisions.
44 */
45
46#ifdef _KERNEL
47
48#include <dev/sound/pcm/sound.h>
49#include "feeder_if.h"
50
1/*
2 * Copyright (c) 2003 Orion Hodson <orion@freebsd.org>
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

--- 34 unchanged lines hidden (view full) ---

43 * testing revisions.
44 */
45
46#ifdef _KERNEL
47
48#include <dev/sound/pcm/sound.h>
49#include "feeder_if.h"
50
51SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/feeder_rate.c 110108 2003-01-30 16:32:56Z orion $");
51SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/feeder_rate.c 110466 2003-02-06 17:32:02Z orion $");
52
53#endif /* _KERNEL */
54
52MALLOC_DEFINE(M_RATEFEEDER, "ratefeed", "pcm rate feeder");
53
55MALLOC_DEFINE(M_RATEFEEDER, "ratefeed", "pcm rate feeder");
56
54#define RATE_ASSERT(x, y) /* KASSERT(x,y) */
55#define RATE_TRACE(x...) /* printf(x) */
57#ifndef RATE_ASSERT
58#define RATE_ASSERT(x, y) /* KASSERT(x) */
59#endif /* RATE_ASSERT */
56
60
57#endif /* _KERNEL */
61#ifndef RATE_TRACE
62#define RATE_TRACE(x...) /* printf(x) */
63#endif
58
59/*****************************************************************************/
64
65/*****************************************************************************/
60/* All of the following coefficients are coupled. They are chosen to be
61 * good in the operating space 4000-96000kHz work. Decreasing the
62 * granularity increases the required buffer size and affects the gain
63 * values at different points in the space. These values were found by
64 * running the test program with -p (probe) and some trial and error.
66
67/* The following coefficients are coupled. They are chosen to be
68 * guarantee calculable factors for the interpolation routine. They
69 * have been tested over the range of RATEMIN-RATEMAX Hz. Decreasing
70 * the granularity increases the required buffer size and affects the
71 * gain values at different points in the space. These values were
72 * found by running the test program with -p (probe) and some trial
73 * and error.
65 *
66 * ROUNDHZ the granularity of sample rates (fits n*11025 and n*8000).
67 * FEEDBUFSZ the amount of buffer space.
68 * MINGAIN the minimum acceptable gain in coefficients search.
69 */
70#define ROUNDHZ 25
74 *
75 * ROUNDHZ the granularity of sample rates (fits n*11025 and n*8000).
76 * FEEDBUFSZ the amount of buffer space.
77 * MINGAIN the minimum acceptable gain in coefficients search.
78 */
79#define ROUNDHZ 25
71#define FEEDBUFSZ 8192
80#define FEEDBUFSZ 8192
72#define MINGAIN 92
73
81#define MINGAIN 92
82
74#define RATEMIN 4000
75#define RATEMAX 96000
83#define RATEMIN 4000
84#define RATEMAX 48000
76
77struct feed_rate_info;
78
79typedef int (*rate_convert_method)(struct feed_rate_info *,
80 uint32_t, uint32_t, int16_t *);
81
82static int
83convert_stereo_up(struct feed_rate_info *info,

--- 342 unchanged lines hidden (view full) ---

426 d_ticks = info->convert(info, s_ticks, d_ticks,
427 (int16_t*)(b + done));
428 if (d_ticks == 0)
429 break;
430 done += d_ticks * bytes_per_tick(info);
431
432 RATE_ASSERT(info->buffer_pos <= info->buffer_ticks,
433 ("%s: buffer_ticks too big\n", __func__));
85
86struct feed_rate_info;
87
88typedef int (*rate_convert_method)(struct feed_rate_info *,
89 uint32_t, uint32_t, int16_t *);
90
91static int
92convert_stereo_up(struct feed_rate_info *info,

--- 342 unchanged lines hidden (view full) ---

435 d_ticks = info->convert(info, s_ticks, d_ticks,
436 (int16_t*)(b + done));
437 if (d_ticks == 0)
438 break;
439 done += d_ticks * bytes_per_tick(info);
440
441 RATE_ASSERT(info->buffer_pos <= info->buffer_ticks,
442 ("%s: buffer_ticks too big\n", __func__));
434 RATE_TRACE("%s: ticks %5d pos %d\n", __func__,
435 info->buffer_ticks, info->buffer_pos);
443 RATE_ASSERT(info->buffer_ticks <= src_ticks_per_cycle(info),
444 ("too many ticks %d / %d\n",
445 info->buffer_ticks, src_ticks_per_cycle(info)));
446 RATE_TRACE("%s: ticks %5d / %d pos %d\n", __func__,
447 info->buffer_ticks, src_ticks_per_cycle(info),
448 info->buffer_pos);
436
437 if (src_ticks_per_cycle(info) <= info->buffer_pos) {
438 /* End of cycle reached, copy last samples to start */
439 uint8_t *u8b;
440 u8b = (uint8_t*)info->buffer;
441 bcopy(u8b + src_bytes_per_cycle(info), u8b,
442 bytes_per_tick(info));
443

--- 12 unchanged lines hidden (view full) ---

456
457 if (done != count) {
458 RATE_TRACE("Only did %d of %d\n", done, count);
459 }
460
461 return done;
462}
463
449
450 if (src_ticks_per_cycle(info) <= info->buffer_pos) {
451 /* End of cycle reached, copy last samples to start */
452 uint8_t *u8b;
453 u8b = (uint8_t*)info->buffer;
454 bcopy(u8b + src_bytes_per_cycle(info), u8b,
455 bytes_per_tick(info));
456

--- 12 unchanged lines hidden (view full) ---

469
470 if (done != count) {
471 RATE_TRACE("Only did %d of %d\n", done, count);
472 }
473
474 return done;
475}
476
464#ifdef _KERNEL
465
466static struct pcm_feederdesc feeder_rate_desc[] = {
467 {FEEDER_RATE, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0},
477static struct pcm_feederdesc feeder_rate_desc[] = {
478 {FEEDER_RATE, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0},
468 {0},
479 {0, 0, 0, 0},
469};
470static kobj_method_t feeder_rate_methods[] = {
471 KOBJMETHOD(feeder_init, feed_rate_init),
472 KOBJMETHOD(feeder_free, feed_rate_free),
473 KOBJMETHOD(feeder_set, feed_rate_set),
474 KOBJMETHOD(feeder_get, feed_rate_get),
475 KOBJMETHOD(feeder_feed, feed_rate),
480};
481static kobj_method_t feeder_rate_methods[] = {
482 KOBJMETHOD(feeder_init, feed_rate_init),
483 KOBJMETHOD(feeder_free, feed_rate_free),
484 KOBJMETHOD(feeder_set, feed_rate_set),
485 KOBJMETHOD(feeder_get, feed_rate_get),
486 KOBJMETHOD(feeder_feed, feed_rate),
476 { 0, 0 }
487 {0, 0}
477};
478FEEDER_DECLARE(feeder_rate, 2, NULL);
479
488};
489FEEDER_DECLARE(feeder_rate, 2, NULL);
490
480#endif /* _KERNEL */