commit 26/07/2025
This commit is contained in:
BIN
libs/linux-aarch64/libbassenc.so
Normal file
BIN
libs/linux-aarch64/libbassenc.so
Normal file
Binary file not shown.
BIN
libs/linux-armhf/libbassenc.so
Normal file
BIN
libs/linux-armhf/libbassenc.so
Normal file
Binary file not shown.
BIN
libs/linux-x86-64/libbassenc.so
Normal file
BIN
libs/linux-x86-64/libbassenc.so
Normal file
Binary file not shown.
BIN
libs/linux-x86/libbassenc.so
Normal file
BIN
libs/linux-x86/libbassenc.so
Normal file
Binary file not shown.
BIN
libs/win32-arm64/bassenc.dll
Normal file
BIN
libs/win32-arm64/bassenc.dll
Normal file
Binary file not shown.
BIN
libs/win32-x86-64/bassenc.dll
Normal file
BIN
libs/win32-x86-64/bassenc.dll
Normal file
Binary file not shown.
BIN
libs/win32-x86/bassenc.dll
Normal file
BIN
libs/win32-x86/bassenc.dll
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
|||||||
package audio
|
package audio
|
||||||
|
|
||||||
|
import audio.Bass.BASS_ACTIVE_PLAYING
|
||||||
import audio.Bass.BASS_DEVICE_ENABLED
|
import audio.Bass.BASS_DEVICE_ENABLED
|
||||||
import audio.Bass.BASS_DEVICE_INIT
|
import audio.Bass.BASS_DEVICE_INIT
|
||||||
import audio.Bass.BASS_POS_BYTE
|
import audio.Bass.BASS_POS_BYTE
|
||||||
@@ -137,32 +138,60 @@ class AudioPlayer (var samplingrate: Int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val thread = Thread {
|
||||||
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
|
return@Thread
|
||||||
}
|
}
|
||||||
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
|
return@Thread
|
||||||
}
|
}
|
||||||
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
|
return@Thread
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO write each source to the stream
|
var allsuccess = true
|
||||||
|
sources.forEach { source ->
|
||||||
|
if (source.isValid()) {
|
||||||
|
// write the bytes to the stream
|
||||||
|
val mem = Memory(source.bytes.size.toLong())
|
||||||
|
mem.write(0, source.bytes, 0, source.bytes.size)
|
||||||
|
val pushresult = bass.BASS_StreamPutData(streamhandle, mem, source.bytes.size)
|
||||||
|
if (pushresult == -1) {
|
||||||
|
Logger.error { "Failed to write data from ${source.fileName} to stream: ${bass.BASS_ErrorGetCode()}" }
|
||||||
|
allsuccess = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we wait until the stream is finished
|
||||||
|
while(bassenc.BASS_Encode_IsActive(encodehandle) == BASS_ACTIVE_PLAYING) {
|
||||||
|
Thread.sleep(100) // Sleep for a short time to avoid busy waiting
|
||||||
|
}
|
||||||
|
|
||||||
// close the encoding handle
|
// close the encoding handle
|
||||||
bassenc.BASS_Encode_Stop(encodehandle)
|
bassenc.BASS_Encode_Stop(encodehandle)
|
||||||
bass.BASS_ChannelFree(streamhandle)
|
bass.BASS_ChannelFree(streamhandle)
|
||||||
|
if (allsuccess){
|
||||||
callback.accept(true, "WAV file written successfully: $target")
|
callback.accept(true, "WAV file written successfully: $target")
|
||||||
|
} else {
|
||||||
|
callback.accept(false, "Failed to write some data to WAV file: $target")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thread.name = "WavWriter Thread"
|
||||||
|
thread.isDaemon = true
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -126,4 +126,5 @@ public interface BassEnc extends Library {
|
|||||||
int BASS_Encode_IsActive(int handle);
|
int BASS_Encode_IsActive(int handle);
|
||||||
boolean BASS_Encode_SetPaused(int handle, boolean paused);
|
boolean BASS_Encode_SetPaused(int handle, boolean paused);
|
||||||
int BASS_Encode_GetChannel(int handle);
|
int BASS_Encode_GetChannel(int handle);
|
||||||
|
boolean BASS_Encode_StopEx(int handle, boolean queue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user