Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

units.h

Go to the documentation of this file.
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 // h:mm:ss.sss
00016 #define TIME_HMS 0
00017 // h:mm:ss
00018 #define TIME_HMS2 6
00019 // hh:mm:ss
00020 #define TIME_HMS3 7
00021 // h:mm:ss:ff
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 // fffff-ff
00028 #define TIME_FEET_FRAMES 5
00029 
00030 class DB
00031 {
00032 public:
00033         DB(float infinitygain = INFINITYGAIN);
00034         virtual ~DB() {};
00035         
00036 // return power of db using a table
00037         float fromdb_table();
00038         float fromdb_table(float db);
00039 // return power from db using log10
00040         float fromdb();
00041         static float fromdb(float db);
00042 
00043 // convert db to power using a formula
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 // Third octave frequency table
00061 class Freq
00062 {
00063 public:
00064         Freq();
00065         Freq(const Freq& oldfreq);
00066         virtual ~Freq() {};
00067 
00068         static void init_table();
00069 
00070 // set freq to index given
00071         static int tofreq(int index);
00072 
00073 // return index of frequency
00074         int fromfreq();
00075         static int fromfreq(int index);
00076 
00077 // increment frequency by one
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 // No rounding.
00100         static float toframes(int64_t samples, int sample_rate, float framerate);
00101 // Round up if > .5
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 // Punctuate with commas
00107         static void punctuate(char *string);
00108 
00109 
00110 // separator strings for BC_TextBox::set_separators
00111 // Returns 0 if the format has no separators.
00112         static char* format_to_separators(int time_format);
00113 
00114         static int64_t tosamples(float frames, int sample_rate, float framerate);
00115 // give text representation as time
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 // give text representation as time
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 // convert time to samples
00130         static int64_t fromtext(char *text, 
00131                                 int samplerate, 
00132                                 int time_format, 
00133                                 float frame_rate, 
00134                                 float frames_per_foot);
00135 // Convert text to seconds
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 // Numbers < 0 round down if next digit is < 5
00148 // Numbers > 0 round up if next digit is > 5
00149         static int64_t round(double result);
00150 
00151 // Flooring type converter rounded to nearest .001
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

Generated on Sun Jan 8 13:26:35 2006 for Guicast-svn by  doxygen 1.4.4