Downmix SDC SFX sounds to mono to allow positioning to work

Closes #174.
This commit is contained in:
Fingercomp 2025-08-05 01:04:39 +03:00
parent 09277887a6
commit 9192d7fc48
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37
9 changed files with 28 additions and 20 deletions

View File

@ -21,7 +21,7 @@ object AL10W extends Logging {
val exc = OpenAlException(func, errName, err)
if (Settings.get.logAudioErrorStacktrace) {
logger.error(exc)
logger.error(exc.getMessage, exc)
} else {
logger.error(exc.getMessage)
}

View File

@ -34,15 +34,15 @@ class SoundSource(
Audio.getSourceStatus(this)
}
def isPlaying: Boolean = {
def playing: Boolean = {
status == SoundSource.Status.Playing
}
def isPaused: Boolean = {
def paused: Boolean = {
status == SoundSource.Status.Paused
}
def isStopped: Boolean = {
def stopped: Boolean = {
status == SoundSource.Status.Stopped
}
@ -124,15 +124,9 @@ object SoundSource {
SoundSource.fromBuffer(SoundBuffers.MinecraftClickRelease, SoundCategory.Interface)
}
lazy val MinecraftExplosion: SoundSource =
SoundSource.fromBuffer(SoundBuffers.MinecraftExplosion, SoundCategory.Environment)
lazy val MachineFloppyInsert: SoundSource =
SoundSource.fromBuffer(SoundBuffers.MachineFloppyInsert, SoundCategory.Environment)
lazy val MachineFloppyEject: SoundSource =
SoundSource.fromBuffer(SoundBuffers.MachineFloppyEject, SoundCategory.Environment)
lazy val SelfDestructingCardCountdownBeep: SoundSource =
SoundSource.fromBuffer(SoundBuffers.SelfDestructingCardCountdownBeep, SoundCategory.Environment)
}

View File

@ -152,7 +152,7 @@ class OpenFMRadio extends Entity with Environment with DeviceInfo with Logging {
}
def isPlaying: Boolean =
playbackSoundSource.isDefined && playbackSoundSource.get.isPlaying || playbackThread.isDefined
playbackSoundSource.isDefined && playbackSoundSource.get.playing || playbackThread.isDefined
@Callback()
def start(context: Context, args: Arguments): Array[AnyRef] =

View File

@ -1,6 +1,6 @@
package ocelot.desktop.node
import ocelot.desktop.audio.SoundSource
import ocelot.desktop.audio.{SoundBuffers, SoundCategory, SoundSource}
import ocelot.desktop.color.Color
import ocelot.desktop.geometry.FloatUtils.ExtendedFloat
import ocelot.desktop.graphics.{Graphics, IconSource}
@ -14,15 +14,23 @@ import totoro.ocelot.brain.event.SelfDestructingCardBoomEvent
trait BoomCardFxHandler extends Node with PositionalSoundSourcesNode with SmokeParticleNode {
private var boomPhase: Float = -1
private lazy val explosionSound = {
SoundSource.fromBuffer(SoundBuffers.MinecraftExplosion, SoundCategory.Environment)
}
private lazy val countdownBeepSound = {
SoundSource.fromBuffer(SoundBuffers.SelfDestructingCardCountdownBeep, SoundCategory.Environment)
}
override def soundSources: Seq[SoundSource] = super.soundSources ++ Seq(
SoundSource.MinecraftExplosion,
SoundSource.SelfDestructingCardCountdownBeep,
explosionSound,
countdownBeepSound,
)
eventHandlers += {
case BrainEvent(_: SelfDestructingCardBoomEvent) =>
OcelotDesktop.updateThreadTasks.add(() => {
SoundSource.MinecraftExplosion.play()
explosionSound.play()
emitSmoke()
destroy()
})
@ -44,7 +52,7 @@ trait BoomCardFxHandler extends Node with PositionalSoundSourcesNode with SmokeP
boomPhase = boomPhase.max(1 - item.card.time.toFloat / item.card.initialTime)
if (item.card.lastBeepTime < 0 || item.card.lastBeepTime - item.card.time >= 20) {
SoundSource.SelfDestructingCardCountdownBeep.play()
countdownBeepSound.play()
item.card.lastBeepTime = item.card.time
flickerPhase = FlickerDuty
}

View File

@ -4,6 +4,12 @@ import ocelot.desktop.audio.SoundSource
import ocelot.desktop.geometry.Vector3D
import ocelot.desktop.{OcelotDesktop, Settings}
/**
* Updates sound sources' position depending on where the camera is.
*
* @note OpenAL only applies positioning to mono sources!
* If your source is stereo, this trait will have no audible effect.
*/
trait PositionalSoundSourcesNode extends Node {
// Every node can have multiple sound sources playing at the same time
def soundSources: Seq[SoundSource] = Seq()

View File

@ -57,9 +57,9 @@ class TapeDriveNode(val tapeDrive: TapeDrive)
val isRewinding =
tapeDrive.state.state == TapeDriveState.State.Rewinding || tapeDrive.state.state == TapeDriveState.State.Forwarding
if (!isRewinding && soundTapeRewind.isPlaying) {
if (!isRewinding && soundTapeRewind.playing) {
soundTapeRewind.stop()
} else if (isRewinding && !soundTapeRewind.isPlaying && !Audio.isDisabled) {
} else if (isRewinding && !soundTapeRewind.playing && !Audio.isDisabled) {
soundTapeRewind.play()
}
}

View File

@ -10,9 +10,9 @@ trait AudibleComputerAware extends ComputerAware {
)
def updateRunningSound(): Unit = {
if (!computer.machine.isRunning && soundComputerRunning.isPlaying) {
if (!computer.machine.isRunning && soundComputerRunning.playing) {
soundComputerRunning.stop()
} else if (computer.machine.isRunning && !soundComputerRunning.isPlaying && !Audio.isDisabled) {
} else if (computer.machine.isRunning && !soundComputerRunning.playing && !Audio.isDisabled) {
soundComputerRunning.play()
}
}