Replace raudio with SDL-Mixer-X for looping support
This commit is contained in:
parent
4f9f62ee8e
commit
01edf59446
8 changed files with 58 additions and 41 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ build*
|
||||||
subprojects/*/
|
subprojects/*/
|
||||||
.cache
|
.cache
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
!subprojects/SDL-Mixer-X/
|
12
.gitmodules
vendored
12
.gitmodules
vendored
|
@ -1,15 +1,9 @@
|
||||||
[submodule "raygui"]
|
|
||||||
path = raygui
|
|
||||||
url = https://github.com/raysan5/raygui.git
|
|
||||||
[submodule "IconFontCppHeaders"]
|
[submodule "IconFontCppHeaders"]
|
||||||
path = IconFontCppHeaders
|
path = IconFontCppHeaders
|
||||||
url = https://github.com/juliettef/IconFontCppHeaders.git
|
url = https://github.com/juliettef/IconFontCppHeaders.git
|
||||||
[submodule "imgui"]
|
[submodule "imgui"]
|
||||||
path = imgui
|
path = imgui
|
||||||
url = https://github.com/ocornut/imgui.git
|
url = https://github.com/ocornut/imgui.git
|
||||||
[submodule "subprojects/raylib"]
|
[submodule "subprojects/SDL-Mixer-X"]
|
||||||
path = subprojects/raylib
|
path = subprojects/SDL-Mixer-X
|
||||||
url = https://github.com/raysan5/raylib.git
|
url = https://github.com/WohlSoft/SDL-Mixer-X.git
|
||||||
[submodule "raudio"]
|
|
||||||
path = raudio
|
|
||||||
url = https://github.com/raysan5/raudio.git
|
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -287,7 +287,7 @@ int main(int, char**)
|
||||||
playback->Seek(0.0);
|
playback->Seek(0.0);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetFontSize() * 22) - (ImGui::GetStyle().FramePadding.x * 10));
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetFontSize() * (22 - 8)) - (ImGui::GetStyle().FramePadding.x * (10 - 2)));
|
||||||
uint8_t components = TimeToComponentCount(playback->GetLength());
|
uint8_t components = TimeToComponentCount(playback->GetLength());
|
||||||
string time_str = TimeToString(position, components);
|
string time_str = TimeToString(position, components);
|
||||||
if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), time_str.c_str(), ImGuiSliderFlags_NoRoundToFormat))
|
if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), time_str.c_str(), ImGuiSliderFlags_NoRoundToFormat))
|
||||||
|
@ -301,13 +301,12 @@ int main(int, char**)
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::SliderFloat("##Volume", &playback->volume, 0.0, 100.0, ICON_FK_VOLUME_UP ": %.0f%%")) {
|
if (ImGui::SliderFloat("##Volume", &playback->volume, 0.0, 100.0, ICON_FK_VOLUME_UP ": %.0f%%")) {
|
||||||
playback->Update();
|
playback->Update();
|
||||||
}
|
}/*
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
|
||||||
if (ImGui::SliderFloat("##Speed", &playback->speed, 0.25, 4.0, "Speed: %.2fx", ImGuiSliderFlags_Logarithmic)) {
|
if (ImGui::SliderFloat("##Speed", &playback->speed, 0.25, 4.0, "Speed: %.2fx", ImGuiSliderFlags_Logarithmic)) {
|
||||||
playback->Update();
|
playback->Update();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
if (prefs_window) {
|
if (prefs_window) {
|
||||||
|
|
15
meson.build
15
meson.build
|
@ -2,18 +2,24 @@ project('neko-player', ['c', 'cpp'],
|
||||||
version : '0.1',
|
version : '0.1',
|
||||||
default_options : ['warning_level=3',
|
default_options : ['warning_level=3',
|
||||||
'cpp_std=c++20'])
|
'cpp_std=c++20'])
|
||||||
|
cmake = import('cmake')
|
||||||
if get_option('debug')
|
if get_option('debug')
|
||||||
add_global_arguments('-DDEBUG', language: 'cpp')
|
add_global_arguments('-DDEBUG', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
raudio_lib = static_library('raudio', 'raudio/src/raudio.c', c_args: ['-DRAUDIO_STANDALONE', '-DSUPPORT_MODULE_RAUDIO', '-DSUPPORT_FILEFORMAT_WAV', '-DSUPPORT_FILEFORMAT_OGG', '-DSUPPORT_FILEFORMAT_MP3', '-DSUPPORT_FILEFORMAT_QOA', '-DSUPPORT_FILEFORMAT_FLAC', '-DSUPPORT_FILEFORMAT_XM', '-DSUPPORT_FILEFORMAT_MOD', '-w'])
|
smx_opts = cmake.subproject_options()
|
||||||
raudio_include = include_directories('raudio/src')
|
smx_opts.add_cmake_defines({'SDL_MIXER_X_STATIC': true, 'SDL_MIXER_X_SHARED': false})
|
||||||
raudio_dep = declare_dependency(include_directories: raudio_include, link_with: raudio_lib)
|
smx_opts.set_override_option('c_std', 'c99')
|
||||||
|
smx_subproj = cmake.subproject('SDL-Mixer-X', options: smx_opts)
|
||||||
|
#raudio_lib = static_library('raudio', 'raudio/src/raudio.c', c_args: ['-DRAUDIO_STANDALONE', '-DSUPPORT_MODULE_RAUDIO', '-DSUPPORT_FILEFORMAT_WAV', '-DSUPPORT_FILEFORMAT_OGG', '-DSUPPORT_FILEFORMAT_MP3', '-DSUPPORT_FILEFORMAT_QOA', '-DSUPPORT_FILEFORMAT_FLAC', '-DSUPPORT_FILEFORMAT_XM', '-DSUPPORT_FILEFORMAT_MOD', '-w'])
|
||||||
|
#raudio_include = include_directories('raudio/src')
|
||||||
|
#raudio_dep = declare_dependency(include_directories: raudio_include, link_with: raudio_lib)
|
||||||
deps = [
|
deps = [
|
||||||
dependency('sdl2'),
|
dependency('sdl2'),
|
||||||
dependency('sdl2_image'),
|
dependency('sdl2_image'),
|
||||||
dependency('gl'),
|
dependency('gl'),
|
||||||
dependency('jsoncpp'),
|
dependency('jsoncpp'),
|
||||||
raudio_dep,
|
#raudio_dep,
|
||||||
|
smx_subproj.dependency('SDL2_mixer_ext_Static'),
|
||||||
]
|
]
|
||||||
|
|
||||||
srcs = [
|
srcs = [
|
||||||
|
@ -35,7 +41,6 @@ include_dirs = [
|
||||||
'imgui-filebrowser',
|
'imgui-filebrowser',
|
||||||
'IconFontCppHeaders',
|
'IconFontCppHeaders',
|
||||||
'assets',
|
'assets',
|
||||||
'raudio/src',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
res = run_command('./assets/update-assets.sh', check: true)
|
res = run_command('./assets/update-assets.sh', check: true)
|
||||||
|
|
55
playback.cpp
55
playback.cpp
|
@ -1,43 +1,56 @@
|
||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
extern "C" {
|
#include "SDL_mixer.h"
|
||||||
#include "raudio.h"
|
#include <SDL_audio.h>
|
||||||
}
|
#include <exception>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
Mix_Music *Playback::Load(const char *file) {
|
||||||
|
Mix_Music *output = Mix_LoadMUS(file);
|
||||||
|
if (!output) {
|
||||||
|
printf("Error loading music '%s': %s\n", file, Mix_GetError());
|
||||||
|
throw std::exception();
|
||||||
|
}
|
||||||
|
Mix_PlayMusicStream(output, -1);
|
||||||
|
length = Mix_MusicDuration(output);
|
||||||
|
update.store(true);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
void Playback::Unload(Mix_Music *music) {
|
||||||
|
Mix_HaltMusicStream(music);
|
||||||
|
Mix_FreeMusic(music);
|
||||||
|
}
|
||||||
void Playback::ThreadFunc() {
|
void Playback::ThreadFunc() {
|
||||||
InitAudioDevice();
|
Mix_Init(MIX_INIT_FLAC|MIX_INIT_MID|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG|MIX_INIT_OPUS|MIX_INIT_WAVPACK);
|
||||||
Music music = LoadMusicStream(filePath.c_str());
|
Mix_OpenAudioDevice(48000, AUDIO_S16SYS, 2, 4096, NULL, 0);
|
||||||
PlayMusicStream(music);
|
Mix_Music *music = Load(filePath.c_str());
|
||||||
length = GetMusicTimeLength(music);
|
|
||||||
while (running) {
|
while (running) {
|
||||||
if (file_changed.exchange(false)) {
|
if (file_changed.exchange(false)) {
|
||||||
StopMusicStream(music);
|
Unload(music);
|
||||||
UnloadMusicStream(music);
|
music = Load(filePath.c_str());
|
||||||
music = LoadMusicStream(filePath.c_str());
|
|
||||||
PlayMusicStream(music);
|
|
||||||
length = GetMusicTimeLength(music);
|
|
||||||
}
|
}
|
||||||
UpdateMusicStream(music);
|
|
||||||
if (flag_mutex.try_lock()) {
|
if (flag_mutex.try_lock()) {
|
||||||
if (seeking.exchange(false)) {
|
if (seeking.exchange(false)) {
|
||||||
SeekMusicStream(music, position);
|
Mix_SetMusicPositionStream(music, position);
|
||||||
}
|
}
|
||||||
if (paused) {
|
if (paused) {
|
||||||
PauseMusicStream(music);
|
Mix_PauseMusicStream(music);
|
||||||
} else {
|
} else {
|
||||||
ResumeMusicStream(music);
|
Mix_ResumeMusicStream(music);
|
||||||
}
|
}
|
||||||
if (update.exchange(false)) {
|
if (update.exchange(false)) {
|
||||||
SetMasterVolume(volume / 100.0);
|
Mix_VolumeMusicStream(music, (volume / 100.0 * MIX_MAX_VOLUME));
|
||||||
SetMusicPitch(music, speed);
|
|
||||||
}
|
}
|
||||||
flag_mutex.unlock();
|
flag_mutex.unlock();
|
||||||
}
|
}
|
||||||
position = GetMusicTimePlayed(music);
|
position = Mix_GetMusicPosition(music);
|
||||||
std::this_thread::sleep_for(20ms);
|
std::this_thread::sleep_for(20ms);
|
||||||
}
|
}
|
||||||
UnloadMusicStream(music);
|
// ====
|
||||||
CloseAudioDevice();
|
Unload(music);
|
||||||
|
Mix_CloseAudio();
|
||||||
|
Mix_Quit();
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Playback::Playback() {
|
Playback::Playback() {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "SDL_mixer.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
@ -15,6 +16,10 @@ private:
|
||||||
double position;
|
double position;
|
||||||
double length;
|
double length;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
Uint8 *buf;
|
||||||
|
size_t bufsize;
|
||||||
|
Mix_Music *Load(const char* file);
|
||||||
|
void Unload(Mix_Music* music);
|
||||||
void ThreadFunc();
|
void ThreadFunc();
|
||||||
public:
|
public:
|
||||||
Playback();
|
Playback();
|
||||||
|
|
1
raudio
1
raudio
|
@ -1 +0,0 @@
|
||||||
Subproject commit 8f0a255549524b5a8ea130371cabfbe77c94c7d5
|
|
1
subprojects/SDL-Mixer-X
Submodule
1
subprojects/SDL-Mixer-X
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 22aed1f6bcfa6912a34d3241edf3bd90498a6bc2
|
Loading…
Reference in a new issue