From 5383311cbabf123f2bdeff21d6b0bff5a730000c Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Tue, 1 Feb 2011 20:35:41 -0500 Subject: [PATCH] testing playing .wav files. lol sounds --- src/interface.c | 3 +- src/main.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/interface.c b/src/interface.c index 5940e6ead..298957113 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3866,7 +3866,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n" - "Current commands are quit, set, reset, load, create, file, kill\n" + "Current commands are quit, set, reset, load, create, file, kill, sound\n" "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" "You can also use 'all' instead of a particle number to do it to everything.\n" "You can now use particle names (ex. set type all deut)\n" @@ -3875,6 +3875,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show "Create particles with 'create deut x,y' where x and y are the coords\n" "Run scripts from file 'file filename'\n" "You can delete/kill a particle with 'kill x,y'" + "Play a sound with (sound blah.wav)" ,255, 187, 187, 255); cc = 0; diff --git a/src/main.c b/src/main.c index b5b2767e4..d4d4f01c9 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,69 @@ #include #include +#define NUM_SOUNDS 2 +struct sample { + Uint8 *data; + Uint32 dpos; + Uint32 dlen; +} sounds[NUM_SOUNDS]; + +void mixaudio(void *unused, Uint8 *stream, int len) +{ + int i; + Uint32 amount; + + for ( i=0; i len ) { + amount = len; + } + SDL_MixAudio(stream, &sounds[i].data[sounds[i].dpos], amount, SDL_MIX_MAXVOLUME); + sounds[i].dpos += amount; + } +} + +void PlaySound(char *file) +{ + int index; + SDL_AudioSpec wave; + Uint8 *data; + Uint32 dlen; + SDL_AudioCVT cvt; + + /* Look for an empty (or finished) sound slot */ + for ( index=0; index