forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FadeSound.cpp
90 lines (76 loc) · 2 KB
/
FadeSound.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//---------------------------------------------------------------------------
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak and others
*/
#include "system.hpp"
#include "classes.hpp"
#pragma hdrstop
#include "Timer.h"
#include "FadeSound.h"
__fastcall TFadeSound::TFadeSound()
{
Sound = NULL;
fFade = 0;
dt = 0;
fTime = 0;
}
__fastcall TFadeSound::~TFadeSound() { Free(); }
void TFadeSound::Free() {}
void TFadeSound::Init(char *Name, float fNewFade)
{
Sound = TSoundsManager::GetFromName(Name, false);
if (Sound)
Sound->SetVolume(0);
fFade = fNewFade;
fTime = 0;
}
void TFadeSound::TurnOn()
{
State = ss_Starting;
Sound->Play(0, 0, DSBPLAY_LOOPING);
fTime = fFade;
}
void TFadeSound::TurnOff() { State = ss_ShuttingDown; }
void TFadeSound::Update()
{
if (State == ss_Starting)
{
fTime += Timer::GetDeltaTime();
// SoundStart->SetVolume(-1000*(4-fTime)/4);
if (fTime >= fFade)
{
fTime = fFade;
State = ss_Commencing;
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * (fTime) / fFade);
}
else if (Timer::GetSoundTimer())
{
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * (fTime) / fFade);
}
}
else if (State == ss_ShuttingDown)
{
fTime -= Timer::GetDeltaTime();
if (fTime <= 0)
{
State = ss_Off;
fTime = 0;
Sound->Stop();
}
if (Timer::GetSoundTimer())
{ // DSBVOLUME_MIN
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * fTime / fFade);
}
}
}
void TFadeSound::Volume(long vol)
{
float glos = 1;
Sound->SetVolume(vol * glos);
}
//---------------------------------------------------------------------------
#pragma package(smart_init)