paulo@0: #include "ljpc.h" paulo@0: extern const DATAFILE *sound_dat; paulo@0: extern char withSound; paulo@0: paulo@0: static const unsigned short shiftPitches[16] = { paulo@0: 630, 667, 707, 749, 794, 841, 891, 944, paulo@0: 1000, 1059, 1122, 1189, 1260, 1335, 1424, 1498 paulo@0: }; paulo@0: paulo@0: /** paulo@0: * Plays a sample from datafile by name, with the specified volume paulo@0: * and the specified rate scale factor, panned center, without loop. paulo@0: * @param filename name of object in datafile paulo@0: * @param vol scale factor for volume (0-255); if set to 0, paulo@0: * stops all voices playing the sample paulo@0: * @param pitch scale factor for playback rate (1000 = normal; 2000 = double speed) paulo@0: */ paulo@0: static void playPitchSample(const char *filename, int vol, int pitch) { paulo@0: if (withSound && sound_dat) { paulo@0: const DATAFILE *entry = find_datafile_object(sound_dat, filename); paulo@0: paulo@0: if (entry) { paulo@0: if (vol < 1) { paulo@0: stop_sample(entry->dat); paulo@0: } else { paulo@0: play_sample(entry->dat, vol, 128, pitch, 0); paulo@0: } paulo@0: } paulo@0: } paulo@0: } paulo@0: paulo@0: void ezPlaySample(const char *filename, int vol) { paulo@0: playPitchSample(filename, vol, 1000); paulo@0: } paulo@0: paulo@0: void playSampleForTetromino(int piece) { paulo@0: static const char tetrominoNames[] = "IJLOSTZ22V"; paulo@0: paulo@0: piece &= LJP_MASK; paulo@0: if (piece >= 0 && piece < 10) { paulo@0: char filename[32]; paulo@0: usprintf(filename, "next%c_wav", tetrominoNames[piece]); paulo@0: ezPlaySample(filename, 128); paulo@0: } paulo@0: } paulo@0: paulo@0: void playSoundEffects(LJView *v, LJBits sounds, int countdown) { paulo@0: // Handle sound paulo@0: if ((sounds & LJSND_SPAWN) paulo@0: && !(v->hideNext)) { paulo@0: playSampleForTetromino(v->field->curPiece[1]); paulo@0: } paulo@0: if (sounds & LJSND_HOLD) { paulo@0: ezPlaySample("hold_wav", 128); paulo@0: } paulo@0: if (sounds & LJSND_ROTATE) { paulo@0: ezPlaySample("rotate_wav", 128); paulo@0: } paulo@0: if (sounds & LJSND_IRS) { paulo@0: ezPlaySample("irs_wav", 128); paulo@0: } paulo@0: if (sounds & LJSND_SQUARE) { paulo@0: ezPlaySample("square_wav", 128); paulo@0: } paulo@0: if (sounds & LJSND_SHIFT) { paulo@0: int x = v->plat->skin->shiftScale paulo@0: ? v->field->x + 8 - (LJ_PF_WID - 4) / 2 paulo@0: : 8; paulo@0: int pitch = shiftPitches[x]; paulo@0: playPitchSample("shift_wav", 128, pitch); paulo@0: } paulo@0: if (sounds & LJSND_LAND) { paulo@0: ezPlaySample("land_wav", 192); paulo@0: } paulo@0: if (sounds & LJSND_LOCK) { paulo@0: ezPlaySample("lock_wav", 192); paulo@0: } paulo@0: if (sounds & LJSND_LINE) { paulo@0: ezPlaySample("line_wav", 128); paulo@0: } paulo@0: if (sounds & LJSND_SECTIONUP) { paulo@0: ezPlaySample("sectionup_wav", 128); paulo@0: } paulo@0: paulo@0: if (v->plat->b2bcd1 > 0) { paulo@0: if (--v->plat->b2bcd1 == 0) { paulo@0: playPitchSample("line_wav", 148, 1200); paulo@0: } paulo@0: } paulo@0: if (sounds & LJSND_SETB2B) { paulo@0: v->plat->b2bcd1 = 10; paulo@0: } paulo@0: if (v->plat->b2bcd2 > 0) { paulo@0: if (--v->plat->b2bcd2 == 0) { paulo@0: playPitchSample("line_wav", 168, 1440); paulo@0: } paulo@0: } paulo@0: if (sounds & LJSND_B2B) { paulo@0: v->plat->b2bcd2 = 20; paulo@0: } paulo@0: if (countdown < v->control->countdown) { paulo@0: char name[32]; paulo@0: usprintf(name, "count_%d_wav", countdown); paulo@0: ezPlaySample(name, 128); paulo@0: } paulo@0: LJMusic_poll(v->plat->skin->bgm); paulo@0: } paulo@0: