From 6c227d28a0e93eb8cfb3d0517fcd5e8d0be12f1c Mon Sep 17 00:00:00 2001 From: rsimonin Date: Fri, 4 Dec 2020 13:54:29 +0100 Subject: [PATCH] premier push --- .vscode/c_cpp_properties.json | 20 ++++++++++++++++++++ .vscode/launch.json | 19 +++++++++++++++++++ COW.WAV | Bin 0 -> 45612 bytes COW_d.WAV | Bin 0 -> 91180 bytes TP_TIM.pdf | Bin 0 -> 165110 bytes com.WAV | Bin 0 -> 384044 bytes cowfft.WAV | Bin 0 -> 89644 bytes fft.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fft.h | 10 ++++++++++ fftcow.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ modifreq.WAV | Bin 0 -> 89644 bytes modifreq.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pur.WAV | Bin 0 -> 48044 bytes pur.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ purfreq2.WAV | Bin 0 -> 384044 bytes purla.WAV | Bin 0 -> 480044 bytes readme | 15 +++++++++++++++ test | Bin 0 -> 25024 bytes test.WAV | Bin 0 -> 96044 bytes test.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test2.WAV | Bin 0 -> 48044 bytes testWAV.pro | 12 ++++++++++++ wavdata.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ wavdata.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 25 files changed, 830 insertions(+), 0 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 COW.WAV create mode 100644 COW_d.WAV create mode 100644 TP_TIM.pdf create mode 100644 com.WAV create mode 100644 cowfft.WAV create mode 100644 fft.cpp create mode 100644 fft.h create mode 100644 fftcow.cpp create mode 100644 main.cpp create mode 100644 modifreq.WAV create mode 100644 modifreq.cpp create mode 100644 pur.WAV create mode 100644 pur.cpp create mode 100644 purfreq2.WAV create mode 100644 purla.WAV create mode 100644 test create mode 100644 test.WAV create mode 100644 test.cpp create mode 100644 test2.WAV create mode 100644 testWAV.pro create mode 100644 wavdata.cpp create mode 100644 wavdata.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..3eb6ef5 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:\\Users\\simon\\OneDrive\\Bureau\\TP6son" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4656989 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Lancer", + "type": "cppvsdbg", + "request": "launch", + "program": "entrer le nom du programme, par exemple ${workspaceFolder}/a.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false + } + ] +} \ No newline at end of file diff --git a/COW.WAV b/COW.WAV new file mode 100644 index 0000000..6cc4f52 Binary files /dev/null and b/COW.WAV differ diff --git a/COW_d.WAV b/COW_d.WAV new file mode 100644 index 0000000..bae44ad Binary files /dev/null and b/COW_d.WAV differ diff --git a/TP_TIM.pdf b/TP_TIM.pdf new file mode 100644 index 0000000..bd2a77d Binary files /dev/null and b/TP_TIM.pdf differ diff --git a/com.WAV b/com.WAV new file mode 100644 index 0000000..39d6f6f Binary files /dev/null and b/com.WAV differ diff --git a/cowfft.WAV b/cowfft.WAV new file mode 100644 index 0000000..54a5d23 Binary files /dev/null and b/cowfft.WAV differ diff --git a/fft.cpp b/fft.cpp new file mode 100644 index 0000000..92567e1 --- /dev/null +++ b/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*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/modifreq.WAV b/modifreq.WAV new file mode 100644 index 0000000..119a9b4 Binary files /dev/null and b/modifreq.WAV differ diff --git a/modifreq.cpp b/modifreq.cpp new file mode 100644 index 0000000..b18cb1f --- /dev/null +++ b/modifreq.cpp @@ -0,0 +1,69 @@ +#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 +#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