FMOD不播放声音C ++

时间:2012-05-31 14:20:29

标签: c++ fmod

我实际上尝试用FMOD播放声音,但它没有用。

#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

#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);
}

但是当我玩的时候(“mysound.wav”);在我的代码没有附加,我验证返回值,没有问题。所以任何想法?感谢

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;
}

1 个答案:

答案 0 :(得分:0)

您没有动态分配Sound变量。

您需要的是:

Sound sound = new Sound();

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

Bombe::update做:

Sound sound;

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

还要确保explosion.wav位于文件夹sound/