Initial commit

This commit is contained in:
Phyks 2013-07-28 15:20:57 +02:00
commit a3d7b77c66
23 changed files with 3811089 additions and 0 deletions

17
gadget Normal file
View File

@ -0,0 +1,17 @@
20
220
247
262
294
330:2
262
311
247
294
262:2
220
247
262
294
330:2
262

BIN
gadget.wav Normal file

Binary file not shown.

119
generateur.c Normal file
View File

@ -0,0 +1,119 @@
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
# include "math.h"
# include "wave_stuff.h"
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
# define TAILLE_MAX 100
char **str_split (char *s, const char *ct)
{
char **tab = NULL;
if (s != NULL && ct != NULL)
{
int i;
char *cs = NULL;
size_t size = 1;
/* (1) */
for (i = 0; (cs = strtok (s, ct)); i++)
{
if (size <= i + 1)
{
void *tmp = NULL;
/* (2) */
size <<= 1;
tmp = realloc (tab, sizeof (*tab) * size);
if (tmp != NULL)
{
tab = tmp;
}
else
{
fprintf (stderr, "Memoire insuffisante\n");
free (tab);
tab = NULL;
exit (EXIT_FAILURE);
}
}
/* (3) */
tab[i] = cs;
s = NULL;
}
tab[i] = NULL;
}
return tab;
}
void generer_note(int freq, int note, int duree, float *xd, int start)
{
int i;
for (i = start; i < start+duree; i++)
{
xd[i] += (int)(32767 *sin(2*M_PI*note*i/freq));
}
}
int main(int argc, char **argv)
{
if (argc < 5)
{
fprintf(stderr,"Usage: %s partition output.wav bpm silence\n",argv[0]);
return 0;
}
float *xd;
int nx = 0, freq = 44100, canal = 0, verbose = 0, BitsPerSample = 16, dureeNote = 0, start = 0, n = 0, silence, Split1, Split2;
float time = 1./atof(argv[3])*60.;
char ligne[TAILLE_MAX];
FILE* partition = NULL;
partition = fopen(argv[1], "r");
fgets(ligne, TAILLE_MAX, partition);
n = atoi(ligne);
silence = atoi(argv[4]);
if(silence == 1)
{
nx = (int)(freq*time*(n+n/8));
}
else
{
nx = (int)(freq*time*n);
}
dureeNote = (int)(freq*time);
xd = (float*)calloc(nx,sizeof(float));
while(fgets(ligne, TAILLE_MAX, partition) != NULL)
{
if(strchr(ligne, ':')!=NULL)
{
char** Split=str_split(ligne, ":");
Split1=atoi(Split[0]);
Split2=atoi(Split[1]);
}
else
{
Split1=atoi(ligne);
Split2=1;
}
generer_note(freq, Split1, Split2*dureeNote, xd, start);
start += Split2*dureeNote;
if(silence == 1)
{
generer_note(freq, 0, (int)(Split2*dureeNote/8), xd, start);
start += (int)(Split2*dureeNote/8);
}
}
save_wave_from_array(xd, nx, argv[2], freq, BitsPerSample);
return 0;
}

BIN
generateur.out Executable file

Binary file not shown.

79
generer_partition.c Normal file
View File

@ -0,0 +1,79 @@
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
int main()
{
char note[100];
int stop = 0, duree = 0;
while(stop == 0)
{
printf("Note ? ");
scanf("%s", note);
printf("Durée ? ");
scanf("%d", duree);
switch(note)
{
case "RE":
printf("294:%d\n",duree);
break;
case "MI":
printf("330:%d\n",duree);
break;
case "FA":
printf("349:%d\n",duree);
break;
case "SOL":
printf("392:%d\n",duree);
break;
case "LA":
printf("440:%d\n",duree);
break;
case "SI":
printf("494:%d\n",duree);
break;
case "DO":
printf("523:%d\n",duree);
break;
case "RE2":
printf("587:%d\n",duree);
break;
case "MI2":
printf("659:%d\n",duree);
break;
case "FA2":
printf("699:%d\n",duree);
break;
case "SOL2":
printf("794:%d\n",duree);
break;
case "LA2":
printf("880:%d\n",duree);
break;
case "SI2":
printf("988:%d\n",duree);
break;
default:
stop = 1;
break;
}
}
return 0;
}

45
lune Normal file
View File

