Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.1 some sounds do not play  (Read 4678 times)

0 Members and 1 Guest are viewing this topic.

nebula

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Email
SFML 2.1 some sounds do not play
« on: March 22, 2014, 07:57:36 pm »
so, the problem is, some sounds are played and some are not...

it is regarding to my project which is also here in this forum:
http://en.sfml-dev.org/forums/index.php?topic=13453.0
if you get the release and play it, you will notice that:
if a big cow is spawning there is no sound
if you get the third weapon there is no sound
if the third boss dies there is no sound
every other sound works

here my code for the sound:
//IngameSfx.h

#ifndef INGAMESFX_H
#define INGAMESFX_H

#include <SFML/Audio.hpp>
#include <string>

class IngameSound
{
public:

        void LoadSoundBuffer();
        void setBuffer(int &volume);
        void PlaySound(std::string sound);

private:

        sf::SoundBuffer bossDeathBuffer;
        sf::SoundBuffer bulletShotBuffer;
        sf::SoundBuffer enemyCollisionBuffer;
        sf::SoundBuffer healthDropBuffer;
        sf::SoundBuffer playerCollisionBuffer;
        sf::SoundBuffer playerDeathBuffer;
        sf::SoundBuffer monkeyFartBuffer;
        sf::SoundBuffer pewBuffer;
        sf::SoundBuffer boss1HitBuffer;
        sf::SoundBuffer cowBuffer;
        sf::SoundBuffer boss3spawn;
        sf::SoundBuffer boss3death;

        sf::Sound bossDeathSound;
        sf::Sound bulletShotSound;
        sf::Sound enemyCollisionSound;
        sf::Sound healthDropSound;
        sf::Sound playerCollisionSound;
        sf::Sound playerDeathSound;
        sf::Sound monkeyFartSound;
        sf::Sound pewSound;
        sf::Sound boss1HitSound;
        sf::Sound cowSound;
        sf::Sound boss3spawnSound;
        sf::Sound boss3deathSound;
};

#endif

//IngameSfx.cpp

#include "IngameSfx.h"

//Sound
void IngameSound::LoadSoundBuffer()
{

        bossDeathBuffer.loadFromFile("audio//bossDeath.ogg");
        bulletShotBuffer.loadFromFile("audio//bulletShot.ogg");
        enemyCollisionBuffer.loadFromFile("audio//enemyCollision.ogg");
        healthDropBuffer.loadFromFile("audio//healthDrop.ogg");
        playerCollisionBuffer.loadFromFile("audio//playerCollision.ogg");
        playerDeathBuffer.loadFromFile("audio//playerDeath.ogg");
        monkeyFartBuffer.loadFromFile("audio//fart.ogg");
        pewBuffer.loadFromFile("audio//pew.ogg");
        boss1HitBuffer.loadFromFile("audio//boss1hit.ogg");
        cowBuffer.loadFromFile("audio//cow.ogg");
        boss3spawn.loadFromFile("audio//boss3spawn.ogg");
        boss3death.loadFromFile("audio//boss3death.ogg");
}

void IngameSound::setBuffer(int &volume)
{
        bossDeathSound.setBuffer(bossDeathBuffer);
                bossDeathSound.setVolume(volume);
        bulletShotSound.setBuffer(bulletShotBuffer);
                bulletShotSound.setVolume(volume);
        enemyCollisionSound.setBuffer(enemyCollisionBuffer);
                enemyCollisionSound.setVolume(volume);
        healthDropSound.setBuffer(healthDropBuffer);
                healthDropSound.setVolume(volume);
        playerCollisionSound.setBuffer(playerCollisionBuffer);
                playerCollisionSound.setVolume(volume);
        playerDeathSound.setBuffer(playerDeathBuffer);
                playerDeathSound.setVolume(volume);
        monkeyFartSound.setBuffer(monkeyFartBuffer);
                monkeyFartSound.setVolume(volume);
        pewSound.setBuffer(pewBuffer);
                pewSound.setVolume(volume);
        boss1HitSound.setBuffer(boss1HitBuffer);
                boss1HitSound.setVolume(volume);
        cowSound.setBuffer(cowBuffer);
                cowSound.setVolume(volume);
        boss3spawnSound.setBuffer(boss3spawn);
                boss3spawnSound.setVolume(volume);
        boss3deathSound.setBuffer(boss3death);
                boss3deathSound.setVolume(volume);
}

