1 /*
2 MPEG Maaate: An Australian MPEG audio analysis toolkit
3 Copyright (C) 2000 Commonwealth Scientific and Industrial Research Organisation
4 (CSIRO), Australia.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef ALLFORMAT_H
22 #define ALLFORMAT_H
23
24 // channels used by decode to return pcm samples
25 typedef enum { LEFT=0, RIGHT, STEREO } Channels;
26
27 // frequency resolution
28 typedef enum { NO = 0, LOW, HIGH, PCM } Resolution;
29
30 #include "tier1Platform.h"
31
32 #ifdef __cplusplus
33
34 #include <algorithm>
35 #include <cstdio>
36 #include <cmath>
37 #include <iostream>
38 #include <string>
39
40 // for reading file size
41 #include <sys/types.h>
42 #include <sys/stat.h>
43
44 using namespace std;
45
46 #ifndef PI
47 #define PI 3.14159265358979
48 #endif
49
50 //--------------------------------------------------------------------------
51
52 // abstract class to define the `format` to be followed by each format,
53 //a kind of normalisation!
54 class CSAPI_TIER1 AllFormat {
55 public:
56
57 /* virtual destructor */
58 // virtual ~AllFormat() = 0;
59
60 /* information about the file to be analysed */
61 virtual bool is_stereo() = 0;
62 virtual double sampling_rate() = 0;
63 virtual int channel() = 0;
64
65 /* number of frequency subbands related to the analysis at the given
66 frequency analysis resolution */
67 virtual unsigned int nb_subbands( Resolution res = LOW ) = 0;
68
69 /* returns the number of frequency values in an analysis window
70 depending on the given frequency analysis resolution */
71 virtual unsigned int timeticks (Resolution res=LOW) = 0;
72
73 /* returns the duration of the time interval (in sec) which is related
74 to one frequency value at the given frequency analysis resolution */
75 virtual float sample_duration (Resolution res=LOW) = 0;
76
77 /* go to the analysis window number w_nb counting from the start of the
78 file without analysing the window */
79 virtual bool seek_window (long w_nb) = 0;
80
81 /* skip to next window without analysing current window */
82 virtual bool skip_window() = 0;
83
84 /* go to the next analysis window while analysing the current window */
85 virtual bool next_window (Resolution res=LOW) = 0;
86
87 /* checks whether there is any data available in the analysis file */
88 virtual bool data_available() = 0;
89
90 /* returns the frequency value number nb from the given channel, subband
91 at the given frequency analysis resolution */
92 virtual double freq_value (unsigned int ch, unsigned int sb,
93 unsigned int nb, Resolution res=LOW) = 0;
94
95 /* return the pcm value number no of a channel ch*/
96 virtual short pcm (unsigned int ch, unsigned int no) = 0;
97
98 /* decodes the frequency values of the given channel and number of windows
99 into PCM values to be stored in the given buffer */
100 virtual long decode (short * buffer, long windows, Channels ch) = 0;
101
102 /* accessor to private fields */
103 inline string get_filename();
104 virtual bool file_ok() = 0;
105 inline long get_fileDuration();
106 inline long get_windowNo();
107 inline float get_windowDuration();
108
109 protected:
110
111 //must be used by all inherited class in the constructor
112 inline bool common_constr(string filestr);
113
114 //must be used by all inherited class in the destructor
115 inline void common_destr();
116
117 //name of the file
118 string filename;
119
120 // remember the file duration in number of windows
121 long fileDuration;
122
123 // remember the current window number
124 long windowNo;
125
126 //window duration in second
127 float windowDuration;
128
129 };
130
131 //--------------------------------------------------------------------------
132
133
134 inline string CSAPI_TIER1
get_filename()135 AllFormat::get_filename() {
136 return filename;
137 }
138
139 inline long CSAPI_TIER1
get_fileDuration()140 AllFormat::get_fileDuration() {
141 return fileDuration;
142 }
143
144 inline long CSAPI_TIER1
get_windowNo()145 AllFormat::get_windowNo() {
146 return windowNo;
147 }
148
149 inline float CSAPI_TIER1
get_windowDuration()150 AllFormat::get_windowDuration() {
151 return windowDuration;
152 }
153
154 inline bool CSAPI_TIER1
common_constr(string filestr)155 AllFormat::common_constr (string filestr) {
156 //allFormat inherited attributs
157 filename = filestr;
158 windowNo = 0;
159 fileDuration = -1;
160 windowDuration = 0.0;
161 return true;
162 }
163
164 inline void CSAPI_TIER1
common_destr()165 AllFormat::common_destr () {
166 return;
167 }
168
169 #else /* __cplusplus */
170
171 typedef struct Allformat AllFormat;
172
173 #endif /* __cplusplus */
174
175 #endif
176