FMOD - 未处理的异常,没有可用的源代码

发布于 2024-12-06 01:08:25 字数 3728 浏览 1 评论 0原文

我正在尝试使用 FMOD 播放我的音轨,但我不断收到未处理的异常,然后它说没有可用的源代码,并向我显示反汇编代码。

main.cpp
        bool AudioProject::initAudio()
    {
        // Audio code
        fmSound = new Sound();
        fmSound->initialise();
        fmSound->load("Music/Rocky_Theme_Tune.mp3");
        fmSound->play();
        return true;
    }

我在它停止的地方放置了断点,它位于初始化函数中。它甚至进入初始化函数,然后随机中断。我想我有 fmod 的每个包含文件,因为我去年使用它没有问题。

我也会发布我的 sound.h/.cpp 文件。

.h

#include "stdafx.h"
#pragma once
#include "fmod.hpp"
#include "fmod.h"


class Sound
{
private:
    bool on; //is sound on?
    bool possible; //is it possible to play sound?
    char * currentSound; //currently played sound
    //FMOD-specific stuff
    FMOD_RESULT result;
    FMOD_SYSTEM * fmodsystem;
    FMOD_SOUND * sound;
    FMOD_CHANNEL * channel;

public:
    Sound();
    ~Sound();
    void initialise (void); 
    void setVolume (float v); 
    void load (const char * filename); 
    void unload (void);
    void play (bool pause = false); 
    bool getSound (void); 
    void setPause (bool pause); 
    void setSound (bool sound); 
    void toggleSound (void); 
    void togglePause (void); 

};

.cpp

#include "stdafx.h"
#include "Sound.h"
#include "fmod.h"
#include "fmod.hpp"

Sound::Sound()
{
    on = true; //is sound on?
    possible = true; //is it possible to play sound?
    currentSound=""; //currently played sound
    sound=0;

}

Sound::~Sound()
{

}

//initialises sound
void Sound::initialise (void) 
{

    //create the sound system. If fails, sound is set to impossible
    result = FMOD_System_Create(&fmodsystem);
    if (result != FMOD_OK) 
        possible = false;

    //if initialise the sound system. If fails, sound is set to impossible
    if (possible) 
        result = FMOD_System_Init(fmodsystem,2, FMOD_INIT_NORMAL, 0);

    if (result != FMOD_OK) 
        possible = false;

    //sets initial sound volume (mute)
    if (possible) 
        FMOD_Channel_SetVolume(channel,1.0f);
}

//sets the actual playing sound's volume
void Sound::setVolume (float v) 
{
    if (possible && on && v >= 0.0f && v <= 1.0f) 
    {
        FMOD_Channel_SetVolume(channel,v);
    }
}

//loads a soundfile
void Sound::load (const char * filename) 
{
    currentSound = (char *)filename;
    if (possible && on) 
    {
        result = FMOD_Sound_Release(sound);
        result = FMOD_System_CreateStream(fmodsystem,currentSound, FMOD_SOFTWARE, 0, &sound);
        if (result != FMOD_OK) 
            possible = false;
    }
}

//frees the sound object
void Sound::unload (void) 
{
    if (possible) 
    {
        result = FMOD_Sound_Release(sound);
    }
}

//plays a sound (no argument to leave pause as dafault)
void Sound::play (bool pause) 
{
    if (possible && on) 
    {
        result = FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound, pause, &channel);
        FMOD_Channel_SetMode(channel,FMOD_LOOP_NORMAL);
    }
}

//toggles sound on and off
void Sound::toggleSound (void) 
{
    on = !on;
    if (on == true) 
    { 
        load(currentSound); 
        play(); 
    }
    if (on == false) 
    { 
        unload(); 
    }
}

//pause or unpause the sound
void Sound::setPause (bool pause) 
{
    FMOD_Channel_SetPaused (channel, pause);
}

//turn sound on or off
void Sound::setSound (bool s) 
{
    on = s;
}

//toggle pause on and off
void Sound::togglePause (void) 
{
    FMOD_BOOL p;
    FMOD_Channel_GetPaused(channel,&p);
    FMOD_Channel_SetPaused (channel,!p);
}

//tells whether the sound is on or off
bool Sound::getSound (void) 
{
    return on;
}

在这里碰壁了,有人有什么想法吗?

I'm trying to get my audio track to play using FMOD but I keep getting an unhandled exception and then it says there's no source code available, and shows me disassembly code.

