add SDL_mixer

This commit is contained in:
scawful
2023-01-01 17:48:51 -06:00
parent 2d3937e791
commit b0338f588a
7 changed files with 62 additions and 5 deletions

3
.gitmodules vendored
View File

@@ -25,3 +25,6 @@
[submodule "src/lib/snes_spc"]
path = src/lib/snes_spc
url = https://github.com/blarggs-audio-libraries/snes_spc.git
[submodule "src/lib/SDL_mixer"]
path = src/lib/SDL_mixer
url = https://github.com/libsdl-org/SDL_mixer.git

View File

@@ -40,6 +40,18 @@ if (UNIX)
else()
find_package(SDL2)
endif()
set(SDL2MIXER_OPUS OFF)
set(SDL2MIXER_FLAC OFF)
set(SDL2MIXER_MOD OFF)
set(SDL2MIXER_MIDI_FLUIDSYNTH OFF)
find_library(SDL_MIXER_LIBRARY
NAMES SDL_mixer
HINTS
ENV SDLMIXERDIR
ENV SDLDIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
)
add_subdirectory(src/lib/SDL_mixer)
# Asar ------------------------------------------------------------------------
add_subdirectory(src/lib/asar/src)

View File

@@ -66,6 +66,7 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/src/
${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
lib/SDL_mixer/include/
${GLEW_INCLUDE_DIRS}
lib/asar/src/asar/
lib/snes_spc/snes_spc/
@@ -84,6 +85,8 @@ target_link_libraries(
yaze PUBLIC
${ABSL_TARGETS}
${SDL_TARGETS}
${SDLMIXER_LIBRARY}
SDL2_mixer
${PNG_LIBRARIES}
${GLEW_LIBRARIES}
${OPENGL_LIBRARIES}

View File

@@ -1,6 +1,7 @@
#include "controller.h"
#include <SDL.h>
#include <SDL_mixer.h>
#include <imgui/backends/imgui_impl_sdl.h>
#include <imgui/backends/imgui_impl_sdlrenderer.h>
#include <imgui/imgui.h>
@@ -165,6 +166,11 @@ absl::Status Controller::CreateWindow() {
return absl::InternalError(
absl::StrFormat("SDL_CreateWindow: %s\n", SDL_GetError()));
}
// Initialize SDL_mixer
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n",
Mix_GetError());
}
}
return absl::OkStatus();
}

View File

@@ -1,5 +1,6 @@
#include "music_editor.h"
#include <SDL_mixer.h>
#include <imgui/imgui.h>
#include "absl/strings/str_format.h"
@@ -17,6 +18,8 @@ namespace editor {
namespace {
#define BUF_SIZE 2048
void PlaySPC() {
/* Create emulator and filter */
SNES_SPC* snes_spc = spc_new();
@@ -43,9 +46,8 @@ void PlaySPC() {
/* Record 20 seconds to wave file */
wave_open(spc_sample_rate, "out.wav");
wave_enable_stereo();
while (wave_sample_count() < 20 * spc_sample_rate * 2) {
/* Play into buffer */
#define BUF_SIZE 2048
while (wave_sample_count() < 30 * spc_sample_rate * 2) {
/* Play into buffer */
short buf[BUF_SIZE];
error(spc_play(snes_spc, BUF_SIZE, buf));
@@ -216,11 +218,34 @@ void MusicEditor::DrawToolset() {
static bool is_playing = false;
static int selected_option = 0;
static int current_volume = 0;
static bool has_loaded_song = false;
const int MAX_VOLUME = 100;
if (is_playing) {
PlaySPC();
if (!has_loaded_song) {
PlaySPC();
current_song_ = Mix_LoadMUS("out.wav");
Mix_PlayMusic(current_song_, -1);
has_loaded_song = true;
}
// // If there is no music playing
// if (Mix_PlayingMusic() == 0) {
// Mix_PlayMusic(current_song_, -1);
// }
// // If music is being played
// else {
// // If the music is paused
// if (Mix_PausedMusic() == 1) {
// // Resume the music
// Mix_ResumeMusic();
// }
// // If the music is playing
// else {
// // Pause the music
// Mix_PauseMusic();
// }
// }
}
gui::ItemLabel("Select a song to edit: ", gui::ItemLabelFlags::Left);
@@ -236,6 +261,10 @@ void MusicEditor::DrawToolset() {
ImGui::TableNextColumn();
if (ImGui::Button(is_playing ? ICON_MD_STOP : ICON_MD_PLAY_ARROW)) {
if (is_playing) {
Mix_HaltMusic();
has_loaded_song = false;
}
is_playing = !is_playing;
}

View File

@@ -1,6 +1,7 @@
#ifndef YAZE_APP_EDITOR_MUSIC_EDITOR_H
#define YAZE_APP_EDITOR_MUSIC_EDITOR_H
#include <SDL_mixer.h>
#include <imgui/imgui.h>
#include "absl/strings/str_format.h"
@@ -62,6 +63,8 @@ class MusicEditor {
void DrawSongToolset();
void DrawToolset();
Mix_Music* current_song_ = NULL;
AssemblyEditor assembly_editor_;
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit |

1
src/lib/SDL_mixer Submodule

Submodule src/lib/SDL_mixer added at 7f73f724f2