From 29c02c33749f9ca21ffa1c22cc2cc37f58584467 Mon Sep 17 00:00:00 2001 From: rodri Date: Tue, 23 May 2023 15:45:13 +0000 Subject: integrated cmixer for sound and sfx. fixed the vfx drawing procedure so that it treats p as the center when rendering the sprite. --- musw.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'musw.c') diff --git a/musw.c b/musw.c index ef5d331..ef75c9f 100644 --- a/musw.c +++ b/musw.c @@ -11,6 +11,7 @@ #include #include "dat.h" #include "fns.h" +#include "cmixer.h" enum { GSIntro, @@ -675,6 +676,24 @@ State *playing_δ(State *s, void*) return s; } +void +soundproc(void *) +{ + Biobuf *aout; + uchar adata[512]; + + threadsetname("soundproc"); + + aout = Bopen("/dev/audio", OWRITE); + if(aout == nil) + sysfatal("Bopen: %r"); + + for(;;){ + cm_process((void *)adata, sizeof(adata)/2); + Bwrite(aout, adata, sizeof adata); + } +} + void usage(void) { @@ -690,6 +709,7 @@ threadmain(int argc, char *argv[]) char *server; int fd; Vfx *vfx; + cm_Source *bgsound; Mousectl *mc; Ioproc *io; @@ -717,6 +737,9 @@ threadmain(int argc, char *argv[]) sysfatal("initdraw: %r"); if((mc = initmouse(nil, screen)) == nil) sysfatal("initmouse: %r"); + cm_init(44100); + cm_set_master_gain(0.5); + display->locking = 1; unlockdisplay(display); @@ -751,6 +774,13 @@ threadmain(int argc, char *argv[]) vfxtab[VFX_BULLET_EXPLOSION] = readpngsprite("assets/vfx/bullet.explosion.png", ZP, Rect(0, 0, 32, 32), 12, 100); initvfx(&vfxqueue); + bgsound = cm_new_source_from_file("assets/sfx/intro.wav"); + if(bgsound == nil) + sysfatal("cm_new_source_from_file: %s", cm_get_error()); + cm_play(bgsound); + + proccreate(soundproc, nil, mainstacksize); + gamestates[GSIntro].δ = intro_δ; gamestates[GSConnecting].δ = connecting_δ; gamestates[GSMatching].δ = matching_δ; -- cgit v1.2.3