commit 28/07/2025
This commit is contained in:
@@ -11,6 +11,10 @@ import audio.BassEnc.BASS_ENCODE_PCM
|
|||||||
import codes.Somecodes.Companion.ValidFile
|
import codes.Somecodes.Companion.ValidFile
|
||||||
import codes.Somecodes.Companion.ValidString
|
import codes.Somecodes.Companion.ValidString
|
||||||
import com.sun.jna.Memory
|
import com.sun.jna.Memory
|
||||||
|
import kotlinx.coroutines.CoroutineName
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.tinylog.Logger
|
import org.tinylog.Logger
|
||||||
import java.util.function.BiConsumer
|
import java.util.function.BiConsumer
|
||||||
|
|
||||||
@@ -138,25 +142,26 @@ class AudioPlayer (var samplingrate: Int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val thread = Thread {
|
val job = CoroutineScope(Dispatchers.Default)
|
||||||
|
job.launch(CoroutineName("WavWriter $target")) {
|
||||||
bass.BASS_SetDevice(0) // Set to No Sound device for writing
|
bass.BASS_SetDevice(0) // Set to No Sound device for writing
|
||||||
val streamhandle = bass.BASS_StreamCreate(samplingrate, 1, BASS_STREAM_DECODE, STREAMPROC_PUSH, null)
|
val streamhandle = bass.BASS_StreamCreate(samplingrate, 1, BASS_STREAM_DECODE, STREAMPROC_PUSH, null)
|
||||||
if (streamhandle==0){
|
if (streamhandle==0){
|
||||||
callback.accept(false, "Failed to create stream: ${bass.BASS_ErrorGetCode()}")
|
callback.accept(false, "Failed to create stream: ${bass.BASS_ErrorGetCode()}")
|
||||||
return@Thread
|
return@launch
|
||||||
}
|
}
|
||||||
val encodehandle = bassenc.BASS_Encode_Start(streamhandle, target, BASS_ENCODE_PCM, null, null)
|
val encodehandle = bassenc.BASS_Encode_Start(streamhandle, target, BASS_ENCODE_PCM, null, null)
|
||||||
if (encodehandle==0){
|
if (encodehandle==0){
|
||||||
bass.BASS_StreamFree(streamhandle)
|
bass.BASS_StreamFree(streamhandle)
|
||||||
callback.accept(false, "Failed to start encoding: ${bass.BASS_ErrorGetCode()}")
|
callback.accept(false, "Failed to start encoding: ${bass.BASS_ErrorGetCode()}")
|
||||||
return@Thread
|
return@launch
|
||||||
}
|
}
|
||||||
val playresult = bass.BASS_ChannelPlay(streamhandle,false)
|
val playresult = bass.BASS_ChannelPlay(streamhandle,false)
|
||||||
if (!playresult) {
|
if (!playresult) {
|
||||||
bassenc.BASS_Encode_Stop(encodehandle)
|
bassenc.BASS_Encode_Stop(encodehandle)
|
||||||
bass.BASS_StreamFree(streamhandle)
|
bass.BASS_StreamFree(streamhandle)
|
||||||
callback.accept(false, "BASS_ChannelPlay failed: ${bass.BASS_ErrorGetCode()}")
|
callback.accept(false, "BASS_ChannelPlay failed: ${bass.BASS_ErrorGetCode()}")
|
||||||
return@Thread
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
var allsuccess = true
|
var allsuccess = true
|
||||||
@@ -187,9 +192,9 @@ class AudioPlayer (var samplingrate: Int) {
|
|||||||
callback.accept(false, "Failed to write some data to WAV file: $target")
|
callback.accept(false, "Failed to write some data to WAV file: $target")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread.name = "WavWriter Thread"
|
|
||||||
thread.isDaemon = true
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user