r288: This commit was manufactured by cvs2svn to create tag 'hv_1_2_0'.
[cinelerra_cv/mob.git] / hvirtual / guicast / units.h
blob1b0cd44a1c0d96cce0f36ebd07844b1cf30ec06e
1 #ifndef UNITS_H
2 #define UNITS_H
4 #include "sizes.h"
6 #include <math.h>
7 #include <stdint.h>
8 #include <stdio.h>
11 #define INFINITYGAIN -40
12 #define MAXGAIN 50
13 #define TOTALFREQS 1024
15 // h:mm:ss.sss
16 #define TIME_HMS 0
17 // h:mm:ss
18 #define TIME_HMS2 6
19 // hh:mm:ss
20 #define TIME_HMS3 7
21 // h:mm:ss:ff
22 #define TIME_HMSF 1
23 #define TIME_SAMPLES 2
24 #define TIME_SAMPLES_HEX 3
25 #define TIME_FRAMES 4
26 // fffff-ff
27 #define TIME_FEET_FRAMES 5
30 class DB
32 public:
33 DB(float infinitygain = INFINITYGAIN);
34 virtual ~DB() {};
36 // return power of db using a table
37 float fromdb_table();
38 float fromdb_table(float db);
39 // return power from db using log10
40 float fromdb();
41 static float fromdb(float db);
43 // convert db to power using a formula
44 static float todb(float power);
46 inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
47 inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
48 inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
49 inline DB& operator=(int newdb) { db = newdb; return *this; };
50 inline int operator==(DB &newdb) { return db == newdb.db; };
51 inline int operator==(int newdb) { return db == newdb; };
53 static float *topower;
54 float db;
55 float infinitygain;
58 // Third octave frequency table
59 class Freq
61 public:
62 Freq();
63 Freq(const Freq& oldfreq);
64 virtual ~Freq() {};
66 static void init_table();
68 // set freq to index given
69 static int tofreq(int index);
71 // return index of frequency
72 int fromfreq();
73 static int fromfreq(int index);
75 // increment frequency by one
76 Freq& operator++();
77 Freq& operator--();
79 int operator>(Freq &newfreq);
80 int operator<(Freq &newfreq);
81 Freq& operator=(const Freq &newfreq);
82 int operator=(const int newfreq);
83 int operator!=(Freq &newfreq);
84 int operator==(Freq &newfreq);
85 int operator==(int newfreq);
87 static int *freqtable;
88 int freq;
92 class Units
94 public:
95 Units() {};
97 // No rounding.
98 static float toframes(int64_t samples, int sample_rate, float framerate);
99 // Round up if > .5
100 static int64_t toframes_round(int64_t samples, int sample_rate, float framerate);
101 static double fix_framerate(double value);
102 static double atoframerate(char *text);
105 // separator strings for BC_TextBox::set_separators
106 // Returns 0 if the format has no separators.
107 static char* format_to_separators(int time_format);
109 static int64_t tosamples(float frames, int sample_rate, float framerate);
110 static char* totext(char *text,
111 int64_t samples,
112 int time_format,
113 int samplerate,
114 float frame_rate = 0,
115 float frames_per_foot = 0); // give text representation as time
116 static char* totext(char *text,
117 double seconds,
118 int time_format,
119 int sample_rate = 0,
120 float frame_rate = 0,
121 float frames_per_foot = 0); // give text representation as time
122 static int64_t fromtext(char *text,
123 int samplerate,
124 int time_format,
125 float frame_rate,
126 float frames_per_foot); // convert time to samples
127 static double text_to_seconds(char *text,
128 int samplerate,
129 int time_format,
130 float frame_rate,
131 float frames_per_foot); // Convert text to seconds
133 static char* print_time_format(int time_format, char *string);
135 static float xy_to_polar(int x, int y);
136 static void polar_to_xy(float angle, int radius, int &x, int &y);
138 // Numbers < 0 round down if next digit is < 5
139 // Numbers > 0 round up if next digit is > 5
140 static int64_t round(double result);
142 // Flooring type converter rounded to nearest .001
143 static int64_t to_int64(double result);
145 static float quantize10(float value);
146 static float quantize(float value, float precision);
148 static void* int64_to_ptr(uint64_t value);
149 static uint64_t ptr_to_int64(void *ptr);
153 #endif