mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
speed of sound moved to the mixer
This commit is contained in:
@@ -20,6 +20,11 @@ import kotlin.math.*
|
|||||||
* Created by minjaesong on 2023-11-07.
|
* Created by minjaesong on 2023-11-07.
|
||||||
*/
|
*/
|
||||||
object AudioMixer: Disposable {
|
object AudioMixer: Disposable {
|
||||||
|
var SPEED_OF_SOUND = 340f
|
||||||
|
|
||||||
|
const val SPEED_OF_SOUND_AIR = 340f
|
||||||
|
const val SPEED_OF_SOUND_WATER = 1480f
|
||||||
|
|
||||||
const val DEFAULT_FADEOUT_LEN = 1.8
|
const val DEFAULT_FADEOUT_LEN = 1.8
|
||||||
|
|
||||||
val masterVolume: Double
|
val masterVolume: Double
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.audio
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import com.jme3.math.FastMath.sin
|
import com.jme3.math.FastMath.sin
|
||||||
|
import net.torvald.terrarum.audio.AudioMixer.SPEED_OF_SOUND
|
||||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.BUFFER_SIZE
|
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.BUFFER_SIZE
|
||||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATEF
|
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATEF
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
@@ -187,7 +188,7 @@ object Buffer : TerrarumAudioFilter() {
|
|||||||
* @param soundSpeed speed of the sound in meters per seconds
|
* @param soundSpeed speed of the sound in meters per seconds
|
||||||
* @param earDist distance between ears in meters
|
* @param earDist distance between ears in meters
|
||||||
*/
|
*/
|
||||||
class BinoPan(var pan: Float, var soundSpeed: Float = 340f, var earDist: Float = 0.18f): TerrarumAudioFilter() {
|
class BinoPan(var pan: Float, var earDist: Float = 0.18f): TerrarumAudioFilter() {
|
||||||
|
|
||||||
private val PANNING_CONST = 3.0 // 3dB panning rule
|
private val PANNING_CONST = 3.0 // 3dB panning rule
|
||||||
|
|
||||||
@@ -203,7 +204,7 @@ class BinoPan(var pan: Float, var soundSpeed: Float = 340f, var earDist: Float =
|
|||||||
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>
|
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>
|
||||||
) {
|
) {
|
||||||
val angle = pan * 1.5707963f
|
val angle = pan * 1.5707963f
|
||||||
val timeDiffMax = earDist / soundSpeed * SAMPLING_RATEF
|
val timeDiffMax = earDist / SPEED_OF_SOUND * SAMPLING_RATEF
|
||||||
val delayInSamples = (timeDiffMax * sin(angle)).absoluteValue
|
val delayInSamples = (timeDiffMax * sin(angle)).absoluteValue
|
||||||
val volMultDbThis = PANNING_CONST * pan.absoluteValue
|
val volMultDbThis = PANNING_CONST * pan.absoluteValue
|
||||||
val volMultFsThis = decibelsToFullscale(volMultDbThis).toFloat()
|
val volMultFsThis = decibelsToFullscale(volMultDbThis).toFloat()
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
else "R${filter.pan.absoluteValue.times(100).toIntAndFrac(3,1)}"
|
else "R${filter.pan.absoluteValue.times(100).toIntAndFrac(3,1)}"
|
||||||
App.fontSmallNumbers.draw(batch, panLabel, x+3f, y+1f)
|
App.fontSmallNumbers.draw(batch, panLabel, x+3f, y+1f)
|
||||||
|
|
||||||
App.fontSmallNumbers.draw(batch, "AS:${filter.soundSpeed.roundToInt()}", x+3f, y+17f)
|
App.fontSmallNumbers.draw(batch, "AS:${AudioMixer.SPEED_OF_SOUND.roundToInt()}", x+3f, y+17f)
|
||||||
}
|
}
|
||||||
is Buffer -> {
|
is Buffer -> {
|
||||||
batch.color = FILTER_NAME_ACTIVE
|
batch.color = FILTER_NAME_ACTIVE
|
||||||
|
|||||||
Reference in New Issue
Block a user