/
Sound.cpp
143 lines (112 loc) · 2.17 KB
/
Sound.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "Main.h"
PlayThread::PlayThread(MainFrame *parent,
PeakMeter *meter,
wxString bnkPath,
wxString imsPath,
wxString issPath)
: wxThread()
{
m_mainFrame = parent;
m_meter = meter;
m_sound = new Sound(parent);
// BANK
Bnk *bnk = m_sound->GetBnk();
bnk->Open(bnkPath);
// IMS
Ims *ims = m_sound->GetIms();
ims->Open(imsPath);
ims->MatchBnk(bnk->GetBnk());
char *title = ims->GetTitleJohab();
//parent->m_issViewer->OutTextXy(0, 0, title);
ims->Reset();
// ISS
Iss *iss = m_sound->GetIss();
if ( iss->Open(issPath) == true )
{
char *writer = iss->GetWriter();
//parent->m_issViewer->OutTextXy(0, 16, writer);
char *composer = iss->GetComposer();
//parent->m_issViewer->OutTextXy(0, 32, composer);
}
// PEAK METER
m_meter->Stop();
// Peak Meter ¾÷µ¥ÀÌÆ® ÁÖ±â
m_meter->Start(30); // 30ms
}
void PlayThread::OnExit()
{
delete m_sound;
m_playMode = STOPPED;
}
void* PlayThread::Entry()
{
m_playMode = PLAYING;
m_sound->Play();
}
void PlayThread::Stop()
{
m_sound->Stop();
}
Ims* PlayThread::GetIms()
{
return m_sound->GetIms();
}
Bnk* PlayThread::GetBnk()
{
return m_sound->GetBnk();
}
Iss* PlayThread::GetIss()
{
return m_sound->GetIss();
}
// ---------------------------------------------------------
Sound::Sound(MainFrame *parent)
{
this->myFrame = parent;
ym3812p = YM3812Init(3579545L, 22050);
SoundWarmInit();
m_ims = new Ims();
m_bnk = new Bnk();
m_iss = new Iss();
}
Sound::~Sound()
{
m_ims->Reset();
delete m_ims;
delete m_bnk;
delete m_iss;
YM3812Shutdown(ym3812p);
free_prepare_pcm_buffer (0);
free_prepare_pcm_buffer (1);
}
Ims *Sound::GetIms()
{
return m_ims;
}
Bnk *Sound::GetBnk()
{
return m_bnk;
}
Iss *Sound::GetIss()
{
return m_iss;
}
void Sound::Stop()
{
m_playMode=STOP;
}
bool Sound::Play()
{
init_prepare_pcm_buffer();
alloc_prepare_pcm_buffer(0);
alloc_prepare_pcm_buffer(1);
prepare_next(myFrame, PREPARE_BUFFER_SIZE, 0);
SDL_PauseAudio(0);
while(1)
{
wxMilliSleep(100);
if ( m_playMode == STOP )
break;
}
SDL_PauseAudio(1);
}