summaryrefslogtreecommitdiff
path: root/src/egg/audio/eggAudioSystem.cpp
blob: 844853abdd0350e1582c53e53ebb82308bd4a25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "egg/audio/eggAudioSystem.h"

#include "nw4r/snd/snd_SoundSystem.h"


namespace EGG {

AudioSystem *AudioSystem::sInstanse;

AudioSystem::AudioSystem() {
    mSavedMasterVolume = 1.0f;
    mShutdownStatus = 0;
    mResetStatus = 0;
    sInstanse = this;
}

AudioSystem::~AudioSystem() {}

void AudioSystem::reset(s32 ms) {
    if (mShutdownStatus == 0 && mResetStatus == 0) {
        mSavedMasterVolume = nw4r::snd::SoundSystem::GetMasterVolume();
        nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * (1.0f / 60.f * 1000.0f));
        mResetStatus = 1;
    }
}

void AudioSystem::recoverReset() {
    if (mShutdownStatus == 0) {
        nw4r::snd::SoundSystem::SetMasterVolume(mSavedMasterVolume, 0);
        mResetStatus = 0;
    }
}

void AudioSystem::shutdown(s32 ms) {
    if (mShutdownStatus == 0) {
        mShutdownStatus = 1;
        nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * (1.0f / 60.f * 1000.0f));
    }
}

void AudioSystem::calc() {
    f32 masterVolume = nw4r::snd::SoundSystem::GetMasterVolume();

    if (mShutdownStatus == 1 && masterVolume == 0.0f) {
        nw4r::snd::SoundSystem::PrepareReset();
        nw4r::snd::SoundSystem::WaitForResetReady();
        mShutdownStatus = 2;
    }

    if (mShutdownStatus != 2 && mResetStatus == 1 && masterVolume == 0.0f) {
        mResetStatus = 2;
    }
}

} // namespace EGG