xref: /illumos-gate/usr/src/cmd/audio/include/AudioGain.h (revision 826ac02a0def83e0a41b29321470d299c7389aab)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1993-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIOGAIN_H
28 #define	_MULTIMEDIA_AUDIOGAIN_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <AudioTypePcm.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // Class to handle gain calculations
39 
40 // Define bits for AudioGain::Process() type argument
41 #define	AUDIO_GAIN_INSTANT	(1)		// Gain for level meter
42 #define	AUDIO_GAIN_WEIGHTED	(2)		// Gain for agc
43 
44 
45 class AudioGain {
46 protected:
47 
48 static const double	LoSigInstantRange;	// normalization constants
49 static const double	HiSigInstantRange;
50 static const double	NoSigWeight;
51 static const double	LoSigWeightRange;
52 static const double	HiSigWeightRange;
53 static const double	PeakSig;
54 static const double	DCtimeconstant;		// DC offset time constant
55 
56 	AudioTypePcm	float_convert;		// used in signal processing
57 	unsigned	clipcnt;		// clip counter
58 	Double		DCaverage;		// weighted DC offset
59 	Double		instant_gain;		// current (instantaneous) gain
60 	Double		weighted_peaksum;	// peak weighted sum
61 	Double		weighted_sum;		// running sum of squares
62 	Double		weighted_avgsum;	// accumulated sums to averages
63 	unsigned	weighted_cnt;		// number of sums to average
64 	double		*gain_cache;		// weighted gains
65 	Double		gain_cache_size;	// number of cached gains
66 
67 protected:
68 	// Internal processing methods
69 
70 	// filter DC bias
71 	virtual void process_dcfilter(
72 	    AudioBuffer*);
73 	// calculate instant gain
74 	virtual void process_instant(
75 	    AudioBuffer*);
76 	// calculate weighted gain
77 	virtual void process_weighted(
78 	    AudioBuffer*);
79 
80 public:
81 		AudioGain();			// Constructor
82 	virtual	~AudioGain();			// Destructor
83 
84 	// TRUE if conversion ok
85 	virtual Boolean CanConvert(
86 	    const AudioHdr&) const;	// type to check against
87 
88 	// Process new audio data
89 	virtual AudioError Process(
90 	    AudioBuffer*, int);		// buffer destroyed if not referenced!
91 	virtual double InstantGain();	// Get most recent gain
92 	virtual double WeightedGain();	// Get current weighted gain
93 	virtual double WeightedPeak();	// Get peak weighted gain
94 	virtual Boolean Clipped();	// TRUE if peak since last check
95 	virtual void Flush();		// Reset state
96 };
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* !_MULTIMEDIA_AUDIOGAIN_H */
103