summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteven Fuller <relnev@icculus.org>2001-08-14 23:36:15 +0000
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-20 02:22:36 +0200
commit14d3cc45bcf1a9dce1e982fd82b79d7053be4048 (patch)
treea313e704cdc20ab2095ec8f80bb7bebf278af3c6 /src
parent48c6088c27bab6ed892fe52df99ca7d5f1803597 (diff)
Fixed sound length and looping. (Setting looping on a source must be done
after setting the buffer)
Diffstat (limited to 'src')
-rw-r--r--src/avp/psnd.c22
-rw-r--r--src/openal.c19
2 files changed, 22 insertions, 19 deletions
diff --git a/src/avp/psnd.c b/src/avp/psnd.c
index 2744ab5..efdf0d8 100644
--- a/src/avp/psnd.c
+++ b/src/avp/psnd.c
@@ -113,8 +113,9 @@ void SoundSys_Management(void)
if(ActiveSounds[i].soundIndex==SID_NOSOUND) continue; /* empty slot */
numActive++;
- if(PlatSoundHasStopped(i)!=0 && !ActiveSounds[i].paused)
+ if(PlatSoundHasStopped(i) && !ActiveSounds[i].paused)
{
+printf("SoundSys_Management: %d\n", i);
Sound_Stop(i);
continue;
}
@@ -343,7 +344,6 @@ void Sound_Play(SOUNDINDEX soundNumber, char *format, ...)
int reverb_off = 0;
int soundStartPosition = 0;
-printf("1 Play: %d\n", soundNumber);
{
extern int PlaySounds;
if (!PlaySounds) return;
@@ -351,17 +351,12 @@ printf("1 Play: %d\n", soundNumber);
if(!SoundSwitchedOn) return;
-printf("2 Play\n");
/* check soundIndex for bounds, whether it has been loaded, and number of instances */
if((soundNumber<0)||(soundNumber>=SID_MAXIMUM)) return;
-printf("A Play: %s\n", GameSounds[soundNumber].wavName);
if(!(GameSounds[soundNumber].loaded)) return;
-printf("B Play\n");
if(!(GameSounds[soundNumber].activeInstances<SOUND_MAXINSTANCES)) return;
-printf("3 Play\n");
-
db_logf5(("About to play sound %i", soundNumber));
/* initialise volume and pitch from game sound data */
@@ -452,8 +447,6 @@ printf("3 Play\n");
return;
}
-printf("4 Play\n");
-
/* Deal with resource allocation. */
{
/* Range of active buffers to search. */
@@ -496,6 +489,7 @@ printf("4 Play\n");
db_log3("Failed to find a lower priority sound.");
return; /* give up */
}
+printf("Play We cannot be here already: %d!\n", newIndex);
/* remove it, and use it's slot */
db_log3("Stopping a lower priority sound.");
Sound_Stop(newIndex);
@@ -517,7 +511,8 @@ printf("4 Play\n");
ActiveSounds[newIndex].reverb_off=reverb_off;
if(loop) ActiveSounds[newIndex].loop = 1;
else ActiveSounds[newIndex].loop = 0;
-printf("Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
+//printf("Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
+printf("Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop);
if(worldPosn)
{
VECTORCH zeroPosn = {0,0,0};
@@ -588,8 +583,11 @@ void Sound_Stop(int activeSoundNumber)
*(ActiveSounds[activeSoundNumber].externalRef) = SOUND_NOACTIVEINDEX;
/* stop the sound: it may have already stopped, of course, but never mind */
+
PlatStopSound(activeSoundNumber);
-
+
+printf("Stop: %d %d %s\n", activeSoundNumber, soundNo, GameSounds[soundNo].wavName);
+
/* release the active sound slot */
{ /* CEM - FIXME: hack */
int buf = ActiveSounds[activeSoundNumber].ds3DBufferP;
@@ -970,4 +968,4 @@ static SOUNDINDEX GetSoundIndexFromNameAndIndex(const char* name,SOUNDINDEX inde
}
}
return SID_NOSOUND;
-} \ No newline at end of file
+}
diff --git a/src/openal.c b/src/openal.c
index 5c841c8..e073f66 100644
--- a/src/openal.c
+++ b/src/openal.c
@@ -12,6 +12,7 @@
#include "3dc.h"
#include "platform.h"
+#include "inline.h"
#include "psndplat.h"
#include "gamedef.h"
#include "avpview.h"
@@ -112,14 +113,14 @@ int PlatPlaySound(int activeIndex)
if (!PlatSoundHasStopped(activeIndex))
PlatStopSound (activeIndex);
-// if (ActiveSounds[activeIndex].loop)
-// alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_LOOPING, AL_TRUE);
-// else
- alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_LOOPING, AL_FALSE);
-
alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_BUFFER,
GameSounds[si].dsBufferP);
+ if (ActiveSounds[activeIndex].loop)
+ alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_LOOPING, AL_TRUE);
+ else
+ alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_LOOPING, AL_FALSE);
+
if (ActiveSounds[activeIndex].pitch != GameSounds[si].pitch) {
int ok = PlatChangeSoundPitch (activeIndex, ActiveSounds[activeIndex].pitch);
@@ -453,13 +454,17 @@ fprintf (stderr, "Loaded %s\n", GameSounds[soundIndex].wavName);
}
if ((rfmt == AUDIO_S16LSB) || (rfmt == AUDIO_S16MSB)) {
+ int bps;
+
if (rchan == 2) {
rfmt = AL_FORMAT_STEREO16;
- seclen = len / (rfreq * 2 * 2);
+ bps = rfreq * 2 * 2;
} else if (rchan == 1) {
rfmt = AL_FORMAT_MONO16;
- seclen = len / (rfreq * 2);
+ bps = rfreq * 2 * 1;
}
+
+ seclen = DIV_FIXED(len, bps);
} else
return (unsigned char *)0;