Fixes crash when not calling ma_audio_unint correctly (#397)
* fixes crash when not calling ma_audio_unint correctly * adds check that we are not still playing the previous track
This commit is contained in:
parent
e757db4227
commit
ec04a9c111
|
@ -9,7 +9,6 @@ void S3DisableMIDI(void) {
|
|||
}
|
||||
|
||||
void S3StopMIDIOutlets(void) {
|
||||
STUB();
|
||||
}
|
||||
|
||||
void S3ReleaseMIDI(tS3_sound_tag tag) {
|
||||
|
|
|
@ -42,6 +42,7 @@ typedef struct tMiniaudio_stream {
|
|||
|
||||
ma_engine engine;
|
||||
ma_sound cda_sound;
|
||||
int cda_sound_initialized;
|
||||
|
||||
tAudioBackend_error_code AudioBackend_Init(void) {
|
||||
ma_result result;
|
||||
|
@ -75,10 +76,14 @@ void AudioBackend_UnInitCDA(void) {
|
|||
}
|
||||
|
||||
tAudioBackend_error_code AudioBackend_StopCDA(void) {
|
||||
if (!cda_sound_initialized) {
|
||||
return eAB_success;
|
||||
}
|
||||
if (ma_sound_is_playing(&cda_sound)) {
|
||||
ma_sound_stop(&cda_sound);
|
||||
ma_sound_uninit(&cda_sound);
|
||||
}
|
||||
ma_sound_uninit(&cda_sound);
|
||||
cda_sound_initialized = 0;
|
||||
return eAB_success;
|
||||
}
|
||||
|
||||
|
@ -91,10 +96,15 @@ tAudioBackend_error_code AudioBackend_PlayCDA(int track) {
|
|||
if (access(path, F_OK) == -1) {
|
||||
return eAB_error;
|
||||
}
|
||||
|
||||
// ensure we are not still playing a track
|
||||
AudioBackend_StopCDA();
|
||||
|
||||
result = ma_sound_init_from_file(&engine, path, 0, NULL, NULL, &cda_sound);
|
||||
if (result != MA_SUCCESS) {
|
||||
return eAB_error;
|
||||
}
|
||||
cda_sound_initialized = 1;
|
||||
result = ma_sound_start(&cda_sound);
|
||||
if (result != MA_SUCCESS) {
|
||||
return eAB_error;
|
||||
|
@ -103,10 +113,16 @@ tAudioBackend_error_code AudioBackend_PlayCDA(int track) {
|
|||
}
|
||||
|
||||
int AudioBackend_CDAIsPlaying(void) {
|
||||
if (!cda_sound_initialized) {
|
||||
return 0;
|
||||
}
|
||||
return ma_sound_is_playing(&cda_sound);
|
||||
}
|
||||
|
||||
tAudioBackend_error_code AudioBackend_SetCDAVolume(int volume) {
|
||||
if (!cda_sound_initialized) {
|
||||
return eAB_error;
|
||||
}
|
||||
ma_sound_set_volume(&cda_sound, volume / 255.0f);
|
||||
return eAB_success;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue