00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __DSP_H
00041 #define __DSP_H
00042 #else
00043 #error Multiple includes of DSP.H are not allowed
00044 #endif
00045
00046 #include <fstream>
00047 #include <iomanip>
00048 #include <iostream>
00049 #include <cmath>
00050 #include <cstdlib>
00051
00052 using namespace std;
00053
00054 #define M_PI 3.14159265358979323846
00055
00056 #include "edeque.h"
00057
00058 class sample_giver
00059 { public:
00060 virtual ~sample_giver() {};
00061 virtual bool give(float & s) = 0;
00062
00063 virtual bool give(float array[], int howmany);
00064
00065 virtual bool skip(int howmany=1);
00066
00067 virtual bool failed(void) const = 0;
00068 virtual int gave(void) const { return mgave; };
00069
00070
00071 protected:
00072 int mgave;
00073 };
00074
00075 class sample_taker
00076 { public:
00077 virtual ~sample_taker() {};
00078 virtual void take(float s) = 0;
00079 virtual void take(float array[], int howmany);
00080 virtual void close(void);
00081 };
00082
00083 class wav_file_giver: public sample_giver
00084 { public:
00085 wav_file_giver(const char * name);
00086 ~wav_file_giver();
00087
00088 int samprate() const;
00089 int bits() const;
00090 int channels() const;
00091 virtual bool failed() const;
00092 virtual bool give(float & s);
00093
00094 private:
00095 wav_file_giver(wav_file_giver const &);
00096 wav_file_giver const & operator=(wav_file_giver const &);
00097
00098 int end_offset;
00099 int mrate, mbits, mchans;
00100 istream * reader;
00101 };
00102
00103 class wav_file_taker: public sample_taker
00104 { public:
00105 wav_file_taker(const char * name, int samprate=44100, int bits=16, int channels=1);
00106 ~wav_file_taker();
00107
00108 bool failed() const;
00109 virtual void take(float s);
00110
00111 bool clipped() const;
00112 void clear_clip();
00113
00114 bool min_max_exists() const;
00115 float max() const;
00116 float min() const;
00117 private:
00118 wav_file_taker(wav_file_taker const &);
00119 wav_file_taker const & operator=(wav_file_taker const &);
00120
00121 void write_header(void);
00122
00123 bool mclipped;
00124 int start_offset;
00125 int bytes_written;
00126 int mrate, mbits, mchans;
00127 int chan_now;
00128 ostream * writer;
00129
00130 bool _have_min_max;
00131 float _min, _max;
00132
00133 float * error;
00134 };
00135
00136 int pump_samples(sample_giver * a, sample_taker * b, int limit=-1,
00137 wav_file_taker * clipmon = 0);
00138
00139