From 76eb4ada1d266f7c8295aced4537a2f9b3ae18ec Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 22 May 2006 01:05:56 +0000 Subject: [PATCH] Fix skill sounds when using JAudiolib instead of JFAud git-svn-id: https://svn.eduke32.com/eduke32@179 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/polymost.c | 10 +- polymer/eduke32/source/actors.c | 6 +- polymer/eduke32/source/funct.h | 2 +- polymer/eduke32/source/game.c | 12 +- polymer/eduke32/source/gameexec.c | 2 +- polymer/eduke32/source/jfaud_sounds.cpp | 876 ++++++++++++------------ polymer/eduke32/source/premap.c | 2 +- polymer/eduke32/source/sector.c | 2 +- polymer/eduke32/source/sounds.c | 8 +- 9 files changed, 461 insertions(+), 459 deletions(-) diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 0e9983114..ad57ec473 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -2759,11 +2759,11 @@ static void polymost_drawalls (long bunch) if ((oy < cy0) && (oy < cy1)) domost(x1,oy,x0,oy); else if ((oy < cy0) != (oy < cy1)) { /* cy1 cy0 - // / \ - //oy---------- oy--------- - // / \ - // cy0 cy1 - */ + // / \ + //oy---------- oy--------- + // / \ + // cy0 cy1 + */ ox = (oy-cy0)*(x1-x0)/(cy1-cy0) + x0; if (oy < cy0) { domost(ox,oy,x0,oy); domost(x1,cy1,ox,oy); } else { domost(ox,oy,x0,cy0); domost(x1,oy,ox,oy); } diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index af32135f7..d59b6c28a 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -2870,7 +2870,7 @@ void moveweapons(void) case COOLEXPLOSION1__STATIC: if( s->picnum == COOLEXPLOSION1 ) - if( !issoundplaying(WIERDSHOT_FLY) ) + if( !issoundplaying(i,WIERDSHOT_FLY) ) spritesound(WIERDSHOT_FLY,i); p = -1; @@ -4907,7 +4907,7 @@ void moveexplosions(void) // STATNUM 5 l = getflorzofslope(sect,s->x,s->y)-s->z; if( l > (16<<8) ) KILLIT(i); } - else */ if (!issoundplaying(ITEM_SPLASH)) + else */ if (!issoundplaying(i,ITEM_SPLASH)) spritesound(ITEM_SPLASH,i); } if(t[0] == 3) @@ -5598,7 +5598,7 @@ void moveeffectors(void) //STATNUM 3 { if( (sc->floorstat&1) == 0 && (sc->ceilingstat&1) == 0 ) { - if( !issoundplaying(hittype[i].lastvx) ) + if( !issoundplaying(i,hittype[i].lastvx) ) spritesound(hittype[i].lastvx,i); } else if( ud.monsters_off == 0 && sc->floorpal == 0 && (sc->floorstat&1) && rnd(8) ) diff --git a/polymer/eduke32/source/funct.h b/polymer/eduke32/source/funct.h index 20bf00ab5..def333cdf 100644 --- a/polymer/eduke32/source/funct.h +++ b/polymer/eduke32/source/funct.h @@ -349,7 +349,7 @@ extern void onvideomodechange(int newmode); extern void OnEvent(int iEventID, short sActor,short sPlayer,long lDist); extern int isspritemakingsound(short i, int num); -extern int issoundplaying(int num); +extern int issoundplaying(short i, int num); extern void stopspritesound(short num, short i); extern void updatenames(void); extern void sendboardname(void); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index c4a2287f4..e7975ff00 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2174,7 +2174,7 @@ void FTA(short q,struct player_struct *p) pub = NUMPAGES; pus = NUMPAGES; if (p == &ps[screenpeek]) - OSD_Printf("%s\n",fta_quotes[q]); + OSD_Printf("%s\n",strip_color_codes(fta_quotes[q])); } } } else OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,p->ftq); @@ -10503,19 +10503,19 @@ void dobonus(char bonusonly) if( ud.lockout == 0 && !KB_KeyWaiting() ) { sound(ENDSEQVOL3SND5); - while(issoundplaying(ENDSEQVOL3SND5)) { handleevents(); getpackets(); } + while(issoundplaying(-1,ENDSEQVOL3SND5)) { handleevents(); getpackets(); } if(KB_KeyWaiting()) goto ENDANM; sound(ENDSEQVOL3SND6); - while(issoundplaying(ENDSEQVOL3SND6)) { handleevents(); getpackets(); } + while(issoundplaying(-1,ENDSEQVOL3SND6)) { handleevents(); getpackets(); } if(KB_KeyWaiting()) goto ENDANM; sound(ENDSEQVOL3SND7); - while(issoundplaying(ENDSEQVOL3SND7)) { handleevents(); getpackets(); } + while(issoundplaying(-1,ENDSEQVOL3SND7)) { handleevents(); getpackets(); } if(KB_KeyWaiting()) goto ENDANM; sound(ENDSEQVOL3SND8); - while(issoundplaying(ENDSEQVOL3SND8)) { handleevents(); getpackets(); } + while(issoundplaying(-1,ENDSEQVOL3SND8)) { handleevents(); getpackets(); } if(KB_KeyWaiting()) goto ENDANM; sound(ENDSEQVOL3SND9); - while(issoundplaying(ENDSEQVOL3SND9)) { handleevents(); getpackets(); } + while(issoundplaying(-1,ENDSEQVOL3SND9)) { handleevents(); getpackets(); } } KB_FlushKeyBoardQueue(); diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 43a7a729b..b1be679c8 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -3754,7 +3754,7 @@ char parse(void) case CON_IFSOUND: insptr++; - parseifelse( Sound[*insptr].num > 0 ); + parseifelse( isspritemakingsound(g_i,*insptr) ); // parseifelse(SoundOwner[*insptr][0].i == g_i); break; diff --git a/polymer/eduke32/source/jfaud_sounds.cpp b/polymer/eduke32/source/jfaud_sounds.cpp index b87c0bc24..08aca40bb 100644 --- a/polymer/eduke32/source/jfaud_sounds.cpp +++ b/polymer/eduke32/source/jfaud_sounds.cpp @@ -28,7 +28,7 @@ extern "C" { # include "winlayer.h" #endif #include "osd.h" -long numenvsnds; + long numenvsnds; } typedef uint64 uint64_t; @@ -52,53 +52,53 @@ typedef uint64 uint64_t; class KenFile : public JFAudFile { private: - int fh; + int fh; public: - KenFile(const char *filename, const char *subfilename) - : JFAudFile(filename, subfilename) - { - fh = kopen4load(const_cast(filename), 0); - } + KenFile(const char *filename, const char *subfilename) + : JFAudFile(filename, subfilename) + { + fh = kopen4load(const_cast(filename), 0); + } - virtual ~KenFile() - { - if (fh >= 0) kclose(fh); - } + virtual ~KenFile() + { + if (fh >= 0) kclose(fh); + } - virtual bool IsOpen(void) const { return fh >= 0; } +virtual bool IsOpen(void) const { return fh >= 0; } - virtual long Read(long nbytes, void *buf) - { - if (fh < 0) return -1; - return kread(fh, buf, nbytes); - } - virtual long Seek(long pos, SeekFrom where) - { - int when; - if (fh < 0) return -1; - switch (where) { - case JFAudFile::Set: when = SEEK_SET; break; - case JFAudFile::Cur: when = SEEK_CUR; break; - case JFAudFile::End: when = SEEK_END; break; - default: return -1; - } - return klseek(fh, pos, when); - } - virtual long Tell(void) const - { - if (fh < 0) return -1; - return klseek(fh, 0, SEEK_CUR); - } - virtual long Length(void) const - { - if (fh < 0) return -1; - return kfilelength(fh); - } + virtual long Read(long nbytes, void *buf) + { + if (fh < 0) return -1; + return kread(fh, buf, nbytes); + } + virtual long Seek(long pos, SeekFrom where) + { + int when; + if (fh < 0) return -1; + switch (where) { + case JFAudFile::Set: when = SEEK_SET; break; + case JFAudFile::Cur: when = SEEK_CUR; break; + case JFAudFile::End: when = SEEK_END; break; + default: return -1; + } + return klseek(fh, pos, when); + } + virtual long Tell(void) const + { + if (fh < 0) return -1; + return klseek(fh, 0, SEEK_CUR); + } + virtual long Length(void) const + { + if (fh < 0) return -1; + return kfilelength(fh); + } }; static JFAudFile *openfile(const char *fn, const char *subfn) { - return static_cast(new KenFile(fn,subfn)); + return static_cast(new KenFile(fn,subfn)); } static void logfunc(const char *s) { initprintf("jfaud: %s", s); } @@ -108,31 +108,31 @@ static void logfunc(const char *s) { initprintf("jfaud: %s", s); } static float pitchtable[PITCHRANGE*PITCHSTEPS*2+1]; static void buildpitchtable(void) { - int i,j; - - for (i=-PITCHRANGE*PITCHSTEPS; i<=PITCHRANGE*PITCHSTEPS; i++) { - pitchtable[i+PITCHRANGE*PITCHSTEPS] = pow(1.0005777895, (1200.0/PITCHSTEPS)*(float)i); - } + int i,j; + + for (i=-PITCHRANGE*PITCHSTEPS; i<=PITCHRANGE*PITCHSTEPS; i++) { + pitchtable[i+PITCHRANGE*PITCHSTEPS] = pow(1.0005777895, (1200.0/PITCHSTEPS)*(float)i); + } } static float translatepitch(int p) { - float t; - int x; - x = (p * PITCHSTEPS / 1200) + PITCHRANGE*PITCHSTEPS; - if (x < 0) x = 0; - else if (x > (int)(sizeof(pitchtable)/sizeof(float))) x = sizeof(pitchtable)/sizeof(float); - t = pitchtable[x]; - /*if (t > 2.0) { - initprintf("translatepitch(%d) > 2.0\n", p); - t = 2.0; - }*/ - return t; + float t; + int x; + x = (p * PITCHSTEPS / 1200) + PITCHRANGE*PITCHSTEPS; + if (x < 0) x = 0; + else if (x > (int)(sizeof(pitchtable)/sizeof(float))) x = sizeof(pitchtable)/sizeof(float); + t = pitchtable[x]; + /*if (t > 2.0) { + initprintf("translatepitch(%d) > 2.0\n", p); + t = 2.0; + }*/ + return t; } typedef struct { - JFAudMixerChannel *chan; - int owner; // sprite number - int soundnum; // sound number + JFAudMixerChannel *chan; + int owner; // sprite number + int soundnum; // sound number } SoundChannel; static SoundChannel *chans = NULL; @@ -143,9 +143,9 @@ static bool havemidi = false, havewave = false; static void stopcallback(int r) { - jfaud->FreeSound(chans[r].chan); - chans[r].chan = NULL; - chans[r].owner = -1; + jfaud->FreeSound(chans[r].chan); + chans[r].chan = NULL; + chans[r].owner = -1; } void testcallback(unsigned long num) @@ -154,85 +154,85 @@ void testcallback(unsigned long num) static int keephandle(JFAudMixerChannel *handle, int soundnum, int owner) { - int i, freeh=-1; - for (i=NumVoices-1;i>=0;i--) { - if ((!chans[i].chan || !jfaud->IsValidSound(chans[i].chan)) && freeh<0) freeh=i; - else if (chans[i].chan == handle) { freeh=i; break; } - } - if (freeh<0) { - initprintf("Warning: keephandle() exhausted handle space!\n"); - return -1; - } + int i, freeh=-1; + for (i=NumVoices-1;i>=0;i--) { + if ((!chans[i].chan || !jfaud->IsValidSound(chans[i].chan)) && freeh<0) freeh=i; + else if (chans[i].chan == handle) { freeh=i; break; } + } + if (freeh<0) { + initprintf("Warning: keephandle() exhausted handle space!\n"); + return -1; + } - chans[freeh].chan = handle; - chans[freeh].soundnum = soundnum; - chans[freeh].owner = owner; - - return freeh; + chans[freeh].chan = handle; + chans[freeh].soundnum = soundnum; + chans[freeh].owner = owner; + + return freeh; } void SoundStartup(void) { - int i; + int i; - if (FXDevice < 0) return; + if (FXDevice < 0) return; - if (jfaud) return; - buildpitchtable(); + if (jfaud) return; + buildpitchtable(); - JFAud_SetLogFunc(logfunc); + JFAud_SetLogFunc(logfunc); - jfaud = new JFAud(); - if (!jfaud) return; + jfaud = new JFAud(); + if (!jfaud) return; - jfaud->SetUserOpenFunc(openfile); + jfaud->SetUserOpenFunc(openfile); #ifdef _WIN32 - jfaud->SetWindowHandle((void*)win_gethwnd()); + jfaud->SetWindowHandle((void*)win_gethwnd()); #endif - havewave = havemidi = false; - if (!jfaud->InitWave("software", NumVoices, MixRate)) { - delete jfaud; - jfaud = NULL; - return; - } + havewave = havemidi = false; + if (!jfaud->InitWave("software", NumVoices, MixRate)) { + delete jfaud; + jfaud = NULL; + return; + } - { - // the engine will take 60% of the system memory size for cache1d if there - // is less than the 16MB asked for in loadpics(), so we'll - // take 30% of what's left for the sound cache if that happened, or - // 50% of the system memory sans the 16MB maximum otherwise - unsigned k; - if (Bgetsysmemsize() <= MAXCACHE1DSIZE) - k = Bgetsysmemsize()/100*30; - else - k = Bgetsysmemsize()/100*50 - MAXCACHE1DSIZE; + { + // the engine will take 60% of the system memory size for cache1d if there + // is less than the 16MB asked for in loadpics(), so we'll + // take 30% of what's left for the sound cache if that happened, or + // 50% of the system memory sans the 16MB maximum otherwise + unsigned k; + if (Bgetsysmemsize() <= MAXCACHE1DSIZE) + k = Bgetsysmemsize()/100*30; + else + k = Bgetsysmemsize()/100*50 - MAXCACHE1DSIZE; jfaud->SetCacheItemAge(24*120); // 24 movements per second, 120 seconds max lifetime - } - - chans = new SoundChannel[NumVoices]; - if (!chans) { - delete jfaud; - jfaud = NULL; - return; - } + } - havewave = true; + chans = new SoundChannel[NumVoices]; + if (!chans) { + delete jfaud; + jfaud = NULL; + return; + } - for (i=NumVoices-1; i>=0; i--) { - chans[i].owner = -1; - } - - if (jfaud->InitMIDI(NULL)) havemidi = true; + havewave = true; + + for (i=NumVoices-1; i>=0; i--) { + chans[i].owner = -1; + } + + if (jfaud->InitMIDI(NULL)) havemidi = true; } void SoundShutdown(void) { - if (jfaud) delete jfaud; - if (chans) delete [] chans; - jfaud = NULL; - chans = NULL; - havewave = havemidi = false; + if (jfaud) delete jfaud; + if (chans) delete [] chans; + jfaud = NULL; + chans = NULL; + havewave = havemidi = false; } void MusicStartup(void) @@ -245,132 +245,132 @@ void MusicShutdown(void) void AudioUpdate(void) { - int i; + int i; - if (!jfaud) return; - if (havewave) - for (i=NumVoices-1; i>=0; i--) { - if (chans[i].chan && !jfaud->IsValidSound(chans[i].chan)) - chans[i].chan = NULL; - } - jfaud->Update(false); + if (!jfaud) return; + if (havewave) + for (i=NumVoices-1; i>=0; i--) { + if (chans[i].chan && !jfaud->IsValidSound(chans[i].chan)) + chans[i].chan = NULL; + } + jfaud->Update(false); } static char menunum = 0; void intomenusounds(void) { - short i; - short menusnds[] = { - LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, - CHAINGUN_FIRE, SQUISHED, KICK_HIT, - PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, - SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, - PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, - RPG_SHOOT, SELECT_WEAPON - }; - sound(menusnds[menunum++]); - menunum %= sizeof(menusnds)/sizeof(menusnds[0]); + short i; + short menusnds[] = { + LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, + CHAINGUN_FIRE, SQUISHED, KICK_HIT, + PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, + SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, + PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, + RPG_SHOOT, SELECT_WEAPON + }; + sound(menusnds[menunum++]); + menunum %= sizeof(menusnds)/sizeof(menusnds[0]); } void playmusic(char *fn) { - char dafn[BMAX_PATH], *dotpos; - int i; - const char *extns[] = { ".ogg",".mp3",".mid", NULL }; + char dafn[BMAX_PATH], *dotpos; + int i; + const char *extns[] = { ".ogg",".mp3",".mid", NULL }; - if (!MusicToggle) return; - if (!jfaud) return; + if (!MusicToggle) return; + if (!jfaud) return; - dotpos = Bstrrchr(fn,'.'); - if (dotpos && Bstrcasecmp(dotpos,".mid")) { - // has extension but isn't midi - jfaud->PlayMusic(fn, NULL); - } else { - Bstrcpy(dafn,fn); - dotpos = Bstrrchr(dafn,'.'); - if (!dotpos) dotpos = dafn+strlen(dafn); + dotpos = Bstrrchr(fn,'.'); + if (dotpos && Bstrcasecmp(dotpos,".mid")) { + // has extension but isn't midi + jfaud->PlayMusic(fn, NULL); + } else { + Bstrcpy(dafn,fn); + dotpos = Bstrrchr(dafn,'.'); + if (!dotpos) dotpos = dafn+strlen(dafn); - for (i=0; extns[i]; i++) { - Bstrcpy(dotpos, extns[i]); - if (jfaud->PlayMusic(dafn, NULL)) return; - } - } + for (i=0; extns[i]; i++) { + Bstrcpy(dotpos, extns[i]); + if (jfaud->PlayMusic(dafn, NULL)) return; + } + } } char loadsound(unsigned short num) { return 1; } int isspritemakingsound(short i, int num) // if num<0, check if making any sound at all { - int j,n=0; - - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - if (chans[j].owner == i) - if (num < 0 || chans[j].soundnum == num) n++; - } - return n; + int j,n=0; + + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + if (chans[j].owner == i) + if (num < 0 || chans[j].soundnum == num) n++; + } + return n; } -int issoundplaying(int num) +int issoundplaying(short i, int num) { - int j,n=0; - - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - if (chans[j].soundnum == num) n++; - } - - return n; + int j,n=0; + + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + if (chans[j].soundnum == num) n++; + } + + return n; } int xyzsound(short num, short i, long x, long y, long z) { - JFAudMixerChannel *chan; - int r, global = 0; - float gain = 1.0, pitch = 1.0; + JFAudMixerChannel *chan; + int r, global = 0; + float gain = 1.0, pitch = 1.0; int sndist; - if (!jfaud || !havewave || - num >= NUM_SOUNDS || - ((soundm[num] & SOUNDM_PARENT) && ud.lockout) || // parental mode - SoundToggle == 0 || - (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || - (ps[myconnectindex].gm & MODE_MENU) - ) return -1; + if (!jfaud || !havewave || + num >= NUM_SOUNDS || + ((soundm[num] & SOUNDM_PARENT) && ud.lockout) || // parental mode + SoundToggle == 0 || + (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || + (ps[myconnectindex].gm & MODE_MENU) + ) return -1; - if (soundm[num] & SOUNDM_PLAYER) { - sound(num); - return 0; - } - - if (soundm[num] & SOUNDM_DUKE) { - // Duke speech, one at a time only - int j; - - if (VoiceToggle == 0 || - (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && ud.coop != 1) - ) return -1; + if (soundm[num] & SOUNDM_PLAYER) { + sound(num); + return 0; + } + + if (soundm[num] & SOUNDM_DUKE) { + // Duke speech, one at a time only + int j; + + if (VoiceToggle == 0 || + (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && ud.coop != 1) + ) return -1; + + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || chans[j].owner < 0) continue; + if (soundm[ chans[j].soundnum ] & SOUNDM_DUKE) return -1; + } + } + + // XXX: here goes musicandsfx ranging. This will change the refdist. + + { + int ps = soundps[num], pe = soundpe[num], cx; + cx = klabs(pe-ps); + if (cx) { + if (ps < pe) pitch = translatepitch(ps + rand()%cx); + else pitch = translatepitch(pe + rand()%cx); + } else pitch = translatepitch(ps); + } - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || chans[j].owner < 0) continue; - if (soundm[ chans[j].soundnum ] & SOUNDM_DUKE) return -1; - } - } - - // XXX: here goes musicandsfx ranging. This will change the refdist. - - { - int ps = soundps[num], pe = soundpe[num], cx; - cx = klabs(pe-ps); - if (cx) { - if (ps < pe) pitch = translatepitch(ps + rand()%cx); - else pitch = translatepitch(pe + rand()%cx); - } else pitch = translatepitch(ps); - } - sndist = FindDistance3D((ps[screenpeek].oposx-SX),(ps[screenpeek].oposy-SY),(ps[screenpeek].oposz-SZ)>>4); if( i >= 0 && (soundm[num]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9 ) @@ -379,207 +379,207 @@ int xyzsound(short num, short i, long x, long y, long z) sndist += soundvo[num]; if(sndist < 0) sndist = 0; - //gain += soundvo[num]; - if (sndist && PN != MUSICANDSFX && - !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), - ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) + //gain += soundvo[num]; + if (sndist && PN != MUSICANDSFX && + !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), + ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) gain *= 0.4; - - switch(num) - { - case PIPEBOMB_EXPLODE: - case LASERTRIP_EXPLODE: - case RPG_EXPLODE: - gain = 1.0; - global = 1; - if (sector[ps[screenpeek].cursectnum].lotag == 2) pitch -= translatepitch(1024); - break; - default: - if(sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&SOUNDM_DUKE) == 0) - pitch = translatepitch(-768); - //if( sndist > 31444 && PN != MUSICANDSFX) - // return -1; - break; - } - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); -/* - // XXX: this is shit - if( Sound[num].num > 0 && PN != MUSICANDSFX ) - { - if( SoundOwner[num][0].i == i ) stopsound(num); - else if( Sound[num].num > 1 ) stopsound(num); - else if( badguy(&sprite[i]) && sprite[i].extra <= 0 ) stopsound(num); - } -*/ - - chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); - if (!chan) return -1; - - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); - chan->SetGain(gain*(FXVolume/252.0)); - chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); - if (soundm[num] & SOUNDM_GLOBAL) global = 1; - chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); - - if (PN == APLAYER && sprite[i].yvel == screenpeek) { - chan->SetRolloff(0.0); - chan->SetFollowListener(true); - chan->SetPosition(0.0, 0.0, 0.0); - } else { - chan->SetRolloff(global ? 0.0 : 0.2); - chan->SetFollowListener(false); + switch(num) + { + case PIPEBOMB_EXPLODE: + case LASERTRIP_EXPLODE: + case RPG_EXPLODE: + gain = 1.0; + global = 1; + if (sector[ps[screenpeek].cursectnum].lotag == 2) pitch -= translatepitch(1024); + break; + default: + if(sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&SOUNDM_DUKE) == 0) + pitch = translatepitch(-768); + //if( sndist > 31444 && PN != MUSICANDSFX) + // return -1; + break; + } + if(ps[screenpeek].sound_pitch) + pitch = translatepitch(ps[screenpeek].sound_pitch); + /* + // XXX: this is shit + if( Sound[num].num > 0 && PN != MUSICANDSFX ) + { + if( SoundOwner[num][0].i == i ) stopsound(num); + else if( Sound[num].num > 1 ) stopsound(num); + else if( badguy(&sprite[i]) && sprite[i].extra <= 0 ) stopsound(num); + } + */ + + chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); + if (!chan) return -1; + + if(ps[screenpeek].sound_pitch) + pitch = translatepitch(ps[screenpeek].sound_pitch); + + chan->SetGain(gain*(FXVolume/252.0)); + chan->SetPitch(pitch); + chan->SetLoop(soundm[num] & SOUNDM_LOOP); + if (soundm[num] & SOUNDM_GLOBAL) global = 1; + chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); + + if (PN == APLAYER && sprite[i].yvel == screenpeek) { + chan->SetRolloff(0.0); + chan->SetFollowListener(true); + chan->SetPosition(0.0, 0.0, 0.0); + } else { + chan->SetRolloff(global ? 0.0 : 0.2); + chan->SetFollowListener(false); chan->SetPosition((float)x/UNITSPERMETRE, (float)(-z>>4)/UNITSPERMETRE, (float)y/UNITSPERMETRE); - } - - r = keephandle(chan, num, i); - if (r >= 0) chan->SetStopCallback(stopcallback, r); - chan->Play(); - - return 0; + } + + r = keephandle(chan, num, i); + if (r >= 0) chan->SetStopCallback(stopcallback, r); + chan->Play(); + + return 0; } void sound(short num) { - JFAudMixerChannel *chan; - int r; - float pitch = 1.0; + JFAudMixerChannel *chan; + int r; + float pitch = 1.0; - if (!jfaud || !havewave || - num >= NUM_SOUNDS || - SoundToggle == 0 || - ((soundm[num] & SOUNDM_DUKE) && VoiceToggle == 0) || - ((soundm[num] & SOUNDM_PARENT) && ud.lockout) // parental mode - ) return; + if (!jfaud || !havewave || + num >= NUM_SOUNDS || + SoundToggle == 0 || + ((soundm[num] & SOUNDM_DUKE) && VoiceToggle == 0) || + ((soundm[num] & SOUNDM_PARENT) && ud.lockout) // parental mode + ) return; - { - int ps = soundps[num], pe = soundpe[num], cx; - cx = klabs(pe-ps); - if (cx) { - if (ps < pe) pitch = translatepitch(ps + rand()%cx); - else pitch = translatepitch(pe + rand()%cx); - } else pitch = translatepitch(ps); - } - - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); + { + int ps = soundps[num], pe = soundpe[num], cx; + cx = klabs(pe-ps); + if (cx) { + if (ps < pe) pitch = translatepitch(ps + rand()%cx); + else pitch = translatepitch(pe + rand()%cx); + } else pitch = translatepitch(ps); + } - chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); - if (!chan) return; + if(ps[screenpeek].sound_pitch) + pitch = translatepitch(ps[screenpeek].sound_pitch); - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); + chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); + if (!chan) return; - chan->SetGain(FXVolume/252.0); - chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); - chan->SetRolloff(0.0); - chan->SetFollowListener(true); - chan->SetPosition(0.0, 0.0, 0.0); - chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); + if(ps[screenpeek].sound_pitch) + pitch = translatepitch(ps[screenpeek].sound_pitch); - r = keephandle(chan, num, -1); - if (r >= 0) chan->SetStopCallback(stopcallback, r); - chan->Play(); + chan->SetGain(FXVolume/252.0); + chan->SetPitch(pitch); + chan->SetLoop(soundm[num] & SOUNDM_LOOP); + chan->SetRolloff(0.0); + chan->SetFollowListener(true); + chan->SetPosition(0.0, 0.0, 0.0); + chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); + + r = keephandle(chan, num, -1); + if (r >= 0) chan->SetStopCallback(stopcallback, r); + chan->Play(); } int spritesound(unsigned short num, short i) { - if (num >= NUM_SOUNDS) return -1; - return xyzsound(num,i,SX,SY,SZ); + if (num >= NUM_SOUNDS) return -1; + return xyzsound(num,i,SX,SY,SZ); } void stopsound(short num) { - int j; - - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].soundnum != num) continue; - - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } + int j; + + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].soundnum != num) continue; + + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } } void stopspritesound(short num, short i) { - int j; - - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i || chans[j].soundnum != num) continue; - - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - return; - } + int j; + + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i || chans[j].soundnum != num) continue; + + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + return; + } } void stopenvsound(short num, short i) { - int j; - - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i) continue; + int j; - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i) continue; + + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } } void pan3dsound(void) { - JFAudMixer *mix; - int j, global; - short i; - long cx, cy, cz, sx,sy,sz; - short ca,cs; - float gain; + JFAudMixer *mix; + int j, global; + short i; + long cx, cy, cz, sx,sy,sz; + short ca,cs; + float gain; - numenvsnds = 0; - if (!jfaud || !havewave) return; - mix = jfaud->GetWave(); - if (!mix) return; + numenvsnds = 0; + if (!jfaud || !havewave) return; + mix = jfaud->GetWave(); + if (!mix) return; jfaud->AgeCache(); - if(ud.camerasprite == -1) { - cx = ps[screenpeek].oposx; - cy = ps[screenpeek].oposy; - cz = ps[screenpeek].oposz; - cs = ps[screenpeek].cursectnum; - ca = ps[screenpeek].ang+ps[screenpeek].look_ang; - } else { - cx = sprite[ud.camerasprite].x; - cy = sprite[ud.camerasprite].y; - cz = sprite[ud.camerasprite].z; - cs = sprite[ud.camerasprite].sectnum; - ca = sprite[ud.camerasprite].ang; - } + if(ud.camerasprite == -1) { + cx = ps[screenpeek].oposx; + cy = ps[screenpeek].oposy; + cz = ps[screenpeek].oposz; + cs = ps[screenpeek].cursectnum; + ca = ps[screenpeek].ang+ps[screenpeek].look_ang; + } else { + cx = sprite[ud.camerasprite].x; + cy = sprite[ud.camerasprite].y; + cz = sprite[ud.camerasprite].z; + cs = sprite[ud.camerasprite].sectnum; + ca = sprite[ud.camerasprite].ang; + } - mix->SetListenerPosition((float)cx/UNITSPERMETRE, (float)(-cz>>4)/UNITSPERMETRE, (float)cy/UNITSPERMETRE); - mix->SetListenerOrientation((float)sintable[(ca+512)&2047]/16384.0, 0.0, (float)sintable[ca&2047]/16384.0, - 0.0, 1.0, 0.0); - - for (j=NumVoices-1; j>=0; j--) { + mix->SetListenerPosition((float)cx/UNITSPERMETRE, (float)(-cz>>4)/UNITSPERMETRE, (float)cy/UNITSPERMETRE); + mix->SetListenerOrientation((float)sintable[(ca+512)&2047]/16384.0, 0.0, (float)sintable[ca&2047]/16384.0, + 0.0, 1.0, 0.0); + + for (j=NumVoices-1; j>=0; j--) { int sndist; - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner < 0) continue; + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner < 0) continue; - global = 0; - gain = 1.0; - i = chans[j].owner; + global = 0; + gain = 1.0; + i = chans[j].owner; - sx = sprite[i].x; - sy = sprite[i].y; - sz = sprite[i].z; + sx = sprite[i].x; + sy = sprite[i].y; + sz = sprite[i].z; if( PN == APLAYER && sprite[i].yvel == screenpeek) { @@ -595,41 +595,41 @@ void pan3dsound(void) sndist += soundvo[j]; if(sndist < 0) sndist = 0; - //gain += soundvo[num]; - if (sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT) ) - gain *= 0.4; - - if(PN == MUSICANDSFX && SLT < 999) numenvsnds++; - if( soundm[ chans[j].soundnum ]&SOUNDM_GLOBAL ) global = 1; - - switch(chans[j].soundnum) { - case PIPEBOMB_EXPLODE: - case LASERTRIP_EXPLODE: - case RPG_EXPLODE: - gain = 1.0; - global = 1; - break; - default: - //if( sndist > 31444 && PN != MUSICANDSFX) { - // stopsound(j); - // continue; - //} - break; - } - - // A sound may move from player-relative 3D if the viewpoint shifts from the player - // through a viewscreen or viewpoint switching - chans[j].chan->SetGain(gain*(FXVolume/252.0)); - if (PN == APLAYER && sprite[i].yvel == screenpeek) { - chans[j].chan->SetRolloff(0.0); - chans[j].chan->SetFollowListener(true); - chans[j].chan->SetPosition(0.0, 0.0, 0.0); - } else { - chans[j].chan->SetRolloff(global ? 0.0 : 0.1); - chans[j].chan->SetFollowListener(false); - chans[j].chan->SetPosition((float)sx/UNITSPERMETRE, (float)(-sz>>4)/UNITSPERMETRE, (float)sy/UNITSPERMETRE); - } - } + //gain += soundvo[num]; + if (sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT) ) + gain *= 0.4; + + if(PN == MUSICANDSFX && SLT < 999) numenvsnds++; + if( soundm[ chans[j].soundnum ]&SOUNDM_GLOBAL ) global = 1; + + switch(chans[j].soundnum) { + case PIPEBOMB_EXPLODE: + case LASERTRIP_EXPLODE: + case RPG_EXPLODE: + gain = 1.0; + global = 1; + break; + default: + //if( sndist > 31444 && PN != MUSICANDSFX) { + // stopsound(j); + // continue; + //} + break; + } + + // A sound may move from player-relative 3D if the viewpoint shifts from the player + // through a viewscreen or viewpoint switching + chans[j].chan->SetGain(gain*(FXVolume/252.0)); + if (PN == APLAYER && sprite[i].yvel == screenpeek) { + chans[j].chan->SetRolloff(0.0); + chans[j].chan->SetFollowListener(true); + chans[j].chan->SetPosition(0.0, 0.0, 0.0); + } else { + chans[j].chan->SetRolloff(global ? 0.0 : 0.1); + chans[j].chan->SetFollowListener(false); + chans[j].chan->SetPosition((float)sx/UNITSPERMETRE, (float)(-sz>>4)/UNITSPERMETRE, (float)sy/UNITSPERMETRE); + } + } } void clearsoundlocks(void) @@ -654,49 +654,49 @@ void FX_SetReverbDelay( int delay ) int FX_VoiceAvailable( int priority ) { - int j; - - if (!jfaud) return 0; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) return 1; - } - return 0; + int j; + + if (!jfaud) return 0; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) return 1; + } + return 0; } int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ) + int priority, unsigned long callbackval ) { - printf("FX_PlayVOC3D()\n"); - return 0; + printf("FX_PlayVOC3D()\n"); + return 0; } int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ) + int priority, unsigned long callbackval ) { - printf("FX_PlayWAV3D()\n"); - return 0; + printf("FX_PlayWAV3D()\n"); + return 0; } int FX_StopSound( int handle ) { - printf("FX_StopSound()\n"); - return 0; + printf("FX_StopSound()\n"); + return 0; } int FX_StopAllSounds( void ) { - int j; - - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + int j; - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - return 0; + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } + + return 0; } void MUSIC_SetVolume( int volume ) @@ -705,18 +705,18 @@ void MUSIC_SetVolume( int volume ) void MUSIC_Pause( void ) { - if (jfaud) jfaud->PauseMusic(true); + if (jfaud) jfaud->PauseMusic(true); } void MUSIC_Continue( void ) { - if (jfaud) jfaud->PauseMusic(false); + if (jfaud) jfaud->PauseMusic(false); } int MUSIC_StopSong( void ) { - if (jfaud) jfaud->StopMusic(); - return 0; + if (jfaud) jfaud->StopMusic(); + return 0; } void MUSIC_RegisterTimbreBank( unsigned char *timbres ) diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 8cac9c4b3..3c4b8657e 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -999,7 +999,7 @@ void newgame(char vn,char ln,char sk) short i; if(globalskillsound >= 0) - while(issoundplaying(globalskillsound)) { handleevents(); getpackets(); } + while(issoundplaying(-1,globalskillsound)) { handleevents(); getpackets(); } globalskillsound = -1; waitforeverybody(); diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 66abe5e97..7a869c40e 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -2032,7 +2032,7 @@ void checkhitsprite(short i,short sn) sprite[sn].xvel = (sprite[i].xvel>>1)+(sprite[i].xvel>>2); sprite[sn].ang -= (SA<<1)+1024; SA = getangle(SX-sprite[sn].x,SY-sprite[sn].y)-512; - if(issoundplaying(POOLBALLHIT) < 2) + if(issoundplaying(i,POOLBALLHIT) < 2) spritesound(POOLBALLHIT,i); } else diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index bf702f653..ad4cf242b 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -624,10 +624,12 @@ void clearsoundlocks(void) int isspritemakingsound(short i, int num) { if (num < 0) num=0; // FIXME - return issoundplaying(num) > 0; + return (Sound[num].num > 0); } -int issoundplaying(int num) +int issoundplaying(short i, int num) { - return Sound[num].num; + if(i == -1) + return (Sound[num].lock != 199); + else return (Sound[num].num); }