1 /* SpectrumTier.cpp
2  *
3  * Copyright (C) 20072008,2010-2012,2015,2016,2018,2020 Paul Boersma
4  *
5  * This code is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This code is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this work. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "Ltas_to_SpectrumTier.h"
20 
21 Thing_implement (SpectrumTier, RealTier, 0);
22 
v_info()23 void structSpectrumTier :: v_info () {
24 	our structDaata :: v_info ();
25 	MelderInfo_writeLine (U"Frequency domain:");
26 	MelderInfo_writeLine (U"   Lowest frequency: ", our xmin, U" Hz");
27 	MelderInfo_writeLine (U"   Highest frequency: ", our xmax, U" Hz");
28 	MelderInfo_writeLine (U"   Total bandwidth: ", our xmax - our xmin, U" Hz");
29 	MelderInfo_writeLine (U"Number of points: ", our points.size);
30 	MelderInfo_writeLine (U"Minimum power value: ", RealTier_getMinimumValue (this), U" dB/Hz");
31 	MelderInfo_writeLine (U"Maximum power value: ", RealTier_getMaximumValue (this), U" dB/Hz");
32 }
33 
SpectrumTier_create(double fmin,double fmax)34 autoSpectrumTier SpectrumTier_create (double fmin, double fmax) {
35 	try {
36 		autoSpectrumTier me = Thing_new (SpectrumTier);
37 		RealTier_init (me.get(), fmin, fmax);
38 		return me;
39 	} catch (MelderError) {
40 		Melder_throw (U"SpectrumTier not created.");
41 	}
42 }
43 
SpectrumTier_draw(SpectrumTier me,Graphics g,double fmin,double fmax,double pmin,double pmax,bool garnish,conststring32 method)44 void SpectrumTier_draw (SpectrumTier me, Graphics g, double fmin, double fmax,
45 	double pmin, double pmax, bool garnish, conststring32 method)
46 {
47 	RealTier_draw (me, g, fmin, fmax, pmin, pmax, garnish, method, U"Power spectral density (dB)");
48 }
49 
SpectrumTier_list(SpectrumTier me,bool includeIndexes,bool includeFrequency,bool includePowerDensity)50 void SpectrumTier_list (SpectrumTier me, bool includeIndexes, bool includeFrequency, bool includePowerDensity) {
51 	try {
52 		autoTable table = SpectrumTier_downto_Table (me, includeIndexes, includeFrequency, includePowerDensity);
53 		Table_list (table.get(), false);
54 	} catch (MelderError) {
55 		Melder_throw (me, U": not listed.");
56 	}
57 }
58 
SpectrumTier_downto_Table(SpectrumTier me,bool includeIndexes,bool includeFrequency,bool includePowerDensity)59 autoTable SpectrumTier_downto_Table (SpectrumTier me, bool includeIndexes, bool includeFrequency, bool includePowerDensity) {
60 	return RealTier_downto_Table (me,
61 		includeIndexes ? U"index" : nullptr,
62 		includeFrequency ? U"freq(Hz)" : nullptr,
63 		includePowerDensity ? U"pow(dB/Hz)" : nullptr);
64 }
65 
Spectrum_to_SpectrumTier_peaks(Spectrum me)66 autoSpectrumTier Spectrum_to_SpectrumTier_peaks (Spectrum me) {
67 	try {
68 		autoLtas ltas = Spectrum_to_Ltas_1to1 (me);
69 		autoSpectrumTier thee = Ltas_to_SpectrumTier_peaks (ltas.get());
70 		return thee;
71 	} catch (MelderError) {
72 		Melder_throw (me, U": peaks not converted to SpectrumTier.");
73 	}
74 }
75 
76 /* End of file SpectrumTier.cpp */
77