My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

#include <mikmod.h>


#include <iostream>
#include <string>

#include <assert.h>

#include "BuildDefines.h"

#include "WavPlayer.h"


//#if (BUILD_TYPE == RELEASE)
#ifdef RELEASE

#define SOUNDS_PATH "./Sounds/"

#else
#define SOUNDS_PATH "ms0:/PSP/Game/TimeCube/Sounds/"

#endif

using namespace std;

//**********************************************************
WavPlayer::WavPlayer():
paused(true)
{

md_sndfxvolume = 0xFF;
md_volume = 0xFF;

}

//**********************************************************

WavSample::WavSample():
voice(0),
pan(127),
vol(254),
freq(22000),
sample(NULL)
{


}

//**********************************************************

WavSample::~WavSample()
{

}

//**********************************************************

void WavSample::freeSample()
{

if(sample)
{

cout << "Sample freed..." << endl;
fflush(stdout);

Sample_Free(sample);

}

sample = NULL;

}

//**********************************************************
/**
* The use in the thread for processing sound
*/

void WavPlayer::update()
{

if(paused)
return;

MikMod_Update();

}

//**********************************************************
/**
* The use in the thread for processing sound
*/

void WavPlayer::setPause(bool p)
{

paused = p;
if(paused)
MikMod_DisableOutput();
else
MikMod_EnableOutput();

}

//**********************************************************

void my_error_handler()

{

PRINT("_mm_critical %d\n", MikMod_critical);

PRINT("_mm_errno %d\n", MikMod_errno);

PRINT("%s\n", MikMod_strerror(MikMod_errno));

return;

}

//**********************************************************
/**
* Load sample
*/

void WavSample::loadSample(const char* file)
{

assert(file);

string path = SOUNDS_PATH;
path += file;
if(sample == NULL)
{

sample = Sample_Load((CHAR*) path.c_str());
if(sample == NULL)
{

ERROR("Cannot load file: %s\n", path.c_str());
exit(1);

}

}
else
{

ERROR("Cannot load sample, one was already loaded!");

}
assert(sample);

}

//**********************************************************

void WavPlayer::addSample(WavSample* s)
{

samples.push_back(s);

}


//**********************************************************
/**
* Play the wave sample
*/

void WavSample::play()
{

SBYTE i = Sample_Play(sample,0,0);
Voice_SetVolume(i, vol);
//Voice_SetPanning(voice, pan);

}


//**********************************************************
/**
* @param function pointer to the thread we are going to
* use
*/

int WavPlayer::initWav()
{

if (!MikMod_InitThreads())
{
PRINT("MikMod thread init failed\n");
}


MikMod_RegisterErrorHandler(my_error_handler);

/* register all the drivers */

MikMod_RegisterAllDrivers();

/* register all the module loaders */

MikMod_RegisterAllLoaders();

/* initialize the library */
md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC;
md_reverb = 0;
md_pansep = 128;

if (MikMod_Init((char*)""))
{

PRINT("Could not initialize sound, reason: %s\n",
MikMod_strerror(MikMod_errno));
exit(1);

}

MikMod_SetNumVoices(-1, 8);
/* get ready to play */

PRINT("Starting WavPlayer....\n");
MikMod_EnableOutput();

return 1;

}


//**********************************************************
/**
* Shut down the Mikmod sound system
*/

void WavPlayer::shutdown()
{

PRINT("Shutdown WavPlayer...\n");

// Stop MikMod lib from feeding audio buffers
MikMod_DisableOutput();

// if (thread_id > 0)
// {
//
// SceUInt timeout = 100000;
// sceKernelWaitThreadEnd(thread_id, &timeout);
//
// // Delete the play thread from the OS
// sceKernelDeleteThread(thread_id);
//
// }

Player_Stop();

// Delete the samples manually (forced destruction), since prob needed before
// MikMod_Exit leaves the references hanging.
for(unsigned int i = 0; i < samples.size(); i++)
{

// Free sample from MikMod system
if(samples[i])
samples[i]->freeSample();

}
samples.clear();

MikMod_Exit();

}

Change log

r405 by kyle2 on May 29, 2011   Diff
Adding particle system
- Works nice.
- Needs better alpha blending and sprite
rotation

Go to: 
Project members, sign in to write a code review

Older revisions

r380 by kyle2 on May 27, 2011   Diff
Changing all the sound samples to
16bit
-  Bug in Audacity tells you all
samples are 32bit when opening them..
(lame)
...
r216 by kyle2 on Apr 10, 2011   Diff
Weekly checkin.  Maybe to get ported
to old laptop

r214 by kyle2 on Feb 23, 2011   Diff
Deleted old background

All revisions of this file

File info

Size: 4152 bytes, 274 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting