Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Feb 17, 2021
1 parent 8d0e558 commit 270ee73
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 466 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ easyPluginVersion=0.13.0
group=com.soywiz.korlibs.korau
version=2.0.0-SNAPSHOT

korioVersion=2.0.7
korioVersion=2.0.8

# bintray location
project.bintray.org=korlibs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.soywiz.korau.internal

internal fun Float.coerceToShort(): Short = this.toInt().coerceToShort()

internal fun Int.coerceToShort(): Short = this.coerceIn(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt()).toShort()
internal fun Int.coerceToByte(): Byte = this.coerceIn(Byte.MIN_VALUE.toInt(), Byte.MAX_VALUE.toInt()).toByte()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.soywiz.korau.sound

import com.soywiz.kds.iterators.*
import com.soywiz.kmem.*
import com.soywiz.korau.internal.*
import kotlin.math.*
Expand Down Expand Up @@ -78,8 +79,20 @@ class AudioSamples(override val channels: Int, override val totalSamples: Int, v
override operator fun get(channel: Int, sample: Int): Short = data[channel][sample]
override operator fun set(channel: Int, sample: Int, value: Short) = run { data[channel][sample] = value }

fun setTo(that: AudioSamples) {
fun scaleVolume(scale: Double): AudioSamples = scaleVolume(scale.toFloat())

fun scaleVolume(scale: Float): AudioSamples {
data.fastForEach { channel ->
for (n in channel.indices) {
channel[n] = (channel[n] * scale).toInt().coerceToShort()
}
}
return this
}

fun setTo(that: AudioSamples): AudioSamples {
that.copyTo(this)
return this
}

fun copyTo(that: AudioSamples) {
Expand Down
4 changes: 3 additions & 1 deletion korau/src/commonMain/kotlin/com/soywiz/korau/sound/Sound.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ open class NativeSoundProvider {
suspend fun playAndWait(stream: AudioStream, params: PlaybackParameters = PlaybackParameters.DEFAULT) = createStreamingSound(stream).playAndWait(params)
}

class DummyNativeSoundProvider : NativeSoundProvider()
open class DummyNativeSoundProvider : NativeSoundProvider() {
companion object : DummyNativeSoundProvider()
}

class DummySoundChannel(sound: Sound, val data: AudioData? = null) : SoundChannel(sound) {
private var timeStart = DateTime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.soywiz.korau.sound
import com.soywiz.korau.format.*
import com.soywiz.korau.format.mp3.*
import com.soywiz.korau.sound.impl.jna.*
import com.soywiz.korio.time.*
import java.util.*

internal val nativeAudioFormats = AudioFormats(WAV, MP3Decoder, OGG) + AudioFormats(try {
Expand All @@ -12,6 +13,17 @@ internal val nativeAudioFormats = AudioFormats(WAV, MP3Decoder, OGG) + AudioForm
listOf<AudioFormat>()
})

actual val nativeSoundProvider: NativeSoundProvider by lazy { JnaOpenALNativeSoundProvider() }
actual val nativeSoundProvider: NativeSoundProvider by lazy {
try {
traceTime("OpenAL") {
JnaOpenALNativeSoundProvider()
}
} catch (e: UnsatisfiedLinkError) {
DummyNativeSoundProvider
} catch (e: Throwable) {
e.printStackTrace()
DummyNativeSoundProvider
}
}
//actual val nativeSoundProvider: NativeSoundProvider by lazy { JogampNativeSoundProvider() }
//actual val nativeSoundProvider: NativeSoundProvider by lazy { AwtNativeSoundProvider() }
541 changes: 263 additions & 278 deletions korau/src/jvmMain/kotlin/com/soywiz/korau/sound/impl/jna/AL.kt

Large diffs are not rendered by default.

68 changes: 0 additions & 68 deletions korau/src/jvmMain/kotlin/com/soywiz/korau/sound/impl/jna/AL2.kt

This file was deleted.

Loading

0 comments on commit 270ee73

Please sign in to comment.