diff --git a/.main.cpp.swp b/.main.cpp.swp new file mode 100644 index 0000000..2191455 Binary files /dev/null and b/.main.cpp.swp differ 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/DO.WAV b/DO.WAV new file mode 100644 index 0000000..7952f97 Binary files /dev/null and b/DO.WAV differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b7eed0b --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ + +CC = g++ +FLAGS = -c +OBJECTS = $(SOURDES:.cpp=.o) + +TARGET = clavier + +$(TARGET) : $(OBJECTS) + +all: $(TARGET) + +clean: + rm -f core *.o $(TARGET) + + + + 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 DELAY 5000 +#define TOUCH 15000 +#define AMPLITUDE 0.5 + +int main(int argc, char **argv) +{ + /*WavData w; + char * name = "COW.WAV"; + w.load(name); + + 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); + + char * name_save = "COW_d.WAV"; + w.save(name_save);*/ + + + // recréer une note ) partir du son de la vache + + WavData note_do; + note_do.load("COW.WAV"); + char * data_do = note_do.data(); + + // TOUCH = durée d'une note + int size = note_do.datasize(); + if (size > TOUCH) size = TOUCH; + + // changer le son pour avoir une note approprié + + int i; + for (i = 0; i < size ; i++) { + data_do[i] = i; + } + + // assign new data & save + + note_do.clearData(); + note_do.setDatasize(size); + note_do.setData(data_do); + + note_do.save("DO.WAV"); + + +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..e183827 Binary files /dev/null and b/main.o differ diff --git a/task.txt b/task.txt new file mode 100644 index 0000000..20b2fbf --- /dev/null +++ b/task.txt @@ -0,0 +1 @@ +Realiser un clavier de piano sur les touches pour avoir le son de vach pour chaque note musicale diff --git a/test b/test new file mode 100755 index 0000000..06dd734 Binary files /dev/null and b/test differ diff --git a/testWAV.pro b/testWAV.pro new file mode 100644 index 0000000..d2d7879 --- /dev/null +++ b/testWAV.pro @@ -0,0 +1,12 @@ +###################################################################### +# Automatically generated by qmake (2.01a) lun. mai 9 11:16:11 2011 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +HEADERS += fft.h wavdata.h +SOURCES += fft.cpp main.cpp wavdata.cpp diff --git a/wavdata.cpp b/wavdata.cpp new file mode 100644 index 0000000..2130077 --- /dev/null +++ b/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; +} + +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 << "|"<"<>= 8; + } + + return; +} + +void WavData::write(ofstream *file,char* mess,unsigned int size) +{ + for(int i=0;iput(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/wavdata.o b/wavdata.o new file mode 100644 index 0000000..b888219 Binary files /dev/null and b/wavdata.o differ -- libgit2 0.21.2