Mercurial > hg > index.fcgi > lj > lj046
view src/pcsound.c @ 2:80a2761bd3a4
change DS keys (add alt. rotate)
author | paulo@localhost |
---|---|
date | Mon, 23 Mar 2009 01:19:12 -0700 |
parents | |
children |
line source
1 #include "ljpc.h"
2 extern const DATAFILE *sound_dat;
3 extern char withSound;
5 static const unsigned short shiftPitches[16] = {
6 630, 667, 707, 749, 794, 841, 891, 944,
7 1000, 1059, 1122, 1189, 1260, 1335, 1424, 1498
8 };
10 /**
11 * Plays a sample from datafile by name, with the specified volume
12 * and the specified rate scale factor, panned center, without loop.
13 * @param filename name of object in datafile
14 * @param vol scale factor for volume (0-255); if set to 0,
15 * stops all voices playing the sample
16 * @param pitch scale factor for playback rate (1000 = normal; 2000 = double speed)
17 */
18 static void playPitchSample(const char *filename, int vol, int pitch) {
19 if (withSound && sound_dat) {
20 const DATAFILE *entry = find_datafile_object(sound_dat, filename);
22 if (entry) {
23 if (vol < 1) {
24 stop_sample(entry->dat);
25 } else {
26 play_sample(entry->dat, vol, 128, pitch, 0);
27 }
28 }
29 }
30 }
32 void ezPlaySample(const char *filename, int vol) {
33 playPitchSample(filename, vol, 1000);
34 }
36 void playSampleForTetromino(int piece) {
37 static const char tetrominoNames[] = "IJLOSTZ22V";
39 piece &= LJP_MASK;
40 if (piece >= 0 && piece < 10) {
41 char filename[32];
42 usprintf(filename, "next%c_wav", tetrominoNames[piece]);
43 ezPlaySample(filename, 128);
44 }
45 }
47 void playSoundEffects(LJView *v, LJBits sounds, int countdown) {
48 // Handle sound
49 if ((sounds & LJSND_SPAWN)
50 && !(v->hideNext)) {
51 playSampleForTetromino(v->field->curPiece[1]);
52 }
53 if (sounds & LJSND_HOLD) {
54 ezPlaySample("hold_wav", 128);
55 }
56 if (sounds & LJSND_ROTATE) {
57 ezPlaySample("rotate_wav", 128);
58 }
59 if (sounds & LJSND_IRS) {
60 ezPlaySample("irs_wav", 128);
61 }
62 if (sounds & LJSND_SQUARE) {
63 ezPlaySample("square_wav", 128);
64 }
65 if (sounds & LJSND_SHIFT) {
66 int x = v->plat->skin->shiftScale
67 ? v->field->x + 8 - (LJ_PF_WID - 4) / 2
68 : 8;
69 int pitch = shiftPitches[x];
70 playPitchSample("shift_wav", 128, pitch);
71 }
72 if (sounds & LJSND_LAND) {
73 ezPlaySample("land_wav", 192);
74 }
75 if (sounds & LJSND_LOCK) {
76 ezPlaySample("lock_wav", 192);
77 }
78 if (sounds & LJSND_LINE) {
79 ezPlaySample("line_wav", 128);
80 }
81 if (sounds & LJSND_SECTIONUP) {
82 ezPlaySample("sectionup_wav", 128);
83 }
85 if (v->plat->b2bcd1 > 0) {
86 if (--v->plat->b2bcd1 == 0) {
87 playPitchSample("line_wav", 148, 1200);
88 }
89 }
90 if (sounds & LJSND_SETB2B) {
91 v->plat->b2bcd1 = 10;
92 }
93 if (v->plat->b2bcd2 > 0) {
94 if (--v->plat->b2bcd2 == 0) {
95 playPitchSample("line_wav", 168, 1440);
96 }
97 }
98 if (sounds & LJSND_B2B) {
99 v->plat->b2bcd2 = 20;
100 }
101 if (countdown < v->control->countdown) {
102 char name[32];
103 usprintf(name, "count_%d_wav", countdown);
104 ezPlaySample(name, 128);
105 }
106 LJMusic_poll(v->plat->skin->bgm);
107 }