add SDL_mixer
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -25,3 +25,6 @@
|
|||||||
[submodule "src/lib/snes_spc"]
|
[submodule "src/lib/snes_spc"]
|
||||||
path = src/lib/snes_spc
|
path = src/lib/snes_spc
|
||||||
url = https://github.com/blarggs-audio-libraries/snes_spc.git
|
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
|
||||||
|
|||||||
@@ -40,6 +40,18 @@ if (UNIX)
|
|||||||
else()
|
else()
|
||||||
find_package(SDL2)
|
find_package(SDL2)
|
||||||
endif()
|
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 ------------------------------------------------------------------------
|
# Asar ------------------------------------------------------------------------
|
||||||
add_subdirectory(src/lib/asar/src)
|
add_subdirectory(src/lib/asar/src)
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ target_include_directories(
|
|||||||
${CMAKE_SOURCE_DIR}/src/
|
${CMAKE_SOURCE_DIR}/src/
|
||||||
${PNG_INCLUDE_DIRS}
|
${PNG_INCLUDE_DIRS}
|
||||||
${SDL2_INCLUDE_DIR}
|
${SDL2_INCLUDE_DIR}
|
||||||
|
lib/SDL_mixer/include/
|
||||||
${GLEW_INCLUDE_DIRS}
|
${GLEW_INCLUDE_DIRS}
|
||||||
lib/asar/src/asar/
|
lib/asar/src/asar/
|
||||||
lib/snes_spc/snes_spc/
|
lib/snes_spc/snes_spc/
|
||||||
@@ -84,6 +85,8 @@ target_link_libraries(
|
|||||||
yaze PUBLIC
|
yaze PUBLIC
|
||||||
${ABSL_TARGETS}
|
${ABSL_TARGETS}
|
||||||
${SDL_TARGETS}
|
${SDL_TARGETS}
|
||||||
|
${SDLMIXER_LIBRARY}
|
||||||
|
SDL2_mixer
|
||||||
${PNG_LIBRARIES}
|
${PNG_LIBRARIES}
|
||||||
${GLEW_LIBRARIES}
|
${GLEW_LIBRARIES}
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <SDL_mixer.h>
|
||||||
#include <imgui/backends/imgui_impl_sdl.h>
|
#include <imgui/backends/imgui_impl_sdl.h>
|
||||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
@@ -165,6 +166,11 @@ absl::Status Controller::CreateWindow() {
|
|||||||
return absl::InternalError(
|
return absl::InternalError(
|
||||||
absl::StrFormat("SDL_CreateWindow: %s\n", SDL_GetError()));
|
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();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "music_editor.h"
|
#include "music_editor.h"
|
||||||
|
|
||||||
|
#include <SDL_mixer.h>
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
@@ -17,6 +18,8 @@ namespace editor {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#define BUF_SIZE 2048
|
||||||
|
|
||||||
void PlaySPC() {
|
void PlaySPC() {
|
||||||
/* Create emulator and filter */
|
/* Create emulator and filter */
|
||||||
SNES_SPC* snes_spc = spc_new();
|
SNES_SPC* snes_spc = spc_new();
|
||||||
@@ -43,9 +46,8 @@ void PlaySPC() {
|
|||||||
/* Record 20 seconds to wave file */
|
/* Record 20 seconds to wave file */
|
||||||
wave_open(spc_sample_rate, "out.wav");
|
wave_open(spc_sample_rate, "out.wav");
|
||||||
wave_enable_stereo();
|
wave_enable_stereo();
|
||||||
while (wave_sample_count() < 20 * spc_sample_rate * 2) {
|
while (wave_sample_count() < 30 * spc_sample_rate * 2) {
|
||||||
/* Play into buffer */
|
/* Play into buffer */
|
||||||
#define BUF_SIZE 2048
|
|
||||||
short buf[BUF_SIZE];
|
short buf[BUF_SIZE];
|
||||||
error(spc_play(snes_spc, BUF_SIZE, buf));
|
error(spc_play(snes_spc, BUF_SIZE, buf));
|
||||||
|
|
||||||
@@ -216,11 +218,34 @@ void MusicEditor::DrawToolset() {
|
|||||||
static bool is_playing = false;
|
static bool is_playing = false;
|
||||||
static int selected_option = 0;
|
static int selected_option = 0;
|
||||||
static int current_volume = 0;
|
static int current_volume = 0;
|
||||||
|
static bool has_loaded_song = false;
|
||||||
const int MAX_VOLUME = 100;
|
const int MAX_VOLUME = 100;
|
||||||
|
|
||||||
|
|
||||||
if (is_playing) {
|
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);
|
gui::ItemLabel("Select a song to edit: ", gui::ItemLabelFlags::Left);
|
||||||
@@ -236,6 +261,10 @@ void MusicEditor::DrawToolset() {
|
|||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
if (ImGui::Button(is_playing ? ICON_MD_STOP : ICON_MD_PLAY_ARROW)) {
|
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;
|
is_playing = !is_playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef YAZE_APP_EDITOR_MUSIC_EDITOR_H
|
#ifndef YAZE_APP_EDITOR_MUSIC_EDITOR_H
|
||||||
#define YAZE_APP_EDITOR_MUSIC_EDITOR_H
|
#define YAZE_APP_EDITOR_MUSIC_EDITOR_H
|
||||||
|
|
||||||
|
#include <SDL_mixer.h>
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
@@ -62,6 +63,8 @@ class MusicEditor {
|
|||||||
void DrawSongToolset();
|
void DrawSongToolset();
|
||||||
void DrawToolset();
|
void DrawToolset();
|
||||||
|
|
||||||
|
Mix_Music* current_song_ = NULL;
|
||||||
|
|
||||||
AssemblyEditor assembly_editor_;
|
AssemblyEditor assembly_editor_;
|
||||||
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
|
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
|
||||||
ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit |
|
ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit |
|
||||||
|
|||||||
1
src/lib/SDL_mixer
Submodule
1
src/lib/SDL_mixer
Submodule
Submodule src/lib/SDL_mixer added at 7f73f724f2
Reference in New Issue
Block a user