dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / audio / include / Resample.h
blobd78792b0b39461fd4de1ebd7f619f008c6f68f28
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _MULTIMEDIA_RESAMPLE_H
28 #define _MULTIMEDIA_RESAMPLE_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * To convert the sampling rate of fi of input signal to fo of output signal,
34 * the least common multiple fm = L * fi = M * fo needs to be derived first.
35 * Then the input signal is
36 * 1) up-sampled to fm by inserting (L - 1) zero-valued samples after each
37 * input sample,
38 * 2) low-pass filtered to half of the lower of fi and fo, and
39 * 3) down-sampled to fo by saving one out of every M samples.
41 * The low-pass filter is implemented with an FIR filter which is a truncated
42 * ideal low pass filter whose order is dependent on its bandwidth.
44 * Refer to Fir.h for explanations of filter() and flush().
47 #include <Fir.h>
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 class ResampleFilter : public Fir {
54 int num_state; // interpolation requires less states
55 int up; // upsampling ratio
56 int down; // down sampling ratio
57 int down_offset; // 0 <= index in down-sampling < down
58 int up_offset; // -up < index in up_sampling <= 0
60 void updateState(double *in, int size);
62 // if fi is a multiple of fo, LP filtering followed by down_sampling
63 int decimate_noadjust(short *in, int size, short *out);
64 int decimate_flush(short *);
65 int decimate(short *in, int size, short *out);
67 // if fo is a multiple of fi, up-sampling followed by LP filtering
68 int interpolate_noadjust(short *in, int size, short *out);
69 int interpolate_flush(short *);
70 int interpolate(short *in, int size, short *out);
72 int flush(short *out);
74 public:
75 ResampleFilter(int rate_in, int rate_out);
76 virtual int filter_noadjust(short *in, int size, short *out);
77 virtual int filter(short *in, int size, short *out);
78 virtual int getFlushSize(void);
81 #ifdef __cplusplus
83 #endif
85 #endif /* !_MULTIMEDIA_RESAMPLE_H */