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
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]
23 * Copyright (c) 1993-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _MULTIMEDIA_AUDIOGAIN_H
28 #define _MULTIMEDIA_AUDIOGAIN_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <AudioTypePcm.h>
38 // Class to handle gain calculations
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
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
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
68 // Internal processing methods
71 virtual void process_dcfilter(
73 // calculate instant gain
74 virtual void process_instant(
76 // calculate weighted gain
77 virtual void process_weighted(
81 AudioGain(); // Constructor
82 virtual ~AudioGain(); // Destructor
84 // TRUE if conversion ok
85 virtual Boolean
CanConvert(
86 const AudioHdr
&) const; // type to check against
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
102 #endif /* !_MULTIMEDIA_AUDIOGAIN_H */