difficulté adaptative

This commit is contained in:
antpoms 2025-06-14 21:56:10 +02:00
parent da42d26c23
commit ed67d84c88
2 changed files with 30 additions and 18 deletions

View file

@ -16,6 +16,7 @@ private:
std::vector<std::vector<float>> markov_matrix_chords;
std::vector<std::vector<float>> markov_matrix_melody;
int nbr_melo_max{4};
int nbr_melo_total{ 64 };
int current_beat{0};
std::vector<std::vector<float>> rythmes;
int index_note;

View file

@ -58,6 +58,9 @@ AudioEmitter::AudioEmitter() {
for (int i = 0; i < 7; i += 1) {
chords.push_back(std::unique_ptr<FMOD::Sound>(rawChords[i]));
}
for (int i = 0; i < 7; i += 1) {
chords.push_back(std::unique_ptr<FMOD::Sound>(rawChords2[i]));
}
std::vector<FMOD::Sound *> rawNotes(15);
ERRCHECK(system->createSound("media/notes/A1.mp3", FMOD_LOOP_OFF, nullptr,
@ -96,10 +99,6 @@ AudioEmitter::AudioEmitter() {
index_note = firstNote();
std::vector<std::vector<float>> rythmes2 = {
};
rythmes = {
{0, 4},
{0, 2, 4, 6},
@ -285,6 +284,14 @@ std::vector<std::pair<float, int>> AudioEmitter::generateMusic() {
float beatDuration = tempo / 60.f;
unsigned int sampleRate = 48000;
int maxsize = 400;
int variation = 0;
if (((current_beat / nbr_melo_max) % 4) < 2) { //On change la manière dont sont joués les accords toutes les 2*nbr_melo_max mélodies générées
variation = 0;
}
else {
variation = 1;
}
int nbrChords = 7;
if (activeChannels.size() > maxsize) {
for (int i = 0; i < maxsize / 2; i += 1) {
if (activeChannels[i]) {
@ -301,7 +308,7 @@ std::vector<std::pair<float, int>> AudioEmitter::generateMusic() {
// Chords
FMOD::Channel *channelChords = nullptr;
int index_chord = chordProgression[i % 4];
ERRCHECK(system->playSound(chords[index_chord].get(), nullptr, true,
ERRCHECK(system->playSound(chords[index_chord + variation*nbrChords].get(), nullptr, true,
&channelChords));
unsigned long long delay =
@ -311,19 +318,23 @@ std::vector<std::pair<float, int>> AudioEmitter::generateMusic() {
activeChannels.push_back(channelChords);
// Mélodie
std::vector<float> rythme_melodie = rythmes[rand() % rythmes.size()];
for (float time : rythme_melodie) {
FMOD::Channel *channelNote = nullptr;
ERRCHECK(system->playSound(notes[index_note].get(), nullptr, true,
&channelNote));
float note_start = (i + time / 8.f) * beatDuration;
unsigned long long delayNote =
(unsigned long long)(note_start * sampleRate);
ERRCHECK(channelNote->setDelay(delayNote, 0, true));
ERRCHECK(channelNote->setPaused(false));
result.push_back(std::pair<float, int>(note_start, index_note));
index_note = nextNote(index_note);
activeChannels.push_back(channelNote);
if (i >= 4) {
int index_rythme = floor(((i - 4) * 1.f / nbr_melo_total) * (rythmes.size() - 1)) + ( rand() % nbr_melo_max ); //Les rythmes deviennent de plus en plus complexe, plus on avance dans le temps, plus le rythme est tiré de la fin du vecteur
index_rythme = (int)fmin(index_rythme, rythmes.size() - 1);
std::vector<float> rythme_melodie = rythmes[index_rythme];
for (float time : rythme_melodie) {
FMOD::Channel* channelNote = nullptr;
ERRCHECK(system->playSound(notes[index_note].get(), nullptr, true,
&channelNote));
float note_start = (i + time / 8.f) * beatDuration;
unsigned long long delayNote =
(unsigned long long)(note_start * sampleRate);
ERRCHECK(channelNote->setDelay(delayNote, 0, true));
ERRCHECK(channelNote->setPaused(false));
result.push_back(std::pair<float, int>(note_start, index_note));
index_note = nextNote(index_note);
activeChannels.push_back(channelNote);
}
}
}
current_beat += nbr_melo_max;