home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / guicast / units.h < prev    next >
C/C++ Source or Header  |  2000-11-29  |  3KB  |  120 lines

  1. #ifndef UNITS_H
  2. #define UNITS_H
  3.  
  4. #include <math.h>
  5. #include <stdio.h>
  6. #define INFINITYGAIN -40
  7. #define MAXGAIN 50
  8. #define TOTALFREQS 400
  9.  
  10.  
  11. #define TIME_HMS 0
  12. #define TIME_HMS2 6
  13. #define TIME_HMSF 1
  14. #define TIME_SAMPLES 2
  15. #define TIME_SAMPLES_HEX 3
  16. #define TIME_FRAMES 4
  17. #define TIME_FEET_FRAMES 5
  18.  
  19. class DB
  20. {
  21. public:
  22.     DB(float infinitygain = INFINITYGAIN);
  23.     virtual ~DB() {};
  24.     
  25. // return power of db using a table
  26.     float fromdb_table();
  27.     float fromdb_table(float db);
  28. // return power from db using log10
  29.     float fromdb();
  30.     static float fromdb(float db);
  31.  
  32. // convert db to power using a formula
  33.     static float todb(float power);
  34.  
  35.     inline DB& operator++() { if(db < MAXGAIN) db += 0.1; return *this; };
  36.     inline DB& operator--() { if(db > INFINITYGAIN) db -= 0.1; return *this; };
  37.     inline DB& operator=(DB &newdb) { db = newdb.db; return *this; };
  38.     inline DB& operator=(int newdb) { db = newdb; return *this; };
  39.     inline int operator==(DB &newdb) { return db == newdb.db; };
  40.     inline int operator==(int newdb) { return db == newdb; };
  41.  
  42.     static float *topower;
  43.     float db;
  44.     float infinitygain;
  45. };
  46.  
  47. class Freq
  48. {
  49. public:
  50.     Freq();
  51.     Freq(const Freq& oldfreq);
  52.     virtual ~Freq() {};
  53.  
  54. // set freq to index given
  55.     int tofreq(int index);
  56.  
  57. // return index of frequency
  58.     int fromfreq();
  59.     int fromfreq(int index);
  60.  
  61. // increment frequency by one
  62.     Freq& operator++();
  63.     Freq& operator--();
  64.     
  65.     int operator>(Freq &newfreq);
  66.     int operator<(Freq &newfreq);
  67.     Freq& operator=(const Freq &newfreq);
  68.     int operator=(const int newfreq);
  69.     int operator!=(Freq &newfreq);
  70.     int operator==(Freq &newfreq);
  71.     int operator==(int newfreq);
  72.  
  73.     static int *freqtable;
  74.     int freq;
  75. };
  76.  
  77.  
  78. class Units
  79. {
  80. public:
  81.     Units() {};
  82.  
  83.     // No rounding.
  84.     static float toframes(long samples, int sample_rate, float framerate);
  85.     // Round up if > .5
  86.     static long toframes_round(long samples, int sample_rate, float framerate);
  87.  
  88.     static long tosamples(float frames, int sample_rate, float framerate);
  89.     static char* totext(char *text, 
  90.                 long samples, 
  91.                 int time_format, 
  92.                 int samplerate, 
  93.                 float frame_rate = 0, 
  94.                 float frames_per_foot = 0);    // give text representation as time
  95.     static char* totext(char *text, 
  96.                 double seconds, 
  97.                 int time_format, 
  98.                 int sample_rate = 0,
  99.                 float frame_rate = 0, 
  100.                 float frames_per_foot = 0);    // give text representation as time
  101.     static long fromtext(char *text, 
  102.                 int samplerate, 
  103.                 int time_format, 
  104.                 float frame_rate, 
  105.                 float frames_per_foot);    // convert time to samples
  106.     static double text_to_seconds(char *text, 
  107.                 int samplerate, 
  108.                 int time_format, 
  109.                 float frame_rate, 
  110.                 float frames_per_foot);   // Convert text to seconds
  111.  
  112.     static float xy_to_polar(int x, int y);
  113.     static void polar_to_xy(float angle, int radius, int &x, int &y);
  114.     
  115.     static long round(double result);
  116.     static float quantize10(float value);
  117. };
  118.  
  119. #endif
  120.