Atteinte de l'objectif proto : ça joue de la musique :) (et pas n'importe laquelle)

This commit is contained in:
Raspbeguy 2014-04-10 17:44:27 +02:00
parent 979230f880
commit ee77215acf
9 changed files with 96 additions and 11 deletions

BIN
sources/lecture/0.wav Normal file

Binary file not shown.

BIN
sources/lecture/1.wav Normal file

Binary file not shown.

BIN
sources/lecture/2.wav Normal file

Binary file not shown.

BIN
sources/lecture/3.wav Normal file

Binary file not shown.

BIN
sources/lecture/4.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,22 +6,39 @@ void lireTick (Motif* m, int tmp, Mix_Chunk* chunk[], int nbrPortees) { // On
for (int chaine = 0; chaine < nbrPortees; chaine++) { // On va lire les chaines une à une par numéro croissant
if (m != NULL) {
if (getNote(m,0,tmp) == -1) Mix_HaltChannel(chaine); // Si la note est un silence, la chaine s'arrête
if (getInstrument(m,0,tmp) == -1) Mix_HaltChannel(chaine); // Si la note est un silence, la chaine s'arrête
else {
Mix_PlayChannel(-1, chunk[getInstrument(m,chaine,tmp)], -1); // Sinon le sample de la chaine est joué en boucle
if (getNote(m,0,tmp) != 0) {
Mix_PlayChannel(chaine, chunk[getInstrument(m,chaine,tmp)], -1); // Sinon le sample de la chaine est joué en boucle
}
}
}
}
while (SDL_GetTicks() - tempsPrecedent < 250) {} // Si 250 ms se sont écoulées (il faudra régler ce temps sur le tempo)
tempsPrecedent = tempsPrecedent + 250;
while (SDL_GetTicks() - tempsPrecedent < 125) {} // Si 250 ms se sont écoulées (il faudra régler ce temps sur le tempo)
tempsPrecedent = tempsPrecedent + 125;
}
void lecture (int nombreChaines, Motif* melodie[]) {
// Tout ça c'est pour ouvrir le périphérique audio
int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
int audio_channels = 1;
int audio_buffers = 4096;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio!\n");
exit(1);
}
//INITIALISATION SAMPLES ET CHANNELS
Mix_AllocateChannels(nombreChaines); // On ouvre le nombre de chaines nécessaires dans le mixer
Mix_Chunk* chunk[2] = {Mix_LoadWAV("Square.wav"), Mix_LoadWAV("Saw.wav")};
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");
//Lecture des motifs
for (courant = 0; courant < taille; courant++) {
for (int i = 0; i < melodie[courant] -> nbrTmp; i++) {

View File

@ -29,16 +29,84 @@ void afficherMotif(Motif* m, int nbrPortees){
void debut(Motif* melodie[], Motif* liste, int nbrPortees){
ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
Motif* m = liste;
definirNote(m,0,4,5);
definirNote(m,0,2,9);
// My Little Pony.
definirNote(m,0,0,1);
definirInstrument(m,0,0,1);
definirInstrument(m,0,2,-1);
definirNote(m,0,4,1);
definirInstrument(m,0,4,0);
definirNote(m,0,5,1);
definirInstrument(m,0,5,1);
definirInstrument(m,0,6,-1);
definirNote(m,0,7,1);
definirInstrument(m,0,7,2);
definirInstrument(m,0,8,-1);
definirNote(m,0,9,1);
definirInstrument(m,0,9,1);
definirInstrument(m,0,12,-1);
ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
Motif* n = liste;
definirNote(n,0,10,3);
definirNote(n,0,6,7);
// I used to wonder what friendship could be.
definirNote(n,0,1,1);
definirInstrument(n,0,1,3);
definirNote(n,0,2,1);
definirInstrument(n,0,2,3);
definirNote(n,0,3,1);
definirInstrument(n,0,3,3);
definirNote(n,0,4,1);
definirInstrument(n,0,4,3);
definirInstrument(n,0,5,-1);
definirNote(n,0,6,1);
definirInstrument(n,0,6,1);
definirNote(n,0,7,1);
definirInstrument(n,0,7,2);
definirInstrument(n,0,8,-1);
definirNote(n,0,9,1);
definirInstrument(n,0,9,1);
definirInstrument(n,0,10,-1);
definirNote(n,0,11,1);
definirInstrument(n,0,11,3);
definirInstrument(n,0,12,-1);
definirNote(n,0,13,1);
definirInstrument(n,0,13,2);
definirInstrument(n,0,14,-1);
definirNote(n,0,15,1);
definirInstrument(n,0,15,1);
ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
Motif* p = liste;
// Until you all shared its magic with me.
definirNote(p,0,0,1);
definirInstrument(p,0,0,3);
definirNote(p,0,1,1);
definirInstrument(p,0,1,4);
definirInstrument(p,0,2,-1);
definirNote(p,0,3,1);
definirInstrument(p,0,3,4);
definirInstrument(p,0,4,-1);
definirNote(p,0,5,1);
definirInstrument(p,0,5,3);
definirInstrument(p,0,6,-1);
definirNote(p,0,7,1);
definirInstrument(p,0,7,2);
definirInstrument(p,0,8,-1);
definirNote(p,0,9,1);
definirInstrument(p,0,9,1);
definirNote(p,0,10,1);
definirInstrument(p,0,10,3);
definirInstrument(p,0,11,-1);
definirNote(p,0,12,1);
definirInstrument(p,0,12,2);
definirInstrument(p,0,14,-1);
ajouterMotifVirtuel(melodie,0,m);
ajouterMotifVirtuel(melodie,1,n);
ajouterMotifVirtuel(melodie,2,m);
ajouterMotifVirtuel(melodie,3,n);
ajouterMotifVirtuel(melodie,3,p);
}
int main( int argc, char *argv[] ){