annotate src/pcsound.c @ 3:17286938e22a

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