00001 #ifndef UNITS_H
00002 #define UNITS_H
00003
00004 #include "sizes.h"
00005
00006 #include <math.h>
00007 #include <stdint.h>
00008 #include <stdio.h>
00009
00010
00011 #define INFINITYGAIN -40
00012 #define MAXGAIN 50
00013 #define TOTALFREQS 1024
00014
00015
00016 #define TIME_HMS 0
00017
00018 #define TIME_HMS2 6
00019
00020 #define TIME_HMS3 7
00021
00022 #define TIME_SECONDS 8
00023 #define TIME_HMSF 1
00024 #define TIME_SAMPLES 2
00025 #define TIME_SAMPLES_HEX 3
00026 #define TIME_FRAMES 4
00027
00028 #define TIME_FEET_FRAMES 5
00029 #define TIME_SECONDS__STR "ssss.sss"
00030 #define TIME_HMS__STR "h:mm:ss.sss"
00031 #define TIME_HMS2__STR "h:mm:ss"
00032 #define TIME_HMS3__STR "hh:mm:ss"
00033 #define TIME_HMSF__STR "h:mm:ss:ff"
00034 #define TIME_SAMPLES__STR "audio samples"
00035 #define TIME_SAMPLES_HEX__STR "audio samples (hex)"
00036 #define TIME_FRAMES__STR "video frames"
00037 #define TIME_FEET_FRAMES__STR "video frames (feet)"
00038
00039 class DB
00040 {
00041 public:
00042 DB(float infinitygain = INFINITYGAIN);
00043 virtual ~DB() {};
00044
00045
00046 float fromdb_table();
00047 float fromdb_table(float db);
00048
00049 float fromdb();
00050 static float fromdb(float db);
00051
00052
00053 static float todb(float power);
00054
00055 inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
00056 inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
00057 inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
00058 inline DB& operator=(int newdb) { db = newdb; return *this; };
00059 inline int operator==(DB &newdb) { return db == newdb.db; };
00060 inline int operator==(int newdb) { return db == newdb; };
00061
00062 static float *topower;
00063 float db;
00064 float infinitygain;
00065 private:
00066 static float *allocated;
00067 };
00068
00069
00070 class Freq
00071 {
00072 public:
00073 Freq();
00074 Freq(const Freq& oldfreq);
00075 virtual ~Freq() {};
00076
00077 static void init_table();
00078
00079
00080 static int tofreq(int index);
00081
00082
00083 int fromfreq();
00084 static int fromfreq(int index);
00085
00086
00087 Freq& operator++();
00088 Freq& operator--();
00089
00090 int operator>(Freq &newfreq);
00091 int operator<(Freq &newfreq);
00092 Freq& operator=(const Freq &newfreq);
00093 int operator=(const int newfreq);
00094 int operator!=(Freq &newfreq);
00095 int operator==(Freq &newfreq);
00096 int operator==(int newfreq);
00097
00098 static int *freqtable;
00099 int freq;
00100 };
00101
00102
00103 class Units
00104 {
00105 public:
00106 Units() {};
00107
00108 static int timeformat_totype(char *tcf);
00109
00110
00111 static float toframes(int64_t samples, int sample_rate, float framerate);
00112
00113 static int64_t toframes_round(int64_t samples, int sample_rate, float framerate);
00114 static double fix_framerate(double value);
00115 static double atoframerate(char *text);
00116
00117
00118
00119 static void punctuate(char *string);
00120
00121
00122
00123
00124 static char* format_to_separators(int time_format);
00125
00126 static int64_t tosamples(float frames, int sample_rate, float framerate);
00127
00128 static char* totext(char *text,
00129 int64_t samples,
00130 int time_format,
00131 int samplerate,
00132 float frame_rate = 0,
00133 float frames_per_foot = 0);
00134
00135 static char* totext(char *text,
00136 double seconds,
00137 int time_format,
00138 int sample_rate = 0,
00139 float frame_rate = 0,
00140 float frames_per_foot = 0);
00141
00142 static int64_t fromtext(char *text,
00143 int samplerate,
00144 int time_format,
00145 float frame_rate,
00146 float frames_per_foot);
00147
00148 static double text_to_seconds(char *text,
00149 int samplerate,
00150 int time_format,
00151 float frame_rate,
00152 float frames_per_foot);
00153
00154 static char* print_time_format(int time_format, char *string);
00155
00156 static float xy_to_polar(int x, int y);
00157 static void polar_to_xy(float angle, int radius, int &x, int &y);
00158
00159
00160
00161 static int64_t round(double result);
00162
00163
00164 static int64_t to_int64(double result);
00165
00166 static float quantize10(float value);
00167 static float quantize(float value, float precision);
00168
00169 static void* int64_to_ptr(uint64_t value);
00170 static uint64_t ptr_to_int64(void *ptr);
00171
00172
00173
00174 static void fix_double(double *x);
00175 };
00176
00177 #endif