@@ -15,11 +15,12 @@ import "math"
1515type BinMethod func (int , float64 , float64 ) float64
1616
1717type AnalyzerConfig struct {
18- SampleRate float64 // audio sample rate
19- SampleSize int // number of samples per slice
20- SquashLow bool // squash the low end the spectrum
21- SquashLowOld bool // squash the low end using the old method
22- BinMethod BinMethod // method used for calculating bin value
18+ SampleRate float64 // audio sample rate
19+ SampleSize int // number of samples per slice
20+ SquashLow bool // squash the low end the spectrum
21+ SquashLowOld bool // squash the low end using the old method
22+ DontNormalize bool // dont run math.Log on output
23+ BinMethod BinMethod // method used for calculating bin value
2324}
2425
2526type Analyzer interface {
@@ -30,10 +31,11 @@ type Analyzer interface {
3031
3132// analyzer is an audio spectrum in a buffer
3233type analyzer struct {
33- cfg AnalyzerConfig // the analyzer config
34- bins []bin // bins for processing
35- binCount int // number of bins we look at
36- fftSize int // number of fft bins
34+ cfg AnalyzerConfig // the analyzer config
35+ bins []bin // bins for processing
36+ binCount int // number of bins we look at
37+ fftSize int // number of fft bins
38+ dontNormalize bool // dont normalize the output
3739}
3840
3941// Bin is a helper struct for spectrum
@@ -107,9 +109,10 @@ func MinNonZeroSampleValue() BinMethod {
107109
108110func NewAnalyzer (cfg AnalyzerConfig ) Analyzer {
109111 return & analyzer {
110- cfg : cfg ,
111- bins : make ([]bin , cfg .SampleSize ),
112- fftSize : cfg .SampleSize / 2 + 1 ,
112+ cfg : cfg ,
113+ bins : make ([]bin , cfg .SampleSize ),
114+ fftSize : cfg .SampleSize / 2 + 1 ,
115+ dontNormalize : cfg .DontNormalize ,
113116 }
114117}
115118
@@ -151,7 +154,9 @@ func (az *analyzer) ProcessBin(idx int, src []complex128) float64 {
151154 return 0.0
152155 }
153156
154- mag = math .Log (mag )
157+ if ! az .dontNormalize {
158+ mag = math .Log (mag )
159+ }
155160
156161 if mag < 0.0 {
157162 return 0.0
0 commit comments