main.cpp
        bool AudioProject::initAudio()
    {
        // Audio code
        fmSound = new Sound();
        fmSound->initialise();
        fmSound->load("Music/Rocky_Theme_Tune.mp3");
        fmSound->play();
        return true;
    }

I put break points in the see where it stopped, which was in the initialise function. It even goes into the initialise function and then just randomly breaks. I think I have every include file for fmod as I used it last year no problem.

I'll post my sound.h/.cpp files too.

.h

#include "stdafx.h"
#pragma once
#include "fmod.hpp"
#include "fmod.h"


class Sound
{
private:
    bool on; //is sound on?
    bool possible; //is it possible to play sound?
    char * currentSound; //currently played sound
    //FMOD-specific stuff
    FMOD_RESULT result;
    FMOD_SYSTEM * fmodsystem;
    FMOD_SOUND * sound;
    FMOD_CHANNEL * channel;

public:
    Sound();
    ~Sound();
    void initialise (void); 
    void setVolume (float v); 
    void load (const char * filename); 
    void unload (void);
    void play (bool pause = false); 
    bool getSound (void); 
    void setPause (bool pause); 
    void setSound (bool sound); 
    void toggleSound (void); 
    void togglePause (void); 

};

.cpp

#include "stdafx.h"
#include "Sound.h"
#include "fmod.h"
#include "fmod.hpp"

Sound::Sound()
{
    on = true; //is sound on?
    possible = true; //is it possible to play sound?
    currentSound=""; //currently played sound
    sound=0;

}

Sound::~Sound()
{

}

//initialises sound
void Sound::initialise (void) 
{

    //create the sound system. If fails, sound is set to impossible
    result = FMOD_System_Create(&fmodsystem);
    if (result != FMOD_OK) 
        possible = false;

    //if initialise the sound system. If fails, sound is set to impossible
    if (possible) 
        result = FMOD_System_Init(fmodsystem,2, FMOD_INIT_NORMAL, 0);

    if (result != FMOD_OK) 
        possible = false;

    //sets initial sound volume (mute)
    if (possible) 
        FMOD_Channel_SetVolume(channel,1.0f);
}

//sets the actual playing sound's volume
void Sound::setVolume (float v) 
{
    if (possible && on && v >= 0.0f && v <= 1.0f) 
    {
        FMOD_Channel_SetVolume(channel,v);
    }
}

//loads a soundfile
void Sound::load (const char * filename) 
{
    currentSound = (char *)filename;
    if (possible && on) 
    {
        result = FMOD_Sound_Release(sound);
        result = FMOD_System_CreateStream(fmodsystem,currentSound, FMOD_SOFTWARE, 0, &sound);
        if (result != FMOD_OK) 
            possible = false;
    }
}

//frees the sound object
void Sound::unload (void) 
{
    if (possible) 
    {
        result = FMOD_Sound_Release(sound);
    }
}

//plays a sound (no argument to leave pause as dafault)
void Sound::play (bool pause) 
{
    if (possible && on) 
    {
        result = FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound, pause, &channel);
        FMOD_Channel_SetMode(channel,FMOD_LOOP_NORMAL);
    }
}

//toggles sound on and off
void Sound::toggleSound (void) 
{
    on = !on;
    if (on == true) 
    { 
        load(currentSound); 
        play(); 
    }
    if (on == false) 
    { 
        unload(); 
    }
}

//pause or unpause the sound
void Sound::setPause (bool pause) 
{
    FMOD_Channel_SetPaused (channel, pause);
}

//turn sound on or off
void Sound::setSound (bool s) 
{
    on = s;
}

//toggle pause on and off
void Sound::togglePause (void) 
{
    FMOD_BOOL p;
    FMOD_Channel_GetPaused(channel,&p);
    FMOD_Channel_SetPaused (channel,!p);
}

//tells whether the sound is on or off
bool Sound::getSound (void) 
{
    return on;
}

Hit a brick wall here, anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒江雪… 2024-12-13 01:08:25

您在 initialise 中调用 FMOD_Channel_SetVolume(channel,1.0f),但 channel 变量尚未初始化,它会由 Sound::play 中的 FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound,pause, &channel); 初始化

You are calling FMOD_Channel_SetVolume(channel,1.0f) in initialise, but the channel variable isn't hasn't been initialized yet, it gets initialized by the FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound, pause, &channel); in Sound::play

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文