From 6a961b68b14c2128fe682f5a99e3f65b40d449fa Mon Sep 17 00:00:00 2001 From: rsimonin Date: Sat, 5 Dec 2020 15:29:02 +0100 Subject: [PATCH] modifications --- COW.WAV | Bin 45612 -> 0 bytes COW_d.WAV | Bin 91180 -> 0 bytes com.WAV | Bin 384044 -> 0 bytes cowfft.WAV | Bin 89644 -> 0 bytes fft.cpp | 104 -------------------------------------------------------------------------------------------------------- fft.h | 10 ---------- fft/COW.WAV | Bin 0 -> 45612 bytes fft/cowfft.WAV | Bin 0 -> 45612 bytes fft/fft.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fft/fft.h | 10 ++++++++++ fft/fftcow.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fft/fftla.WAV | Bin 0 -> 44844 bytes fft/fftla.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fft/test | Bin 0 -> 33432 bytes fft/wavdata.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fft/wavdata.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fftcow.cpp | 57 --------------------------------------------------------- main.cpp | 40 ---------------------------------------- main/COW.WAV | Bin 0 -> 45612 bytes main/COW_d.WAV | Bin 0 -> 91180 bytes main/fft.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main/fft.h | 10 ++++++++++ main/main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ main/wavdata.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main/wavdata.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ modifreq.WAV | Bin 89644 -> 0 bytes modifreq.cpp | 69 --------------------------------------------------------------------- pur.WAV | Bin 48044 -> 0 bytes pur.cpp | 42 ------------------------------------------ pur/fft.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pur/fft.h | 10 ++++++++++ pur/pur.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ pur/purdo.WAV | Bin 0 -> 224044 bytes pur/purla.WAV | Bin 0 -> 224044 bytes pur/test | Bin 0 -> 29280 bytes pur/wavdata.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pur/wavdata.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ purfreq2.WAV | Bin 384044 -> 0 bytes purla.WAV | Bin 480044 -> 0 bytes strech/COW.WAV | Bin 0 -> 45612 bytes strech/fft.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ strech/fft.h | 10 ++++++++++ strech/lastrech.WAV | Bin 0 -> 44844 bytes strech/lastrech.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ strech/modifreq.WAV | Bin 0 -> 89644 bytes strech/modifreq.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ strech/strechcow.WAV | Bin 0 -> 45612 bytes strech/test | Bin 0 -> 33424 bytes strech/timestrechcow.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ strech/wavdata.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ strech/wavdata.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test | Bin 25024 -> 0 bytes test.WAV | Bin 96044 -> 0 bytes test.cpp | 107 ----------------------------------------------------------------------------------------------------------- test2.WAV | Bin 48044 -> 0 bytes testWAV.pro | 12 ------------ wavdata.cpp | 269 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- wavdata.h | 66 ------------------------------------------------------------------ 58 files changed, 2234 insertions(+), 776 deletions(-) delete mode 100644 COW.WAV delete mode 100644 COW_d.WAV delete mode 100644 com.WAV delete mode 100644 cowfft.WAV delete mode 100644 fft.cpp delete mode 100644 fft.h create mode 100644 fft/COW.WAV create mode 100644 fft/cowfft.WAV create mode 100644 fft/fft.cpp create mode 100644 fft/fft.h create mode 100644 fft/fftcow.cpp create mode 100644 fft/fftla.WAV create mode 100644 fft/fftla.cpp create mode 100644 fft/test create mode 100644 fft/wavdata.cpp create mode 100644 fft/wavdata.h delete mode 100644 fftcow.cpp delete mode 100644 main.cpp create mode 100644 main/COW.WAV create mode 100644 main/COW_d.WAV create mode 100644 main/fft.cpp create mode 100644 main/fft.h create mode 100644 main/main.cpp create mode 100644 main/wavdata.cpp create mode 100644 main/wavdata.h delete mode 100644 modifreq.WAV delete mode 100644 modifreq.cpp delete mode 100644 pur.WAV delete mode 100644 pur.cpp create mode 100644 pur/fft.cpp create mode 100644 pur/fft.h create mode 100644 pur/pur.cpp create mode 100644 pur/purdo.WAV create mode 100644 pur/purla.WAV create mode 100644 pur/test create mode 100644 pur/wavdata.cpp create mode 100644 pur/wavdata.h delete mode 100644 purfreq2.WAV delete mode 100644 purla.WAV create mode 100644 strech/COW.WAV create mode 100644 strech/fft.cpp create mode 100644 strech/fft.h create mode 100644 strech/lastrech.WAV create mode 100644 strech/lastrech.cpp create mode 100644 strech/modifreq.WAV create mode 100644 strech/modifreq.cpp create mode 100644 strech/strechcow.WAV create mode 100644 strech/test create mode 100644 strech/timestrechcow.cpp create mode 100644 strech/wavdata.cpp create mode 100644 strech/wavdata.h delete mode 100644 test delete mode 100644 test.WAV delete mode 100644 test.cpp delete mode 100644 test2.WAV delete mode 100644 testWAV.pro delete mode 100644 wavdata.cpp delete mode 100644 wavdata.h diff --git a/COW.WAV b/COW.WAV deleted file mode 100644 index 6cc4f52..0000000 Binary files a/COW.WAV and /dev/null differ diff --git a/COW_d.WAV b/COW_d.WAV deleted file mode 100644 index bae44ad..0000000 Binary files a/COW_d.WAV and /dev/null differ diff --git a/com.WAV b/com.WAV deleted file mode 100644 index 39d6f6f..0000000 Binary files a/com.WAV and /dev/null differ diff --git a/cowfft.WAV b/cowfft.WAV deleted file mode 100644 index 54a5d23..0000000 Binary files a/cowfft.WAV and /dev/null differ diff --git a/fft.cpp b/fft.cpp deleted file mode 100644 index 92567e1..0000000 --- a/fft.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/*---------------------------------------------------------------------------- - fft.c - fast Fourier transform and its inverse (both recursively) - Copyright (C) 2004, Jerome R. Breitenbach. All rights reserved. - - The author gives permission to anyone to freely copy, distribute, and use - this file, under the following conditions: - - No changes are made. - - No direct commercial advantage is obtained. - - No liability is attributed to the author for any damages incurred. - ----------------------------------------------------------------------------*/ - -/****************************************************************************** - * This file defines a C function fft that, by calling another function * - * fft_rec (also defined), calculates an FFT recursively. Usage: * - * fft(N, x, X); * - * Parameters: * - * N: number of points in FFT (must equal 2^n for some integer n >= 1) * - * x: pointer to N time-domain samples given in rectangular form (Re x, * - * Im x) * - * X: pointer to N frequency-domain samples calculated in rectangular form * - * (Re X, Im X) * - * Similarly, a function ifft with the same parameters is defined that * - * calculates an inverse FFT (IFFT) recursively. Usage: * - * ifft(N, x, X); * - * Here, N and X are given, and x is calculated. * - ******************************************************************************/ - -#include -#include -#include "fft.h" -/* macros */ -#define TWO_PI (6.2831853071795864769252867665590057683943L) - -/* FFT */ -void fft(int N, double (*x)[2], double (*X)[2]) -{ - /* Declare a pointer to scratch space. */ - double (*XX)[2] = (double (*)[2]) malloc(2 * N * sizeof(double)); - - /* Calculate FFT by a recursion. */ - fft_rec(N, 0, 1, x, X, XX); - - /* Free memory. */ - free(XX); -} - -/* FFT recursion */ -void fft_rec(int N, int offset, int delta, - double (*x)[2], double (*X)[2], double (*XX)[2]) -{ - int N2 = N/2; /* half the number of points in FFT */ - int k; /* generic index */ - double cs, sn; /* cosine and sine */ - int k00, k01, k10, k11; /* indices for butterflies */ - double tmp0, tmp1; /* temporary storage */ - - if(N != 2) /* Perform recursive step. */ - { - /* Calculate two (N/2)-point DFT's. */ - fft_rec(N2, offset, 2*delta, x, XX, X); - fft_rec(N2, offset+delta, 2*delta, x, XX, X); - - /* Combine the two (N/2)-point DFT's into one N-point DFT. */ - for(k=0; k= 1) * + * x: pointer to N time-domain samples given in rectangular form (Re x, * + * Im x) * + * X: pointer to N frequency-domain samples calculated in rectangular form * + * (Re X, Im X) * + * Similarly, a function ifft with the same parameters is defined that * + * calculates an inverse FFT (IFFT) recursively. Usage: * + * ifft(N, x, X); * + * Here, N and X are given, and x is calculated. * + ******************************************************************************/ + +#include +#include +#include "fft.h" +/* macros */ +#define TWO_PI (6.2831853071795864769252867665590057683943L) + +/* FFT */ +void fft(int N, double (*x)[2], double (*X)[2]) +{ + /* Declare a pointer to scratch space. */ + double (*XX)[2] = (double (*)[2]) malloc(2 * N * sizeof(double)); + + /* Calculate FFT by a recursion. */ + fft_rec(N, 0, 1, x, X, XX); + + /* Free memory. */ + free(XX); +} + +/* FFT recursion */ +void fft_rec(int N, int offset, int delta, + double (*x)[2], double (*X)[2], double (*XX)[2]) +{ + int N2 = N/2; /* half the number of points in FFT */ + int k; /* generic index */ + double cs, sn; /* cosine and sine */ + int k00, k01, k10, k11; /* indices for butterflies */ + double tmp0, tmp1; /* temporary storage */ + + if(N != 2) /* Perform recursive step. */ + { + /* Calculate two (N/2)-point DFT's. */ + fft_rec(N2, offset, 2*delta, x, XX, X); + fft_rec(N2, offset+delta, 2*delta, x, XX, X); + + /* Combine the two (N/2)-point DFT's into one N-point DFT. */ + for(k=0; k +#include "wavdata.h" +#include "fft.h" +#include + + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*4 + + +int main(int argc, char **argv) +{ +//Definition variables + int i; + float pi=3.141592; + WavData w; + w.load("COW.WAV"); + char *data = w.data(); + printf("%d\n",w.datasize()); + char *data2 = new char[w.datasize()]; + + double test[w.datasize()*2][2]; + double test1[w.datasize()*2][2]; + double test2[w.datasize()*2][2]; + +//Creation de la donnée + + for(i=0;i +#include "wavdata.h" +#include "fft.h" +#include + + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*2 + + +int main(int argc, char **argv) +{ +//Definition variables + int i,j; + float pi=3.141592; + double test[SIZE*2][2]; + double test2[SIZE*2][2]; + double test1[SIZE*2][2]; + + char *data2 = new char[SIZE]; + WavData w; + +//Creation de la donnée + for(i=0;i + + +using namespace std; + +WavData::WavData() +{ + _data=NULL; +} + +int WavData::error(int i,int line) +{ + std::cerr << "Erreur "<<__FILE__<<" L"<=0;i--) + { + result *= 256; + result += (unsigned char)content[i]; + } + return result; +} + +char * WavData::toLittleEndian(unsigned int content, int size) +{ + char * result= new char [size*sizeof(char)]; + + for(int i=0;i>= 8; + } + + return result; +} + +void WavData::toLittleEndian(char* result,unsigned int content, int size) +{ + for(int i=0;i>= 8; + } + + return; +} + +char * WavData::read(ifstream* file,unsigned int size) +{ + char * c = new char[size+1]; + for(int i=0;iget(); + } + c[size]='\0'; + return c; +} + +bool WavData::comp(char* c1, char *c2, int size) +{ + for(int i=0;i"<< content << std::endl << "|"<"<put(mess[i]); + } +} + +int WavData::saveFormatBloc(ofstream* file) +{ + char b[13] = "RIFF WAVE"; + + toLittleEndian(b+4,_datasize+36,4); + + write(file,b,12); + + return 1; +} + +int WavData::saveDescriptionBloc(ofstream* file) +{ + char b[25] = "fmt "; + + toLittleEndian(b+4,0x10,4); + std::cout<<_audioFormat< +#include + +class WavData +{ + unsigned int _audioFormat; + unsigned int _nbrChanel; + unsigned int _frequency; + unsigned int _bytePerBloc; + unsigned int _bytePerSec; + unsigned int _bitsPerSample; + + char * _data; + unsigned int _datasize; +public: + WavData(); + + int load(char* s); + int save(char* s); + + unsigned int fromLittleEndian(char * content, int size); + char * toLittleEndian(unsigned int content, int size); + void toLittleEndian(char* result,unsigned int content, int size); + + inline unsigned int audioFormat(){return _audioFormat;} + inline unsigned int nbrChanel(){return _nbrChanel;} + inline unsigned int frequency(){return _frequency;} + inline unsigned int bytePerBloc(){return _bytePerBloc;} + inline unsigned int bytePerSec(){return _bytePerSec;} + inline unsigned int bitsPerSample(){return _bitsPerSample;} + inline unsigned int datasize(){return _datasize;} + inline char * data(){return _data;} + + inline void setAudioFormat(unsigned int a){_audioFormat=a;} + inline void setNbrChanel(unsigned int a){_nbrChanel=a;} + inline void setFrequency(unsigned int a){_frequency=a;} + inline void setBytePerBloc(unsigned int a){_bytePerBloc=a;} + inline void setBytePerSec(unsigned int a){_bytePerSec=a;} + inline void setBitsPerSample(unsigned int a){_bitsPerSample=a;} + inline void setData(char * a){_data=a;} + inline void clearData(){delete[] _data;_data=NULL;} + inline void setDatasize(unsigned int i){_datasize=i;} + +private: + int error(int,int); + int openFormatBloc(std::ifstream* file); + int openDescriptionBloc(std::ifstream *file); + int openDataBloc(std::ifstream *file); + + int saveFormatBloc(std::ofstream *file); + int saveDescriptionBloc(std::ofstream *file); + int saveDataBloc(std::ofstream *file); + + void write(std::ofstream *file,char* mess,unsigned int size); + char * read(std::ifstream* file,unsigned int size); + + bool comp(char* c1, char *c2, int size); + int testString(std::ifstream* file,char*compstr,int size,char *mess); + int testInt(std::ifstream* file,int size,char *mess,unsigned int *val=NULL); + +}; + +#endif // WAVDATA_H diff --git a/fftcow.cpp b/fftcow.cpp deleted file mode 100644 index d9c40c7..0000000 --- a/fftcow.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include "wavdata.h" -#include "fft.h" -#include - - -#define FREQ 22400 -#define AMPLITUDE 10 -#define FREQDO 261 -#define FREQLA 440 -#define SIZE FREQ*4 - - -int main(int argc, char **argv) -{ - float pi=3.141592; - WavData w; - - double test[SIZE][2]; - double test1[SIZE][2]; - double test2[SIZE][2]; - - char *data = new char[SIZE]; - char *data2 = new char[SIZE]; - - int i; - for(i=0;i -#include "wavdata.h" -#include "fft.h" -#include - -#define DELAY 5000 -#define AMPLITUDE 0.5 - -int main(int argc, char **argv) -{ - WavData w; - w.load("COW.WAV"); - - char *data = w.data(); - char *data2 = new char[w.datasize()*2]; - - int i; - for(i=0;i255)val=255; - if(val<0)val=0; - - data2[i]= (unsigned char)(unsigned int)val; - } - - w.clearData(); - w.setDatasize(w.datasize()*2); - w.setData(data2); - - w.save("COW_d.WAV"); -} diff --git a/main/COW.WAV b/main/COW.WAV new file mode 100644 index 0000000..6cc4f52 Binary files /dev/null and b/main/COW.WAV differ diff --git a/main/COW_d.WAV b/main/COW_d.WAV new file mode 100644 index 0000000..bae44ad Binary files /dev/null and b/main/COW_d.WAV differ diff --git a/main/fft.cpp b/main/fft.cpp new file mode 100644 index 0000000..92567e1 --- /dev/null +++ b/main/fft.cpp @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------- + fft.c - fast Fourier transform and its inverse (both recursively) + Copyright (C) 2004, Jerome R. Breitenbach. All rights reserved. + + The author gives permission to anyone to freely copy, distribute, and use + this file, under the following conditions: + - No changes are made. + - No direct commercial advantage is obtained. + - No liability is attributed to the author for any damages incurred. + ----------------------------------------------------------------------------*/ + +/****************************************************************************** + * This file defines a C function fft that, by calling another function * + * fft_rec (also defined), calculates an FFT recursively. Usage: * + * fft(N, x, X); * + * Parameters: * + * N: number of points in FFT (must equal 2^n for some integer n >= 1) * + * x: pointer to N time-domain samples given in rectangular form (Re x, * + * Im x) * + * X: pointer to N frequency-domain samples calculated in rectangular form * + * (Re X, Im X) * + * Similarly, a function ifft with the same parameters is defined that * + * calculates an inverse FFT (IFFT) recursively. Usage: * + * ifft(N, x, X); * + * Here, N and X are given, and x is calculated. * + ******************************************************************************/ + +#include +#include +#include "fft.h" +/* macros */ +#define TWO_PI (6.2831853071795864769252867665590057683943L) + +/* FFT */ +void fft(int N, double (*x)[2], double (*X)[2]) +{ + /* Declare a pointer to scratch space. */ + double (*XX)[2] = (double (*)[2]) malloc(2 * N * sizeof(double)); + + /* Calculate FFT by a recursion. */ + fft_rec(N, 0, 1, x, X, XX); + + /* Free memory. */ + free(XX); +} + +/* FFT recursion */ +void fft_rec(int N, int offset, int delta, + double (*x)[2], double (*X)[2], double (*XX)[2]) +{ + int N2 = N/2; /* half the number of points in FFT */ + int k; /* generic index */ + double cs, sn; /* cosine and sine */ + int k00, k01, k10, k11; /* indices for butterflies */ + double tmp0, tmp1; /* temporary storage */ + + if(N != 2) /* Perform recursive step. */ + { + /* Calculate two (N/2)-point DFT's. */ + fft_rec(N2, offset, 2*delta, x, XX, X); + fft_rec(N2, offset+delta, 2*delta, x, XX, X); + + /* Combine the two (N/2)-point DFT's into one N-point DFT. */ + for(k=0; k +#include "wavdata.h" +#include "fft.h" +#include + +#define DELAY 5000 +#define AMPLITUDE 0.5 + +int main(int argc, char **argv) +{ + WavData w; + w.load("COW.WAV"); + + char *data = w.data(); + char *data2 = new char[w.datasize()*2]; + + int i; + for(i=0;i255)val=255; + if(val<0)val=0; + + data2[i]= (unsigned char)(unsigned int)val; + } + + w.clearData(); + w.setDatasize(w.datasize()*2); + w.setData(data2); + + w.save("COW_d.WAV"); +} diff --git a/main/wavdata.cpp b/main/wavdata.cpp new file mode 100644 index 0000000..71642a7 --- /dev/null +++ b/main/wavdata.cpp @@ -0,0 +1,269 @@ +#include "wavdata.h" +#include + + +using namespace std; + +WavData::WavData() +{ + _data=NULL; +} + +int WavData::error(int i,int line) +{ + std::cerr << "Erreur "<<__FILE__<<" L"<=0;i--) + { + result *= 256; + result += (unsigned char)content[i]; + } + return result; +} + +char * WavData::toLittleEndian(unsigned int content, int size) +{ + char * result= new char [size*sizeof(char)]; + + for(int i=0;i>= 8; + } + + return result; +} + +void WavData::toLittleEndian(char* result,unsigned int content, int size) +{ + for(int i=0;i>= 8; + } + + return; +} + +char * WavData::read(ifstream* file,unsigned int size) +{ + char * c = new char[size+1]; + for(int i=0;iget(); + } + c[size]='\0'; + return c; +} + +bool WavData::comp(char* c1, char *c2, int size) +{ + for(int i=0;i"<< content << std::endl << "|"<"<put(mess[i]); + } +} + +int WavData::saveFormatBloc(ofstream* file) +{ + char b[13] = "RIFF WAVE"; + + toLittleEndian(b+4,_datasize+36,4); + + write(file,b,12); + + return 1; +} + +int WavData::saveDescriptionBloc(ofstream* file) +{ + char b[25] = "fmt "; + + toLittleEndian(b+4,0x10,4); + std::cout<<_audioFormat< +#include + +class WavData +{ + unsigned int _audioFormat; + unsigned int _nbrChanel; + unsigned int _frequency; + unsigned int _bytePerBloc; + unsigned int _bytePerSec; + unsigned int _bitsPerSample; + + char * _data; + unsigned int _datasize; +public: + WavData(); + + int load(char* s); + int save(char* s); + + unsigned int fromLittleEndian(char * content, int size); + char * toLittleEndian(unsigned int content, int size); + void toLittleEndian(char* result,unsigned int content, int size); + + inline unsigned int audioFormat(){return _audioFormat;} + inline unsigned int nbrChanel(){return _nbrChanel;} + inline unsigned int frequency(){return _frequency;} + inline unsigned int bytePerBloc(){return _bytePerBloc;} + inline unsigned int bytePerSec(){return _bytePerSec;} + inline unsigned int bitsPerSample(){return _bitsPerSample;} + inline unsigned int datasize(){return _datasize;} + inline char * data(){return _data;} + + inline void setAudioFormat(unsigned int a){_audioFormat=a;} + inline void setNbrChanel(unsigned int a){_nbrChanel=a;} + inline void setFrequency(unsigned int a){_frequency=a;} + inline void setBytePerBloc(unsigned int a){_bytePerBloc=a;} + inline void setBytePerSec(unsigned int a){_bytePerSec=a;} + inline void setBitsPerSample(unsigned int a){_bitsPerSample=a;} + inline void setData(char * a){_data=a;} + inline void clearData(){delete[] _data;_data=NULL;} + inline void setDatasize(unsigned int i){_datasize=i;} + +private: + int error(int,int); + int openFormatBloc(std::ifstream* file); + int openDescriptionBloc(std::ifstream *file); + int openDataBloc(std::ifstream *file); + + int saveFormatBloc(std::ofstream *file); + int saveDescriptionBloc(std::ofstream *file); + int saveDataBloc(std::ofstream *file); + + void write(std::ofstream *file,char* mess,unsigned int size); + char * read(std::ifstream* file,unsigned int size); + + bool comp(char* c1, char *c2, int size); + int testString(std::ifstream* file,char*compstr,int size,char *mess); + int testInt(std::ifstream* file,int size,char *mess,unsigned int *val=NULL); + +}; + +#endif // WAVDATA_H diff --git a/modifreq.WAV b/modifreq.WAV deleted file mode 100644 index 119a9b4..0000000 Binary files a/modifreq.WAV and /dev/null differ diff --git a/modifreq.cpp b/modifreq.cpp deleted file mode 100644 index b18cb1f..0000000 --- a/modifreq.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include "wavdata.h" -#include "fft.h" -#include - - -#define FREQ 22400 -#define AMPLITUDE 10 -#define FREQDO 261 -#define FREQLA 440 -#define SIZE FREQ*4 - - -int main(int argc, char **argv) -{ -//Definition variables - int i; - float pi=3.141592; - double test[SIZE][2]; - double test1[SIZE][2]; - double test2[SIZE][2]; - double test3[SIZE*2][2]; - char *data = new char[SIZE]; - char *data2 = new char[SIZE]; - WavData w; - -//Creation de la donnée - for(i=0;i -#include "wavdata.h" -#include "fft.h" -#include - -#define FREQ 48000 -#define AMPLITUDE 10 -#define FREQDO 261 -#define FREQLA 440 -#define SIZE FREQ*10 - - -int main(int argc, char **argv) -{ - float pi=3.141592; - WavData w; - - char *data = new char[SIZE]; - char *data2 = new char[SIZE]; - - int i; - for(i=0;i= 1) * + * x: pointer to N time-domain samples given in rectangular form (Re x, * + * Im x) * + * X: pointer to N frequency-domain samples calculated in rectangular form * + * (Re X, Im X) * + * Similarly, a function ifft with the same parameters is defined that * + * calculates an inverse FFT (IFFT) recursively. Usage: * + * ifft(N, x, X); * + * Here, N and X are given, and x is calculated. * + ******************************************************************************/ + +#include +#include +#include "fft.h" +/* macros */ +#define TWO_PI (6.2831853071795864769252867665590057683943L) + +/* FFT */ +void fft(int N, double (*x)[2], double (*X)[2]) +{ + /* Declare a pointer to scratch space. */ + double (*XX)[2] = (double (*)[2]) malloc(2 * N * sizeof(double)); + + /* Calculate FFT by a recursion. */ + fft_rec(N, 0, 1, x, X, XX); + + /* Free memory. */ + free(XX); +} + +/* FFT recursion */ +void fft_rec(int N, int offset, int delta, + double (*x)[2], double (*X)[2], double (*XX)[2]) +{ + int N2 = N/2; /* half the number of points in FFT */ + int k; /* generic index */ + double cs, sn; /* cosine and sine */ + int k00, k01, k10, k11; /* indices for butterflies */ + double tmp0, tmp1; /* temporary storage */ + + if(N != 2) /* Perform recursive step. */ + { + /* Calculate two (N/2)-point DFT's. */ + fft_rec(N2, offset, 2*delta, x, XX, X); + fft_rec(N2, offset+delta, 2*delta, x, XX, X); + + /* Combine the two (N/2)-point DFT's into one N-point DFT. */ + for(k=0; k +#include "wavdata.h" +#include "fft.h" +#include + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*10 + + +int main(int argc, char **argv) +{ + float pi=3.141592; + WavData w; + char *data = new char[SIZE]; + char *data2 = new char[SIZE]; + int i; + + //Creation de la données + for(i=0;i + + +using namespace std; + +WavData::WavData() +{ + _data=NULL; +} + +int WavData::error(int i,int line) +{ + std::cerr << "Erreur "<<__FILE__<<" L"<=0;i--) + { + result *= 256; + result += (unsigned char)content[i]; + } + return result; +} + +char * WavData::toLittleEndian(unsigned int content, int size) +{ + char * result= new char [size*sizeof(char)]; + + for(int i=0;i>= 8; + } + + return result; +} + +void WavData::toLittleEndian(char* result,unsigned int content, int size) +{ + for(int i=0;i>= 8; + } + + return; +} + +char * WavData::read(ifstream* file,unsigned int size) +{ + char * c = new char[size+1]; + for(int i=0;iget(); + } + c[size]='\0'; + return c; +} + +bool WavData::comp(char* c1, char *c2, int size) +{ + for(int i=0;i"<< content << std::endl << "|"<"<put(mess[i]); + } +} + +int WavData::saveFormatBloc(ofstream* file) +{ + char b[13] = "RIFF WAVE"; + + toLittleEndian(b+4,_datasize+36,4); + + write(file,b,12); + + return 1; +} + +int WavData::saveDescriptionBloc(ofstream* file) +{ + char b[25] = "fmt "; + + toLittleEndian(b+4,0x10,4); + std::cout<<_audioFormat< +#include + +class WavData +{ + unsigned int _audioFormat; + unsigned int _nbrChanel; + unsigned int _frequency; + unsigned int _bytePerBloc; + unsigned int _bytePerSec; + unsigned int _bitsPerSample; + + char * _data; + unsigned int _datasize; +public: + WavData(); + + int load(char* s); + int save(char* s); + + unsigned int fromLittleEndian(char * content, int size); + char * toLittleEndian(unsigned int content, int size); + void toLittleEndian(char* result,unsigned int content, int size); + + inline unsigned int audioFormat(){return _audioFormat;} + inline unsigned int nbrChanel(){return _nbrChanel;} + inline unsigned int frequency(){return _frequency;} + inline unsigned int bytePerBloc(){return _bytePerBloc;} + inline unsigned int bytePerSec(){return _bytePerSec;} + inline unsigned int bitsPerSample(){return _bitsPerSample;} + inline unsigned int datasize(){return _datasize;} + inline char * data(){return _data;} + + inline void setAudioFormat(unsigned int a){_audioFormat=a;} + inline void setNbrChanel(unsigned int a){_nbrChanel=a;} + inline void setFrequency(unsigned int a){_frequency=a;} + inline void setBytePerBloc(unsigned int a){_bytePerBloc=a;} + inline void setBytePerSec(unsigned int a){_bytePerSec=a;} + inline void setBitsPerSample(unsigned int a){_bitsPerSample=a;} + inline void setData(char * a){_data=a;} + inline void clearData(){delete[] _data;_data=NULL;} + inline void setDatasize(unsigned int i){_datasize=i;} + +private: + int error(int,int); + int openFormatBloc(std::ifstream* file); + int openDescriptionBloc(std::ifstream *file); + int openDataBloc(std::ifstream *file); + + int saveFormatBloc(std::ofstream *file); + int saveDescriptionBloc(std::ofstream *file); + int saveDataBloc(std::ofstream *file); + + void write(std::ofstream *file,char* mess,unsigned int size); + char * read(std::ifstream* file,unsigned int size); + + bool comp(char* c1, char *c2, int size); + int testString(std::ifstream* file,char*compstr,int size,char *mess); + int testInt(std::ifstream* file,int size,char *mess,unsigned int *val=NULL); + +}; + +#endif // WAVDATA_H diff --git a/purfreq2.WAV b/purfreq2.WAV deleted file mode 100644 index 39d6f6f..0000000 Binary files a/purfreq2.WAV and /dev/null differ diff --git a/purla.WAV b/purla.WAV deleted file mode 100644 index fe67473..0000000 Binary files a/purla.WAV and /dev/null differ diff --git a/strech/COW.WAV b/strech/COW.WAV new file mode 100644 index 0000000..6cc4f52 Binary files /dev/null and b/strech/COW.WAV differ diff --git a/strech/fft.cpp b/strech/fft.cpp new file mode 100644 index 0000000..92567e1 --- /dev/null +++ b/strech/fft.cpp @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------- + fft.c - fast Fourier transform and its inverse (both recursively) + Copyright (C) 2004, Jerome R. Breitenbach. All rights reserved. + + The author gives permission to anyone to freely copy, distribute, and use + this file, under the following conditions: + - No changes are made. + - No direct commercial advantage is obtained. + - No liability is attributed to the author for any damages incurred. + ----------------------------------------------------------------------------*/ + +/****************************************************************************** + * This file defines a C function fft that, by calling another function * + * fft_rec (also defined), calculates an FFT recursively. Usage: * + * fft(N, x, X); * + * Parameters: * + * N: number of points in FFT (must equal 2^n for some integer n >= 1) * + * x: pointer to N time-domain samples given in rectangular form (Re x, * + * Im x) * + * X: pointer to N frequency-domain samples calculated in rectangular form * + * (Re X, Im X) * + * Similarly, a function ifft with the same parameters is defined that * + * calculates an inverse FFT (IFFT) recursively. Usage: * + * ifft(N, x, X); * + * Here, N and X are given, and x is calculated. * + ******************************************************************************/ + +#include +#include +#include "fft.h" +/* macros */ +#define TWO_PI (6.2831853071795864769252867665590057683943L) + +/* FFT */ +void fft(int N, double (*x)[2], double (*X)[2]) +{ + /* Declare a pointer to scratch space. */ + double (*XX)[2] = (double (*)[2]) malloc(2 * N * sizeof(double)); + + /* Calculate FFT by a recursion. */ + fft_rec(N, 0, 1, x, X, XX); + + /* Free memory. */ + free(XX); +} + +/* FFT recursion */ +void fft_rec(int N, int offset, int delta, + double (*x)[2], double (*X)[2], double (*XX)[2]) +{ + int N2 = N/2; /* half the number of points in FFT */ + int k; /* generic index */ + double cs, sn; /* cosine and sine */ + int k00, k01, k10, k11; /* indices for butterflies */ + double tmp0, tmp1; /* temporary storage */ + + if(N != 2) /* Perform recursive step. */ + { + /* Calculate two (N/2)-point DFT's. */ + fft_rec(N2, offset, 2*delta, x, XX, X); + fft_rec(N2, offset+delta, 2*delta, x, XX, X); + + /* Combine the two (N/2)-point DFT's into one N-point DFT. */ + for(k=0; k +#include "wavdata.h" +#include "fft.h" +#include + + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*2 + + +int main(int argc, char **argv) +{ +//Definition variables + int i,j; + float pi=3.141592; + double test[SIZE*2][2]; + double test2[SIZE*2][2]; + double test1[SIZE*2][2]; + double test3[SIZE*2][2]; + + char *data2 = new char[SIZE]; + WavData w; + +//Creation de la donnée + printf("===Creation data\n"); + for(i=0;i +#include "wavdata.h" +#include "fft.h" +#include + + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*4 + + +int main(int argc, char **argv) +{ +//Definition variables + int i; + float pi=3.141592; + double test[SIZE][2]; + double test1[SIZE][2]; + double test2[SIZE][2]; + double test3[SIZE*2][2]; + char *data = new char[SIZE]; + char *data2 = new char[SIZE]; + WavData w; + +//Creation de la donnée + for(i=0;i +#include "wavdata.h" +#include "fft.h" +#include + + +#define FREQ 22400 +#define AMPLITUDE 10 +#define FREQDO 261 +#define FREQLA 440 +#define SIZE FREQ*2 + + +int main(int argc, char **argv) +{ +//Definition variables + int i; + float pi=3.141592; + WavData w; + w.load("COW.WAV"); + char *data = w.data(); + double test[w.datasize()*2][2]; + double test1[w.datasize()*2][2]; + double test2[w.datasize()*2][2]; + double test3[w.datasize()*2][2]; + + + printf("===Création data\n"); +//Creation de la donnée + char *data2 = new char[w.datasize()*2]; + printf("===load success\n"); + + for(i=0;i + + +using namespace std; + +WavData::WavData() +{ + _data=NULL; +} + +int WavData::error(int i,int line) +{ + std::cerr << "Erreur "<<__FILE__<<" L"<=0;i--) + { + result *= 256; + result += (unsigned char)content[i]; + } + return result; +} + +char * WavData::toLittleEndian(unsigned int content, int size) +{ + char * result= new char [size*sizeof(char)]; + + for(int i=0;i>= 8; + } + + return result; +} + +void WavData::toLittleEndian(char* result,unsigned int content, int size) +{ + for(int i=0;i>= 8; + } + + return; +} + +char * WavData::read(ifstream* file,unsigned int size) +{ + char * c = new char[size+1]; + for(int i=0;iget(); + } + c[size]='\0'; + return c; +} + +bool WavData::comp(char* c1, char *c2, int size) +{ + for(int i=0;i"<< content << std::endl << "|"<"<put(mess[i]); + } +} + +int WavData::saveFormatBloc(ofstream* file) +{ + char b[13] = "RIFF WAVE"; + + toLittleEndian(b+4,_datasize+36,4); + + write(file,b,12); + + return 1; +} + +int WavData::saveDescriptionBloc(ofstream* file) +{ + char b[25] = "fmt "; + + toLittleEndian(b+4,0x10,4); + std::cout<<_audioFormat< +#include + +class WavData +{ + unsigned int _audioFormat; + unsigned int _nbrChanel; + unsigned int _frequency; + unsigned int _bytePerBloc; + unsigned int _bytePerSec; + unsigned int _bitsPerSample; + + char * _data; + unsigned int _datasize; +public: + WavData(); + + int load(char* s); + int save(char* s); + + unsigned int fromLittleEndian(char * content, int size); + char * toLittleEndian(unsigned int content, int size); + void toLittleEndian(char* result,unsigned int content, int size); + + inline unsigned int audioFormat(){return _audioFormat;} + inline unsigned int nbrChanel(){return _nbrChanel;} + inline unsigned int frequency(){return _frequency;} + inline unsigned int bytePerBloc(){return _bytePerBloc;} + inline unsigned int bytePerSec(){return _bytePerSec;} + inline unsigned int bitsPerSample(){return _bitsPerSample;} + inline unsigned int datasize(){return _datasize;} + inline char * data(){return _data;} + + inline void setAudioFormat(unsigned int a){_audioFormat=a;} + inline void setNbrChanel(unsigned int a){_nbrChanel=a;} + inline void setFrequency(unsigned int a){_frequency=a;} + inline void setBytePerBloc(unsigned int a){_bytePerBloc=a;} + inline void setBytePerSec(unsigned int a){_bytePerSec=a;} + inline void setBitsPerSample(unsigned int a){_bitsPerSample=a;} + inline void setData(char * a){_data=a;} + inline void clearData(){delete[] _data;_data=NULL;} + inline void setDatasize(unsigned int i){_datasize=i;} + +private: + int error(int,int); + int openFormatBloc(std::ifstream* file); + int openDescriptionBloc(std::ifstream *file); + int openDataBloc(std::ifstream *file); + + int saveFormatBloc(std::ofstream *file); + int saveDescriptionBloc(std::ofstream *file); + int saveDataBloc(std::ofstream *file); + + void write(std::ofstream *file,char* mess,unsigned int size); + char * read(std::ifstream* file,unsigned int size); + + bool comp(char* c1, char *c2, int size); + int testString(std::ifstream* file,char*compstr,int size,char *mess); + int testInt(std::ifstream* file,int size,char *mess,unsigned int *val=NULL); + +}; + +#endif // WAVDATA_H diff --git a/test b/test deleted file mode 100644 index fe9eae3..0000000 Binary files a/test and /dev/null differ diff --git a/test.WAV b/test.WAV deleted file mode 100644 index a61f5de..0000000 Binary files a/test.WAV and /dev/null differ diff --git a/test.cpp b/test.cpp deleted file mode 100644 index 49f84db..0000000 --- a/test.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include "wavdata.h" -#include "fft.h" -#include - -#define FREQ 48000 -#define AMPLITUDE 10 -#define FREQDO 261 -#define FREQLA 440 -#define SIZE FREQ*1 - - -int main(int argc, char **argv) -{ - WavData w; - int pi=3.14; - char *data = new char[SIZE]; - - - WavData w1; - w1.load("COW.WAV"); - char *dat = w1.data(); - - int i; - for(i=0;i - - -using namespace std; - -WavData::WavData() -{ - _data=NULL; -} - -int WavData::error(int i,int line) -{ - std::cerr << "Erreur "<<__FILE__<<" L"<=0;i--) - { - result *= 256; - result += (unsigned char)content[i]; - } - return result; -} - -char * WavData::toLittleEndian(unsigned int content, int size) -{ - char * result= new char [size*sizeof(char)]; - - for(int i=0;i>= 8; - } - - return result; -} - -void WavData::toLittleEndian(char* result,unsigned int content, int size) -{ - for(int i=0;i>= 8; - } - - return; -} - -char * WavData::read(ifstream* file,unsigned int size) -{ - char * c = new char[size+1]; - for(int i=0;iget(); - } - c[size]='\0'; - return c; -} - -bool WavData::comp(char* c1, char *c2, int size) -{ - for(int i=0;i"<< content << std::endl << "|"<"<put(mess[i]); - } -} - -int WavData::saveFormatBloc(ofstream* file) -{ - char b[13] = "RIFF WAVE"; - - toLittleEndian(b+4,_datasize+36,4); - - write(file,b,12); - - return 1; -} - -int WavData::saveDescriptionBloc(ofstream* file) -{ - char b[25] = "fmt "; - - toLittleEndian(b+4,0x10,4); - std::cout<<_audioFormat< -#include - -class WavData -{ - unsigned int _audioFormat; - unsigned int _nbrChanel; - unsigned int _frequency; - unsigned int _bytePerBloc; - unsigned int _bytePerSec; - unsigned int _bitsPerSample; - - char * _data; - unsigned int _datasize; -public: - WavData(); - - int load(char* s); - int save(char* s); - - unsigned int fromLittleEndian(char * content, int size); - char * toLittleEndian(unsigned int content, int size); - void toLittleEndian(char* result,unsigned int content, int size); - - inline unsigned int audioFormat(){return _audioFormat;} - inline unsigned int nbrChanel(){return _nbrChanel;} - inline unsigned int frequency(){return _frequency;} - inline unsigned int bytePerBloc(){return _bytePerBloc;} - inline unsigned int bytePerSec(){return _bytePerSec;} - inline unsigned int bitsPerSample(){return _bitsPerSample;} - inline unsigned int datasize(){return _datasize;} - inline char * data(){return _data;} - - inline void setAudioFormat(unsigned int a){_audioFormat=a;} - inline void setNbrChanel(unsigned int a){_nbrChanel=a;} - inline void setFrequency(unsigned int a){_frequency=a;} - inline void setBytePerBloc(unsigned int a){_bytePerBloc=a;} - inline void setBytePerSec(unsigned int a){_bytePerSec=a;} - inline void setBitsPerSample(unsigned int a){_bitsPerSample=a;} - inline void setData(char * a){_data=a;} - inline void clearData(){delete[] _data;_data=NULL;} - inline void setDatasize(unsigned int i){_datasize=i;} - -private: - int error(int,int); - int openFormatBloc(std::ifstream* file); - int openDescriptionBloc(std::ifstream *file); - int openDataBloc(std::ifstream *file); - - int saveFormatBloc(std::ofstream *file); - int saveDescriptionBloc(std::ofstream *file); - int saveDataBloc(std::ofstream *file); - - void write(std::ofstream *file,char* mess,unsigned int size); - char * read(std::ifstream* file,unsigned int size); - - bool comp(char* c1, char *c2, int size); - int testString(std::ifstream* file,char*compstr,int size,char *mess); - int testInt(std::ifstream* file,int size,char *mess,unsigned int *val=NULL); - -}; - -#endif // WAVDATA_H -- libgit2 0.21.2