@ -0,0 +1,45 @@
64
523
523
523
587
659:2
587:2
523
659
587
587
523:4
523
523
523
587
659:2
587:2
523
659
587
587
523:4
587
587
587
587
440:2
440:2
587
523
494
440
392:4
523
523
523
587
659:2
587:2
523
659
587
587
523:4

BIN
lune.wav Normal file

Binary file not shown.

9
makefile Normal file
View File

@ -0,0 +1,9 @@
all : generateur.out
generateur.out : generateur.c wave_stuff.o
gcc -lm -o generateur.out generateur.c wave_stuff.o
wave_stuff.o : wave_stuff.c wave_stuff.h
gcc -c wave_stuff.c

Binary file not shown.

BIN
output.wav Normal file

Binary file not shown.

35
read_wav.c Normal file
View File

@ -0,0 +1,35 @@
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
# include "wave_stuff.h"
int main(int argc, char **argv)
{
float *xd;
int i, freq = 0, nx = 0, canal = 0, verbose = 0;
if (argc < 3)
{
fprintf(stderr,"Usage: %s wavefile canal [verbose]\nExample %s d:\\low.wav 1\n",argv[0],argv[0]);
return 0;
}
if (sscanf(argv[2],"%d",&canal) != 1)
{
fprintf(stderr,"cannot read canal value %s\n",argv[2]);
return 1;
}
if (argc > 3) sscanf(argv[3],"%d",&verbose);
xd = read_wave_create_array(argv[1], canal, verbose, &nx, &freq);
if (xd == NULL)
{
fprintf(stderr,"cannot read canal wave file %s\n",argv[1]);
return 2;
}
printf("%% %s wave file, canal %d, frequence %d, nb. of sample %d\n",argv[1],canal,freq,nx);
for (i = 0; i < nx; i++)
printf("%d\n",(int)xd[i]);
return 0;
}

BIN
read_wav.out Normal file

Binary file not shown.

47
sapin Normal file
View File

@ -0,0 +1,47 @@
80
392
523:2
523
523:3
587:2
659:2
659
659:2
523
587
659
699:2
523:2
587:2
523:4
784
784
659
880:2
784
784
699
699:4
699
699:2
784
587:2
699
699:2
659
659:4
392
523:2
523
523:3
587:2
659:2
659
659:2
523
587
659
699:2
523:2
587:2
523:4

BIN
sapin.wav Normal file

Binary file not shown.

77
save_wav.c Normal file
View File

@ -0,0 +1,77 @@
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
# include "wave_stuff.h"
# define MAX_LINE_LENGTH 1024
int main(int argc, char **argv)
{
char line[MAX_LINE_LENGTH], *l;
float *xd = NULL;
int i, freq = 0, nx = 0, canal = 0, BitsPerSample = 16, data, min, max;
FILE *fp;
if (argc < 4)
{
fprintf(stderr,"Usage: %s wave_data.txt wavefile_to_create.wav frequency BitsPerSample\nExample %s d:\\low.wav 44100 16\n",argv[0],argv[0]);
return 0;
}
if ((fp = fopen(argv[1], "r")) == NULL)
{
fprintf(stderr,"cannot open file %s\n",argv[1]);
return 1;
}
if (sscanf(argv[3],"%d",&freq) != 1)
{
fprintf(stderr,"cannot read freq value %s\n",argv[3]);
return 1;
}
if (argc > 4) sscanf(argv[4],"%d",&BitsPerSample);
for(nx = 0, l = fgets(line, MAX_LINE_LENGTH, fp); l != NULL; l = fgets(line, MAX_LINE_LENGTH, fp))
{
if (strcspn(line,"%") >= strlen(line))
{
if (sscanf(line,"%d",&data) == 1)
nx++;
}
}
fclose(fp);
if (nx <= 0)
{
fprintf(stderr,"could not read data");
return 2;
}
xd = (float*)calloc(nx,sizeof(float));
if (xd == NULL)
{
fprintf(stderr,"could not create float array");
return 2;
}
min = max = 0;
fp = fopen(argv[1], "r");
for(i = 0, l = fgets(line, MAX_LINE_LENGTH, fp); l != NULL; l = fgets(line, MAX_LINE_LENGTH, fp))
{
if (strcspn(line,"%") >= strlen(line))
{
if (sscanf(line,"%d",&data) == 1)
{
xd[i] = (float)data;
i++;
}
}
}
fclose(fp);
printf("%d sample read\n",nx);
i = save_wave_from_array(xd, nx, argv[2], freq, BitsPerSample);
if (i)
{
fprintf(stderr,"cannot save wave file %s\n",argv[2]);
return 2;
}
free(xd);
return 0;
}

