2014-04-08 14:23:22 +02:00
|
|
|
|
#include "lecture.h"
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-08 14:23:22 +02:00
|
|
|
|
void lireTick (Motif* m, int tmp, Mix_Chunk* chunk[], int nbrPortees) { // On va lire les ticks (plus petite division temporelle de la playlist) de haut en bas
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-08 14:23:22 +02:00
|
|
|
|
int tempsPrecedent = SDL_GetTicks();
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-10 14:33:33 +02:00
|
|
|
|
for (int chaine = 0; chaine < nbrPortees; chaine++) { // On va lire les chaines une <20> une par num<75>ro croissant
|
2014-04-08 14:23:22 +02:00
|
|
|
|
if (m != NULL) {
|
2014-04-10 17:44:27 +02:00
|
|
|
|
if (getInstrument(m,0,tmp) == -1) Mix_HaltChannel(chaine); // Si la note est un silence, la chaine s'arr<72>te
|
2014-04-10 14:33:33 +02:00
|
|
|
|
else {
|
2014-04-10 17:44:27 +02:00
|
|
|
|
if (getNote(m,0,tmp) != 0) {
|
|
|
|
|
Mix_PlayChannel(chaine, chunk[getInstrument(m,chaine,tmp)], -1); // Sinon le sample de la chaine est jou<6F> en boucle
|
|
|
|
|
}
|
2014-04-10 14:33:33 +02:00
|
|
|
|
}
|
2014-04-08 14:23:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-10 17:44:27 +02:00
|
|
|
|
while (SDL_GetTicks() - tempsPrecedent < 125) {} // Si 250 ms se sont <20>coul<75>es (il faudra r<>gler ce temps sur le tempo)
|
|
|
|
|
tempsPrecedent = tempsPrecedent + 125;
|
2014-04-08 14:23:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lecture (int nombreChaines, Motif* melodie[]) {
|
2014-04-10 17:44:27 +02:00
|
|
|
|
// Tout <20>a c'est pour ouvrir le p<>riph<70>rique audio
|
|
|
|
|
int audio_rate = 44100;
|
|
|
|
|
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
|
|
|
|
|
int audio_channels = 1;
|
|
|
|
|
int audio_buffers = 4096;
|
2014-04-08 08:10:04 +02:00
|
|
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
2014-04-10 17:44:27 +02:00
|
|
|
|
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
|
|
|
|
|
printf("Unable to open audio!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 08:10:04 +02:00
|
|
|
|
//INITIALISATION SAMPLES ET CHANNELS
|
2014-04-08 14:23:22 +02:00
|
|
|
|
Mix_AllocateChannels(nombreChaines); // On ouvre le nombre de chaines n<>cessaires dans le mixer
|
2014-04-10 17:44:27 +02:00
|
|
|
|
Mix_Chunk* chunk[5];
|
|
|
|
|
chunk[0] = Mix_LoadWAV("lecture/0.wav");
|
|
|
|
|
chunk[1] = Mix_LoadWAV("lecture/1.wav");
|
|
|
|
|
chunk[2] = Mix_LoadWAV("lecture/2.wav");
|
|
|
|
|
chunk[3] = Mix_LoadWAV("lecture/3.wav");
|
|
|
|
|
chunk[4] = Mix_LoadWAV("lecture/4.wav");
|
|
|
|
|
|
2014-04-08 08:10:04 +02:00
|
|
|
|
//Lecture des motifs
|
2014-04-08 14:23:22 +02:00
|
|
|
|
for (courant = 0; courant < taille; courant++) {
|
2014-04-08 08:10:04 +02:00
|
|
|
|
for (int i = 0; i < melodie[courant] -> nbrTmp; i++) {
|
2014-04-10 14:33:33 +02:00
|
|
|
|
printf("lecture temps %d : N=%d I=%d\n",i,getNote(melodie[courant],0,i),getInstrument(melodie[courant],0,i));
|
2014-04-08 14:23:22 +02:00
|
|
|
|
lireTick (melodie[courant], i, chunk, nombreChaines);
|
2014-04-08 08:10:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Mix_CloseAudio();
|
|
|
|
|
SDL_Quit();
|
2014-04-07 20:51:04 +02:00
|
|
|
|
}
|