void IngameSound::PlaySound(std::string sound)
{
        if (sound == "bulletShot")
        {
                bulletShotSound.play();
        }
        if (sound == "fart")
        {
                monkeyFartSound.play();
        }
        if (sound == "enemyCollision")
        {
                enemyCollisionSound.play();
        }
        if (sound == "playerCollision")
        {
                playerCollisionSound.play();
        }
        if (sound == "bossDeath")
        {
                bossDeathSound.play();
        }
        if (sound == "healthDrop")
        {
                healthDropSound.play();
        }
        if (sound == "playerDeath")
        {
                playerDeathSound.play();
        }
        if (sound == "pew")
        {
                pewSound.play();
        }
        if (sound == "boss1Hit")
        {
                boss1HitSound.play();
        }
        if (sound == "cow")
        {
                cowSound.play();
        }
        if (sound == "boss3spawn")
        {
                boss3spawnSound.play();
        }
        if (sound == "boss3death")
        {
                boss3deathSound.play();
        }
}

the sound is used in several classes. here some example:

works
void UpdateManager::BulletSpawn(int &counter, std::vector<Bullet> &vector, HighscoreManager &highscore, WeaponManager &weapon, Player &player, IngameSound &sound)
{
        if (counter >= 175 && weapon.bulletA)
        {
                Bullet bulletx;
                highscore.setShotsFired(1);
                bulletx.SetPosition(player.getPosition().x - 4, player.getPosition().y);
                vector.push_back(bulletx);
                sound.PlaySound("bulletShot");
                counter = 0;
        }
}

does not work
void UpdateManager::PewSpawn(std::vector<Pew> &vector, HighscoreManager &highscore, WeaponManager &weapon, Player &player, IngameSound &sound, bool &pewOnCooldown)
{
        if (weapon.pewA && !pewOnCooldown)
        {
                Pew pewx;
                highscore.setShotsFired(1);
                pewx.SetPosition(player.getPosition().x - 4, player.getPosition().y);
                vector.push_back(pewx);
                sound.PlaySound("pew");
                pewOnCooldown = true;
        }
}

maybe it has something to deal with the files?
if you get the release the files are all included.

thanks for any help ;)

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML 2.1 some sounds do not play
« Reply #1 on: March 22, 2014, 08:34:41 pm »
If (foo) ... If (bar) ... If (whatever) ...
Have you considered "else if" ??

nebula

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Email
Re: SFML 2.1 some sounds do not play
« Reply #2 on: March 22, 2014, 08:36:43 pm »
If (foo) ... If (bar) ... If (whatever) ...
Have you considered "else if" ??

i will change it ;)


but do you think it will change something?

____________________________________________________________
i added a console output for the sounds which does not work.
so when the sound has to be played, there is an output but no sound
so i think it has something to do with how the audio file is built??
i really have no idea of audio files :P
« Last Edit: March 22, 2014, 08:48:42 pm by nebula »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML 2.1 some sounds do not play
« Reply #3 on: March 23, 2014, 03:09:18 am »
but do you think it will change something?
No, it won't. I just couldn't read that code and not make that comment.

nebula

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Email
Re: SFML 2.1 some sounds do not play
« Reply #4 on: March 23, 2014, 03:27:46 pm »
^^ sorry :D

now it is with else if ;)

nebula

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Email
Re: SFML 2.1 some sounds do not play
« Reply #5 on: March 23, 2014, 03:55:15 pm »
ok.. i changed the audio files from .ogg to .wav and now it works... so this can be closed

 

anything