BIN
test.wav Normal file

Binary file not shown.

3810243
test.wav.txt Normal file

File diff suppressed because it is too large Load Diff

96
vivelevent Normal file
View File

@ -0,0 +1,96 @@
130
392
659
587
523
392:3
392
392
659
587
523
440:3
440
440
699
659
587
794:3
794
699
794
699
587
659:4
392
659
587
523
392:3
392
392
659
587
523
440:3
440
440
699
659
587
794:2
794
794
699
794
699
587
523:2
794:2
659
659
659:2
659
659
659:2
659
794
523
587
659:4
699
699
699:2
659
659
659:2
587
587
587
659
587:2
794:2
659
659
659:2
659
659
659:2
659
794
523
587
659:4
699
699
699
699
659
659
659
659
794
794
699
587
523:4

BIN
vivelevent.wav Normal file

Binary file not shown.

48
vivelevent2 Normal file
View File

@ -0,0 +1,48 @@
71
554
554
554:2
554
554
554:2
554
659
440
494
554:2
587
587
587:2
587
587
554
554:2
494
494:2
554
494
659:2
554
554
554:2
554
554
554:2
554
659
440
494
554:2
587
587
587
587
587:2
554
554:2
554
659
659
587
494:2
440:2

BIN
vivelevent2.wav Normal file

Binary file not shown.

247
wave_stuff.c Normal file
View File

