4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define INFINITYGAIN -96
34 #define TOTALFREQS 1024
37 #define TOTAL_TIMEFORMATS 8
41 #define TIME_HMS_TEXT _("Hours:Minutes:Seconds.xxx")
44 #define TIME_HMSF_TEXT _("Hours:Minutes:Seconds:Frames")
45 #define TIME_SAMPLES 2
46 #define TIME_SAMPLES_TEXT _("Samples")
47 #define TIME_SAMPLES_HEX 3
48 #define TIME_SAMPLES_HEX_TEXT _("Hex Samples")
50 #define TIME_FRAMES_TEXT _("Frames")
52 #define TIME_FEET_FRAMES 5
53 #define TIME_SECONDS__STR "ssss.sss"
54 #define TIME_HMS__STR "h:mm:ss.sss"
55 #define TIME_HMS2__STR "h:mm:ss"
56 #define TIME_HMS3__STR "hh:mm:ss"
57 #define TIME_HMSF__STR "h:mm:ss:ff"
58 #define TIME_MS1__STR "m:ss"
59 #define TIME_MS2__STR "+m:ss"
60 #define TIME_TIMECODE__STR "timecode"
61 #define TIME_SAMPLES__STR "audio samples"
62 #define TIME_SAMPLES_HEX__STR "audio samples (hex)"
63 #define TIME_FRAMES__STR "video frames"
64 #define TIME_FEET_FRAMES__STR "video frames (feet)"
65 #define TIME_FEET_FRAMES_TEXT _("Feet-frames")
70 #define TIME_HMS2_TEXT _("Hours:Minutes:Seconds")
73 #define TIME_HMS3_TEXT _("Hours:Minutes:Seconds")
75 #define TIME_SECONDS 8
76 #define TIME_SECONDS_TEXT _("Seconds")
81 #define TIME_MS2_TEXT _("Minutes:Seconds")
83 #define TIME_TIMECODE 11
84 #define TIME_TIMECODE_TEXT _("Timecode")
92 DB(float infinitygain = INFINITYGAIN);
95 // return power of db using a table
97 float fromdb_table(float db);
98 // return power from db using log10
100 static float fromdb(float db);
102 // convert db to power using a formula
103 static float todb(float power);
105 inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
106 inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
107 inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
108 inline DB& operator=(int newdb) { db = newdb; return *this; };
109 inline int operator==(DB &newdb) { return db == newdb.db; };
110 inline int operator==(int newdb) { return db == newdb; };
116 static float *topower_base;
119 // Third octave frequency table
125 Freq(const Freq& oldfreq);
128 static void init_table();
130 // set freq to index given
131 static int tofreq(int index);
133 // return index of frequency
135 static int fromfreq(int index);
136 static double tofreq_f(double index);
137 static double fromfreq_f(double freq);
138 // increment frequency by one
142 int operator>(Freq &newfreq);
143 int operator<(Freq &newfreq);
144 Freq& operator=(const Freq &newfreq);
145 int operator=(const int newfreq);
146 int operator!=(Freq &newfreq);
147 int operator==(Freq &newfreq);
148 int operator==(int newfreq);
150 static int *freqtable;
162 static int timeformat_totype(const char *tcf);
163 static const char *timetype_toformat(int type);
165 static float toframes(int64_t samples, int sample_rate, float framerate);
167 static int64_t toframes_round(int64_t samples, int sample_rate, float framerate);
168 static double fix_framerate(double value);
169 static double atoframerate(const char *text);
170 static int64_t get_int64(const char*&cp);
171 static double get_double(const char*&cp);
172 static void skip_seperators(const char*&cp);
174 // Punctuate with commas
175 static void punctuate(char *string);
178 // separator strings for BC_TextBox::set_separators
179 // Returns 0 if the format has no separators.
180 static const char* format_to_separators(int time_format);
181 static int text_to_format(const char *string);
182 static const char* print_time_format(int time_format, char *string);
184 static int64_t tosamples(double frames, int sample_rate, float framerate);
185 // give text representation as time
186 static char* totext(char *text, int64_t samples, int time_format,
187 int samplerate, float frame_rate = 0, float frames_per_foot = 0,
188 double timecode_offset = 0);
189 // give text representation as time
190 static char* totext(char *text, double seconds, int time_format,
191 int sample_rate = 0, float frame_rate = 0, float frames_per_foot = 0,
192 double timecode_offset = 0);
193 // convert time to samples
194 static int64_t fromtext(const char *text, int samplerate,
195 int time_format, float frame_rate, float frames_per_foot,
196 double timecode_offset);
197 // Convert text to seconds
198 static double text_to_seconds(const char *text, int samplerate,
199 int time_format, float frame_rate = 0, float frames_per_foot = 0,
200 double timecode_offset = 0);
201 static char* size_totext(int64_t bytes, char *text);
203 static float xy_to_polar(int x, int y);
204 static void polar_to_xy(float angle, int radius, int &x, int &y);
206 // Numbers < 0 round down if next digit is < 5
207 // Numbers > 0 round up if next digit is > 5
208 static int64_t round(double result);
210 // Flooring type converter rounded to nearest .001
211 static int64_t to_int64(double result);
213 static float quantize10(float value);
214 static float quantize(float value, float precision);
216 static void* int64_to_ptr(uint64_t value);
217 static uint64_t ptr_to_int64(void *ptr);
219 // Comparisons between double seem to work more often when this is called
220 // on the comparison values.
221 static void fix_double(double *x);