first commit 26/07/2025
This commit is contained in:
@@ -8,10 +8,12 @@ class AudioPlayer {
|
|||||||
var initedDevice : Int = -1
|
var initedDevice : Int = -1
|
||||||
init {
|
init {
|
||||||
Logger.info("Audio version ${Integer.toHexString(bass.BASS_GetVersion())}" as Any)
|
Logger.info("Audio version ${Integer.toHexString(bass.BASS_GetVersion())}" as Any)
|
||||||
|
InitAudio(0) // Audio 0 is No Sound, use for reading and writing wav silently
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the audio system with the specified device ID.
|
* Initializes the audio system with the specified device ID.
|
||||||
|
* Call it before using any audio functions.
|
||||||
* @param id The device ID to initialize.
|
* @param id The device ID to initialize.
|
||||||
* @return True if initialization was successful, false otherwise.
|
* @return True if initialization was successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -19,17 +21,23 @@ class AudioPlayer {
|
|||||||
|
|
||||||
|
|
||||||
if (bass.BASS_Init(id, 48000, 0)){
|
if (bass.BASS_Init(id, 48000, 0)){
|
||||||
Logger.info("Audio initialized successfully" as Any)
|
Logger.info { "Audio ID=$id inited succesfully" }
|
||||||
initedDevice = id
|
if (id > 0) {
|
||||||
|
initedDevice = id
|
||||||
|
Logger.info { "Real Audio Device used ID=$initedDevice" }
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
val err = bass.BASS_ErrorGetCode()
|
val err = bass.BASS_ErrorGetCode()
|
||||||
if (err == BASS_ERROR_ALREADY) {
|
if (err == BASS_ERROR_ALREADY) {
|
||||||
Logger.info("Audio already initialized, reusing existing instance" as Any)
|
Logger.info {"Audio ID=$id already initialized, reusing existing instance"}
|
||||||
initedDevice = id
|
if (id > 0) {
|
||||||
|
initedDevice = id
|
||||||
|
Logger.info { "Real Audio Device reused ID=$initedDevice" }
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
Logger.error("Audio initialization failed: ${bass.BASS_ErrorGetCode()}" as Any)
|
Logger.error { "Audio ID=$id initialization failed: ${bass.BASS_ErrorGetCode()}" }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +51,9 @@ class AudioPlayer {
|
|||||||
if (initedDevice != -1) {
|
if (initedDevice != -1) {
|
||||||
bass.BASS_SetDevice(initedDevice)
|
bass.BASS_SetDevice(initedDevice)
|
||||||
if (bass.BASS_Free()) {
|
if (bass.BASS_Free()) {
|
||||||
Logger.info("Audio uninitialized successfully" as Any)
|
Logger.info {"Audio ID=$initedDevice uninitialized successfully"}
|
||||||
} else {
|
} else {
|
||||||
Logger.error("Audio uninitialization failed: ${bass.BASS_ErrorGetCode()}" as Any)
|
Logger.error { "Audio ID=$initedDevice uninitialization failed: ${bass.BASS_ErrorGetCode()}" }
|
||||||
}
|
}
|
||||||
initedDevice = -1
|
initedDevice = -1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user