3

I actually try to play a sound with FMOD but it didn't work.

#ifndef __SOUND_HH__
#define __SOUND_HH__

#include <string>
#include <fmodex/fmod.h>

class Sound
{
  FMOD_SYSTEM *sys;

  FMOD_SOUND *explosion;
  FMOD_RESULT resExplosion;
  FMOD_CHANNEL *channel1;

public:
  Sound();
  ~Sound();

  void play(const std::string &);
};

#endif

and

#include <string>
#include <iostream>
#include "Sound.hh"

Sound::Sound()
{
  FMOD_System_Create(&this->sys);
  FMOD_System_Init(this->sys, 1, FMOD_INIT_NORMAL, NULL);
}

Sound::~Sound()
{
  FMOD_System_Release(sys);
}

but when I do play("mysound.wav"); on my code nothing append, I verify return value and no problem. so any idea ? thanks

void Sound::play(const std::string &filename)
{
  FMOD_System_CreateStream(this->sys, filename.c_str(), FMOD_HARDWARE | FMOD_LOOP_OFF | FMOD_2D, 0, &this->explosion);
  FMOD_System_PlaySound(sys, FMOD_CHANNEL_FREE, explosion, 0 , &channel1);
        std::cout << "playayayyayayayayya" << std::endl;
}
Christian Rau
  • 45,360
  • 10
  • 108
  • 185
ago
  • 31
  • 4
  • Have you turned on/up your speakers? Have you tried playing the sound through a media player? – Carl Winder May 31 '12 at 14:26
  • I have try with an other project in C where I use FMOD and it's work. I try with a same sound and always don't work – ago May 31 '12 at 14:37
  • where's the code where you are calling the play function? – Carl Winder May 31 '12 at 14:39
  • I code a bomberman game so, I call the play function on a class Bomb when the bomb explodes. and I have a Sound *_sound variable on my class. I do _sound = new Sound() on the constructor, and call _sound->play(file) when I need it – ago May 31 '12 at 14:42
  • yeah we need to see that code, exactly as you have it in your game – Carl Winder May 31 '12 at 14:44
  • `void Bombe::update(const gdl::GameClock & gameClock, gdl::Input & input) { (void)input; this->_time += gameClock.getElapsedTime(); if (this->_time > EXPLODE) { this->_boum = true; this->_sound.play("./sound/explosion.wav"); } if (this->_time > FLAMME) this->_pshh = true; } ` – ago May 31 '12 at 14:47

1 Answers1

0

You're not dynamically allocating the Sound variable.

What you need is:

Sound sound = new Sound();

sound->play("./sound/explosion.wav");

Or in the Bombe::update do:

Sound sound;

sound.play("./sound/explosion.wav");

Also make sure that explosion.wav is in the folder sound/.

Carl Winder
  • 938
  • 8
  • 18