@ -0,0 +1,247 @@
# ifndef _WAVE_STUFF_C_
# define _WAVE_STUFF_C_
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
# include "wave_stuff.h"
int save_wave_from_array(float *x, int nx, char *file, int Frequence, int BitsPerSample)
{
FILE *fp;
unsigned char *uch;
int i, j, FileSize, tmp, BytePerSec, DataSize, data, noctets;
short int AudioFormat = 1, NbrCanaux = 1, BytePerBloc, BitsPerSamp;
if (file == NULL || x == NULL) return -1;
noctets = BitsPerSample/8;
BytePerBloc = (NbrCanaux * BitsPerSample/8);
DataSize = nx * BytePerBloc;
FileSize = DataSize + 44;
BytePerSec = Frequence * BytePerBloc;
BitsPerSamp = (short int)BitsPerSample;
fp = fopen(file,"wb");
if (fp == NULL) {fprintf(stderr,"could not open file %s to save wav",file);return 1;}
// [Bloc de déclaration d'un fichier au format WAVE] 12 octets
if (fwrite("RIFF",sizeof(char),4,fp) != 4) {fclose(fp); return 2;}
if (fwrite(&FileSize,sizeof(int),1,fp) != 1) {fclose(fp); return 3;}
if (fwrite("WAVE",sizeof(char),4,fp) != 4) {fclose(fp); return 4;}
// [Bloc décrivant le format audio] 24 octets
if (fwrite("fmt ",sizeof(char),4,fp) != 4) {fclose(fp); return 5;}
tmp = 16; //Nombre d'octets du bloc - 8 (0x10)
if (fwrite(&tmp,sizeof(int),1,fp) != 1) {fclose(fp); return 6;}
if (fwrite(&AudioFormat,sizeof(short int),1,fp) != 1)
{fclose(fp); return 7;}
if (fwrite(&NbrCanaux,sizeof(short int),1,fp) != 1)
{fclose(fp); return 8;}
if (fwrite(&Frequence,sizeof(int),1,fp) != 1) {fclose(fp); return 9;}
if (fwrite(&BytePerSec,sizeof(int),1,fp) != 1) {fclose(fp); return 10;}
if (fwrite(&BytePerBloc,sizeof(short int),1,fp) != 1)
{fclose(fp); return 11;}
if (fwrite(&BitsPerSamp,sizeof(short int),1,fp) != 1)
{fclose(fp); return 12;}
// [Bloc des données] 8 octets + datasize
if (fwrite("data",sizeof(char),4,fp) != 4) {fclose(fp); return 13;}
if (fwrite(&DataSize,sizeof(int),1,fp) != 1) {fclose(fp); return 14;}
for (j = 0, uch = (unsigned char*)&data; j < nx; j++)
{
data = (int)x[j];
if (fwrite(uch,sizeof(unsigned char),noctets,fp) != noctets)
{fclose(fp); return j;}
}
fclose(fp);
return 0;
}
float* read_wave_create_array(char *file, int canal, int verbose, int *ny, int *freq)
{
FILE *fp;
char ch[16];
unsigned char uch[4];
int i, j, FileSize, BytePerSec, DataSize, nx, data, noctets;
short int AudioFormat = 1, NbrCanaux, BytePerBloc, BitsPerSamp, si;
int Frequence, offset, cont;
float *xd;
if (file == NULL) return NULL;
fp = fopen(file,"rb");
if (fp == NULL)
{ fprintf(stderr,"could not open file %s to read wav",file); return NULL;}
// [Bloc de déclaration d'un fichier au format WAVE] 12 octets
if (fread(ch,sizeof(char),4,fp) != 4) // read 4
{ fclose(fp); fprintf(stderr,"could not read RIFF label"); return NULL; }
if (strncmp(ch,"RIFF",4) != 0)
{ fclose(fp); fprintf(stderr,"could not read RIFF tag"); return NULL; }
if (fread(&FileSize,sizeof(int),1,fp) != 1) // read 4
{ fclose(fp); fprintf(stderr,"could not read File size"); return NULL;}
if (verbose) fprintf(stderr,"file size %d",FileSize);
if (fread(ch,sizeof(char),4,fp) != 4) // read 4
{ fclose(fp); fprintf(stderr,"could not read WAVE label"); return NULL; }
if (strncmp(ch,"WAVE",4) != 0)
{ fclose(fp); fprintf(stderr,"could not read WAVE tag"); return NULL; }
// [Bloc décrivant le format audio] 24 octets
if (fread(ch,sizeof(char),4,fp) != 4) // read 4
{ fclose(fp); fprintf(stderr,"could not read fmt label"); return NULL; }
if (strncmp(ch,"fmt ",4) != 0)
{ fclose(fp); fprintf(stderr,"could not read fmt tag"); return NULL; }
if (fread(&offset,sizeof(int),1,fp) != 1) // read 4
{ fclose(fp); fprintf(stderr,"could not read offset"); return NULL; }
if (verbose) fprintf(stderr,"offset %d",offset); // read 4
if (fread(&AudioFormat,sizeof(short int),1,fp) != 1) // read 2
{ fclose(fp); fprintf(stderr,"could not read Audio format"); return NULL;}
if (fread(&NbrCanaux,sizeof(short int),1,fp) != 1) // read 2
{ fclose(fp); fprintf(stderr,"could not read Nb. of canaux"); return NULL;}
if (verbose) fprintf(stderr,"NbrCanaux %d",(int)NbrCanaux); // read 4
if (fread(&Frequence,sizeof(int),1,fp) != 1)
{ fclose(fp); fprintf(stderr,"could not read Frequence"); return NULL; }
if (verbose) fprintf(stderr,"Frequence %d",Frequence); // read 4
if (fread(&BytePerSec,sizeof(int),1,fp) != 1)
{ fclose(fp); fprintf(stderr,"could not read BytePerSec"); return NULL;}
if (verbose) fprintf(stderr,"BytePerSec %d",BytePerSec);
if (fread(&BytePerBloc,sizeof(short int),1,fp) != 1) // read 2
{ fclose(fp); fprintf(stderr,"could not read BytePerSec"); return NULL; }
if (verbose) fprintf(stderr,"BytePerBloc %d",(int)BytePerBloc);
if (fread(&BitsPerSamp,sizeof(short int),1,fp) != 1) // read 2
{ fclose(fp); fprintf(stderr,"could not read BitsPerSamp"); return NULL; }
if (verbose) fprintf(stderr,"BitsPerSamp %d",(int)BitsPerSamp);
// [Bloc des données] 8 octets + datasize
if (fread(ch,sizeof(char),4,fp) != 4) // read 4
{ fclose(fp); fprintf(stderr,"could not read data label"); return NULL;}
if (strncmp(ch,"LIST",4) == 0)
{
if (fread(&offset,sizeof(int),1,fp) != 1) // read 4
{ fclose(fp); fprintf(stderr,"could not read offset"); }
if (verbose) fprintf(stderr,"found list block skipping %d bytes",offset);
for (i = 0; i < offset; i++)
{
if (fread(ch,sizeof(char),1,fp) != 1)
{ fclose(fp); fprintf(stderr,"could not read data"); return NULL;}
}
if (fread(ch,sizeof(char),4,fp) != 4) // read 4
{ fclose(fp); fprintf(stderr,"could not read data label"); return NULL;}
}
if (strncmp(ch,"data",4) != 0)
{
ch[4] = 0;
cont = 0;
fprintf(stderr,"could not read data tag!\n read %s instead "
"\ntype 1 to continue anything else to stop",ch);
scanf("%d",&cont);
if (cont == 1)
{
fclose(fp);
return NULL;
}
}
if (fread(&DataSize,sizeof(int),1,fp) != 1) // read 4
{
fclose(fp);
fprintf(stderr,"could not read datasize");
return NULL;
}
noctets = BitsPerSamp/8;
nx = DataSize/BytePerBloc;
if (verbose) fprintf(stderr,"DataSize %d nx %d noctets %d" ,DataSize,nx,noctets);
if (BytePerBloc != (NbrCanaux * BitsPerSamp/8))
{
fclose(fp);
fprintf(stderr,"Byte per bloc pb!\n"
"Byte per bloc %d != NbrCanaux %d x Bitspersample %d/8"
,BytePerBloc,(int)NbrCanaux,(int)BitsPerSamp);
return NULL;
}
/*
if (FileSize != DataSize + 44)
{
cont = 0;
i = fprintf(stderr,"File size pb!\n"
"File size %d != datasize %d + 44"
"\ntype 1 to continue anything else to stop"
,FileSize,DataSize);
scanf("%d",&cont);
if (cont == 1)
{
fclose(fp);
return NULL;
}
}
*/
if (BytePerSec != Frequence * BytePerBloc)
{
cont = 0;
i = fprintf(stderr,"Byte count pb!\n"
"Byte per sec %d != Frequence %d x Byte per bloc %d"
"\ntype 1 to continue anything else to stop"
,BytePerSec,Frequence,BytePerBloc);
scanf("%d",&cont);
if (cont == 1)
{
fclose(fp);
return NULL;
}
}
xd = (float*)calloc(nx,sizeof(float));
if (xd == NULL)
{
fclose(fp);
fprintf(stderr,"could not create float array");
return NULL;
}
if (freq) *freq = Frequence;
if (ny) *ny = nx;
for (j = 0; j < nx; j++)
{
for (i = 0; i < NbrCanaux; i++)
{
uch[0] = uch[1] = uch[2] = uch[3] = 0;
data = 0;
if (noctets == 1)
{
if (fread(uch,sizeof(unsigned char),noctets,fp) != noctets)
{
fclose(fp);
fprintf(stderr,"could not read unsigned int data at %d %d",i,j);
return NULL;
}
data = uch[0];
}
if (noctets == 2)
{
if (fread(&si,sizeof(short int),1,fp) != 1)
{
fclose(fp);
fprintf(stderr,"could not read short int data at %d %d",i,j);
return NULL;
}
data = (int)si;
}
if (noctets == 3)
{ // to be checked
if (fread(uch,sizeof(unsigned char),noctets,fp) != noctets)
{
fclose(fp);
fprintf(stderr,"could not read data at %d %d",i,j);
return NULL;
}
data = (uch[0] << 8) | (uch[1] << 16) | (uch[2] << 24);
data /= 256;
}
if (i == canal) xd[j] = (float)data;
}
}
fclose(fp);
return xd;
}
# endif

27
wave_stuff.h Normal file
View File

@ -0,0 +1,27 @@
# ifndef _WAVE_STUFF_H_
# define _WAVE_STUFF_H_
/*
read a sound wave file and save it in a float array which is allocated by the function
char *file : the filename of the sound wave file (example "c:\\music\\test.wav"
int canal : the canal to be read if the wav file is in stereo two values are possible 0 and 1
int verbose : flag producing lost of debugging info if different of 0
int *ny : the address of an integer to return the number of points read
int *freq : the address of an integer to return the sampling frequency
if the function fails it return a null pointer
*/
float* read_wave_create_array(char *file, int canal, int verbose, int *ny, int *freq);
/*
save an array of float in a file of format wav,
char *file : the filename of the futur sound wave file (example "c:\\music\\test.wav"
int BitsPerSample : the number of bits per sample (typically 16)
int verbose : flag producing lost of debugging info if different of 0
int nx : the number of points to save
int Frequence : the sampling frequency
on success return 0 otherwise an error code
*/
int save_wave_from_array(float *x, int nx, char *file, int Frequence, int BitsPerSample);
# endif