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-05-06 15:10:34 +02:00
|
|
|
|
if (getInstrument(m,0,tmp) == -1) FMOD_Channel_Stop(chan[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) {
|
2014-05-06 15:10:34 +02:00
|
|
|
|
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sample[getInstrument(m,chaine,tmp)], 0, &chan[chaine]);
|
|
|
|
|
|
|
|
|
|
//Ici on va s'occuper du pitch
|
|
|
|
|
FMOD_DSP *pitch;
|
|
|
|
|
FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_PITCHSHIFT, &pitch);
|
|
|
|
|
FMOD_DSP_SetParameter(pitch, FMOD_DSP_PITCHSHIFT_PITCH, 2);
|
|
|
|
|
FMOD_Channel_AddDSP(chan1, pitch, 0);
|
2014-04-10 17:44:27 +02:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 15:10:34 +02:00
|
|
|
|
|
|
|
|
|
|
2014-04-08 14:23:22 +02:00
|
|
|
|
void lecture (int nombreChaines, Motif* melodie[]) {
|
2014-05-06 15:10:34 +02:00
|
|
|
|
|
|
|
|
|
FMOD_SYSTEM *system;
|
|
|
|
|
|
|
|
|
|
FMOD_RESULT resultat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FMOD_System_Create(&system);
|
|
|
|
|
FMOD_System_Init(system, 8, FMOD_INIT_NORMAL, NULL); //Le deuxi<78>me argument donne le nombre de canal <20> utiliser (nombre de chaines)
|
|
|
|
|
|
|
|
|
|
|
2014-04-08 08:10:04 +02:00
|
|
|
|
//INITIALISATION SAMPLES ET CHANNELS
|
2014-05-06 15:10:34 +02:00
|
|
|
|
|
|
|
|
|
FMOD_CHANNEL *chan[nombreChaines]; // On ouvre le nombre de chaines n<>cessaires dans le mixer
|
|
|
|
|
|
|
|
|
|
FMOD_SOUND *sample[5]; // On charge les samples avec un message d'erreur en cas d'<27>chec
|
|
|
|
|
|
|
|
|
|
resultat = FMOD_System_CreateStream(system, "lecture/0.wav", FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &sample[0]);
|
|
|
|
|
if (resultat != FMOD_OK)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Impossible de lire le fichier audio\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultat = FMOD_System_CreateStream(system, "lecture/1.wav", FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &sample[1]);
|
|
|
|
|
if (resultat != FMOD_OK)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Impossible de lire le fichier audio\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultat = FMOD_System_CreateStream(system, "lecture/2.wav", FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &sample[2]);
|
|
|
|
|
if (resultat != FMOD_OK)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Impossible de lire le fichier audio\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultat = FMOD_System_CreateStream(system, "lecture/3.wav", FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &sample[3]);
|
|
|
|
|
if (resultat != FMOD_OK)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Impossible de lire le fichier audio\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultat = FMOD_System_CreateStream(system, "lecture/4.wav", FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &sample[4]);
|
|
|
|
|
if (resultat != FMOD_OK)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Impossible de lire le fichier audio\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-10 17:44:27 +02:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-06 15:10:34 +02:00
|
|
|
|
|
|
|
|
|
//On relache le syst<73>me FMOD
|
|
|
|
|
for (int i = 0; i <= nombreChaines; i++) {
|
|
|
|
|
FMOD_Sound_Release(sample[i]);
|
|
|
|
|
}
|
|
|
|
|
FMOD_System_Close(system);
|
|
|
|
|
FMOD_System_Release(system);
|
|
|
|
|
|
2014-04-08 08:10:04 +02:00
|
|
|
|
SDL_Quit();
|
2014-04-07 20:51:04 +02:00
|
|
|
|
}
|