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
00030 class DB
00031 {
00032 public:
00033 DB(float infinitygain = INFINITYGAIN);
00034 virtual ~DB() {};
00035
00036
00037 float fromdb_table();
00038 float fromdb_table(float db);
00039
00040 float fromdb();
00041 static float fromdb(float db);
00042
00043
00044 static float todb(float power);
00045
00046 inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
00047 inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
00048 inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
00049 inline DB& operator=(int newdb) { db = newdb; return *this; };
00050 inline int operator==(DB &newdb) { return db == newdb.db; };
00051 inline int operator==(int newdb) { return db == newdb; };
00052
00053 static float *topower;
00054 float db;
00055 float infinitygain;
00056 private:
00057 static float *allocated;
00058 };
00059
00060
00061 class Freq
00062 {
00063 public:
00064 Freq();
00065 Freq(const Freq& oldfreq);
00066 virtual ~Freq() {};
00067
00068 static void init_table();
00069
00070
00071 static int tofreq(int index);
00072
00073
00074 int fromfreq();
00075 static int fromfreq(int index);
00076
00077
00078 Freq& operator++();
00079 Freq& operator--();
00080
00081 int operator>(Freq &newfreq);
00082 int operator<(Freq &newfreq);
00083 Freq& operator=(const Freq &newfreq);
00084 int operator=(const int newfreq);
00085 int operator!=(Freq &newfreq);
00086 int operator==(Freq &newfreq);
00087 int operator==(int newfreq);
00088
00089 static int *freqtable;
00090 int freq;
00091 };
00092
00093
00094 class Units
00095 {
00096 public:
00097 Units() {};
00098
00099
00100 static float toframes(int64_t samples, int sample_rate, float framerate);
00101
00102 static int64_t toframes_round(int64_t samples, int sample_rate, float framerate);
00103 static double fix_framerate(double value);
00104 static double atoframerate(char *text);
00105
00106
00107 static void punctuate(char *string);
00108
00109
00110
00111
00112 static char* format_to_separators(int time_format);
00113
00114 static int64_t tosamples(float frames, int sample_rate, float framerate);
00115
00116 static char* totext(char *text,
00117 int64_t samples,
00118 int time_format,
00119 int samplerate,
00120 float frame_rate = 0,
00121 float frames_per_foot = 0);
00122
00123 static char* totext(char *text,
00124 double seconds,
00125 int time_format,
00126 int sample_rate = 0,
00127 float frame_rate = 0,
00128 float frames_per_foot = 0);
00129
00130 static int64_t fromtext(char *text,
00131 int samplerate,
00132 int time_format,
00133 float frame_rate,
00134 float frames_per_foot);
00135
00136 static double text_to_seconds(char *text,
00137 int samplerate,
00138 int time_format,
00139 float frame_rate,
00140 float frames_per_foot);
00141
00142 static char* print_time_format(int time_format, char *string);
00143
00144 static float xy_to_polar(int x, int y);
00145 static void polar_to_xy(float angle, int radius, int &x, int &y);
00146
00147
00148
00149 static int64_t round(double result);
00150
00151
00152 static int64_t to_int64(double result);
00153
00154 static float quantize10(float value);
00155 static float quantize(float value, float precision);
00156
00157 static void* int64_to_ptr(uint64_t value);
00158 static uint64_t ptr_to_int64(void *ptr);
00159
00160 };
00161
00162 #endif