first commit 26/07/2025

This commit is contained in:
2025-07-26 07:27:26 +07:00
parent b5325ad31c
commit df62bd1cd2
12 changed files with 852 additions and 12 deletions

53
src/audio/AudioPlayer.kt Normal file
View File

@@ -0,0 +1,53 @@
package audio
import audio.Bass.BASS_ERROR_ALREADY
import org.tinylog.Logger
class AudioPlayer {
var bass : Bass = Bass.Instance
var initedDevice : Int = -1
init {
Logger.info("Audio version ${Integer.toHexString(bass.BASS_GetVersion())}" as Any)
}
/**
* Initializes the audio system with the specified device ID.
* @param id The device ID to initialize.
* @return True if initialization was successful, false otherwise.
*/
fun InitAudio(id : Int) : Boolean {
if (bass.BASS_Init(id, 48000, 0)){
Logger.info("Audio initialized successfully" as Any)
initedDevice = id
return true
} else {
val err = bass.BASS_ErrorGetCode()
if (err == BASS_ERROR_ALREADY) {
Logger.info("Audio already initialized, reusing existing instance" as Any)
initedDevice = id
return true
} else {
Logger.error("Audio initialization failed: ${bass.BASS_ErrorGetCode()}" as Any)
return false
}
}
}
/**
* Uninitializes the audio system if it was previously initialized.
*/
fun UnInitAudio(){
if (initedDevice != -1) {
bass.BASS_SetDevice(initedDevice)
if (bass.BASS_Free()) {
Logger.info("Audio uninitialized successfully" as Any)
} else {
Logger.error("Audio uninitialization failed: ${bass.BASS_ErrorGetCode()}" as Any)
}
initedDevice = -1
}
}
}