hi
when i play a sound the music volume is lowered and after few seconds upping to the old volume
music.hpp
#ifndef __music__
#define __music__
#include <SFML/Audio.hpp>
#include <string>
class music{
public:
bool initMusic();
void setMusicVolume(const float volume);
void playSong();
void stopSong();
sf::Music m_music;
private:
bool loadSong(std::string title);
void setMusicLoop(bool loop);
};
#endif
music.cpp
#include "music.hpp"
bool music::loadSong(std::string title)
{
return m_music.openFromFile(title);
}
void music::setMusicVolume(const float volume)
{
m_music.setVolume(volume);
}
void music::setMusicLoop(bool loop)
{
m_music.setLoop(loop);
}
bool music::initMusic()
{
bool flag = loadSong("A Theme.flac");
setMusicLoop(true);
return flag;
}
void music::playSong()
{
m_music.play();
}
void music::stopSong()
{
m_music.stop();
}
sound.hpp
#ifndef __sound__
#define __sound__
#include <SFML/Audio.hpp>
#include <string>
#include <vector>
#include <memory>
class sound{
public:
// sound();
void initSounds();
void playSound(const int thatSound);
void setSoundVolume(const float volume);
private:
bool loadFileSounds();
void assignSoundsToBuffers();
std::array<sf::SoundBuffer, 15> m_soundBuffer;
std::array<sf::Sound, 15> m_sound;
};
#endif
sound.cpp
#include "sound.hpp"
#include <array>
#include <iostream>
bool sound::loadFileSounds()
{
bool flag{true};
bool flag1 = m_soundBuffer[0].loadFromFile("sound\\harddrop.ogg");
flag1 = m_soundBuffer[1].loadFromFile("sound\\rotation.ogg");
flag1 = m_soundBuffer[2].loadFromFile("sound\\softdrop.ogg");
flag1 = m_soundBuffer[3].loadFromFile("sound\\ouverturemenu.ogg");
flag1 = m_soundBuffer[4].loadFromFile("sound\\levelchgt.ogg");
flag1 = m_soundBuffer[5].loadFromFile("sound\\complitedlines.ogg");
flag1 = m_soundBuffer[6].loadFromFile("sound\\departfinpartie.ogg");
}
void sound::assignSoundsToBuffers()
{
for(auto i = 0; i < 15; ++i){
m_sound[i].setBuffer(m_soundBuffer[i]);
}
}
void sound::initSounds()
{
loadFileSounds();
assignSoundsToBuffers();
}
void sound::setSoundVolume(const float volume)
{
for(auto i = 0; i < 15; ++i){
m_sound[i].setVolume(volume);
}
}
void sound::playSound(const int thatSound)
{
m_sound[thatSound].play();
}
both volume are initialized once
m_jsonSetup.loadJsonFile("setup.json");
gameSound.initSounds();
gameMusic.initMusic();
setSetUp();
setSoundVolume(m_setup.soundVolume);
setMusicVolume(m_setup.musicVolume);
thx