update SDL_mixer to SDL3_mixer 3.2.0
This commit is contained in:
+29
-23
@@ -67,8 +67,10 @@ static WGPUSurfaceConfiguration surface_configuration;
|
||||
static Sint32 window_width = 1280;
|
||||
static Sint32 window_height = 720;
|
||||
|
||||
|
||||
static Mix_Music *music_setting_off_piano;
|
||||
static MIX_Mixer *mixer;
|
||||
static MIX_Track *music_track;
|
||||
static MIX_Track *sfx_track;
|
||||
static MIX_Audio *music_setting_off_piano;
|
||||
|
||||
static float volume_master = 50.0f;
|
||||
static float volume_music = 50.0f;
|
||||
@@ -1578,7 +1580,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Mix_Init(MIX_INIT_OPUS)) {
|
||||
if (!MIX_Init()) {
|
||||
log_error("Failed to init SDL_mixer. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
@@ -1599,17 +1601,22 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_AudioSpec audio_spec = {
|
||||
.format = SDL_AUDIO_F32,
|
||||
.channels = 2,
|
||||
.freq = 48000,
|
||||
};
|
||||
|
||||
if (!Mix_OpenAudio(0, &audio_spec)) {
|
||||
mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);
|
||||
if (!mixer) {
|
||||
log_error("Failed to open default audio device. Ignoring.");
|
||||
}
|
||||
|
||||
music_setting_off_piano = Mix_LoadMUS(ASSETS_PATH "music/setting_off_piano.opus");
|
||||
music_track = MIX_CreateTrack(mixer);
|
||||
if (!music_track) {
|
||||
log_error("Failed to create music track. Ignoring.");
|
||||
}
|
||||
|
||||
sfx_track = MIX_CreateTrack(mixer);
|
||||
if (!sfx_track) {
|
||||
log_error("Failed to create sfx track. Ignoring.");
|
||||
}
|
||||
|
||||
music_setting_off_piano = MIX_LoadAudio(mixer, ASSETS_PATH "music/setting_off_piano.opus", false);
|
||||
if (!music_setting_off_piano) {
|
||||
log_error("Failed to load music setting_off_piano.opus. Ignoring.");
|
||||
}
|
||||
@@ -1688,13 +1695,12 @@ int main(int argc, char **argv) {
|
||||
settings_handler.ReadLineFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, void *entry, const char *line) {
|
||||
if (entry == (void *)SETTINGS_AUDIO) {
|
||||
if (SDL_sscanf(line, "Master=%f", &volume_master) == 1) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
Mix_VolumeMusic (MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
MIX_SetMixerGain(mixer, volume_master / 100.0f);
|
||||
}
|
||||
if (SDL_sscanf(line, "Music=%f", &volume_music) == 1)
|
||||
Mix_VolumeMusic(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
MIX_SetTrackGain(music_track, volume_music / 100.0f);
|
||||
if (SDL_sscanf(line, "SFX=%f", &volume_sfx) == 1)
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
MIX_SetTrackGain(sfx_track, volume_sfx / 100.0f);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -1772,14 +1778,13 @@ int main(int argc, char **argv) {
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 0), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("Settings", &show_settings)) {
|
||||
if (ImGui::DragFloat("Master", &volume_master, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
Mix_VolumeMusic (MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
MIX_SetMixerGain(mixer, volume_master / 100.0f);
|
||||
};
|
||||
if (ImGui::DragFloat("Music", &volume_music, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_VolumeMusic(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
if (ImGui::DragFloat("Music", &volume_music, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
MIX_SetTrackGain(music_track, volume_music / 100.0f);
|
||||
}
|
||||
if (ImGui::DragFloat("SFX", &volume_sfx, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
if (ImGui::DragFloat("SFX", &volume_sfx, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
MIX_SetTrackGain(sfx_track, volume_sfx / 100.0f);
|
||||
}
|
||||
ImGui::NewLine();
|
||||
|
||||
@@ -2132,8 +2137,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Mix_PlayingMusic()) {
|
||||
Mix_PlayMusic(music_setting_off_piano, -1);
|
||||
if (!MIX_TrackPlaying(music_track)) {
|
||||
MIX_SetTrackAudio(music_track, music_setting_off_piano);
|
||||
MIX_PlayTrack(music_track, 0);
|
||||
}
|
||||
|
||||
Uint32 surface_width = wgpuTextureGetWidth (surface_texture.texture);
|
||||
|
||||
Reference in New Issue
Block a user