r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / units.h
blobae248634cddabeb4213d2b66f94d1fbceeab2618
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
16 #define TIME_HMS 0
17 #define TIME_HMS2 6
18 #define TIME_HMSF 1
19 #define TIME_SAMPLES 2
20 #define TIME_SAMPLES_HEX 3
21 #define TIME_FRAMES 4
22 #define TIME_FEET_FRAMES 5
25 class DB
27 public:
28 DB(float infinitygain = INFINITYGAIN);
29 virtual ~DB() {};
31 // return power of db using a table
32 float fromdb_table();
33 float fromdb_table(float db);
34 // return power from db using log10
35 float fromdb();
36 static float fromdb(float db);
38 // convert db to power using a formula
39 static float todb(float power);
41 inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
42 inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
43 inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
44 inline DB& operator=(int newdb) { db = newdb; return *this; };
45 inline int operator==(DB &newdb) { return db == newdb.db; };
46 inline int operator==(int newdb) { return db == newdb; };
48 static float *topower;
49 float db;
50 float infinitygain;
53 // Third octave frequency table
54 class Freq
56 public:
57 Freq();
58 Freq(const Freq& oldfreq);
59 virtual ~Freq() {};
61 static void init_table();
63 // set freq to index given
64 static int tofreq(int index);
66 // return index of frequency
67 int fromfreq();
68 static int fromfreq(int index);
70 // increment frequency by one
71 Freq& operator++();
72 Freq& operator--();
74 int operator>(Freq &newfreq);
75 int operator<(Freq &newfreq);
76 Freq& operator=(const Freq &newfreq);
77 int operator=(const int newfreq);
78 int operator!=(Freq &newfreq);
79 int operator==(Freq &newfreq);
80 int operator==(int newfreq);
82 static int *freqtable;
83 int freq;
87 class Units
89 public:
90 Units() {};
92 // No rounding.
93 static float toframes(int64_t samples, int sample_rate, float framerate);
94 // Round up if > .5
95 static int64_t toframes_round(int64_t samples, int sample_rate, float framerate);
96 static double fix_framerate(double value);
97 static double atoframerate(char *text);
100 static int64_t tosamples(float frames, int sample_rate, float framerate);
101 static char* totext(char *text,
102 int64_t samples,
103 int time_format,
104 int samplerate,
105 float frame_rate = 0,
106 float frames_per_foot = 0); // give text representation as time
107 static char* totext(char *text,
108 double seconds,
109 int time_format,
110 int sample_rate = 0,
111 float frame_rate = 0,
112 float frames_per_foot = 0); // give text representation as time
113 static int64_t fromtext(char *text,
114 int samplerate,
115 int time_format,
116 float frame_rate,
117 float frames_per_foot); // convert time to samples
118 static double text_to_seconds(char *text,
119 int samplerate,
120 int time_format,
121 float frame_rate,
122 float frames_per_foot); // Convert text to seconds
124 static char* print_time_format(int time_format, char *string);
126 static float xy_to_polar(int x, int y);
127 static void polar_to_xy(float angle, int radius, int &x, int &y);
129 // Numbers < 0 round down if next digit is < 5
130 // Numbers > 0 round up if next digit is > 5
131 static int64_t round(double result);
133 // Flooring type converter rounded to nearest .001
134 static int64_t to_int64(double result);
136 static float quantize10(float value);
137 static float quantize(float value, float precision);
139 static void* int64_to_ptr(uint64_t value);
140 static uint64_t ptr_to_int64(void *ptr);
143 #endif