This commit is contained in:
Nishi 2025-11-24 19:49:20 +09:00
commit 8aca3fb166
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 24 additions and 28 deletions

View file

@ -3,11 +3,10 @@ include(MDEPkgConfig)
setup_project(mauplay ${CMAKE_INSTALL_BINDIR})
pkg_config_add(mauplay sqlite3)
pkg_config_add(mauplay sndfile)
pkg_config_add(mauplay samplerate)
target_link_libraries(
mauplay
PRIVATE
MDEAudio
MDEAudio MDESound
)

View file

@ -3,18 +3,18 @@
#include <samplerate.h>
#include <stb_ds.h>
static void* audio;
static MDEAudio audio;
pthread_mutex_t audio_mutex;
queue_t* queue = NULL;
int queue_seek = -1;
int paused = 0;
static void handler(void* handle, void* user, void* data, int frames) {
static void handler(MDEAudio handle, void* user, void* data, int frames) {
memset(data, 0, frames * 2 * 2);
pthread_mutex_lock(&audio_mutex);
if(queue_seek != -1 && !paused) {
int from_frames = frames * queue[queue_seek].sfi.samplerate / MDEAudioRate;
int from_frames = frames * queue[queue_seek].sound->context->sample_rate / MDEAudioRate;
float* from = malloc(from_frames * sizeof(*from) * 2);
float* to = malloc(frames * sizeof(*to) * 2);
SRC_DATA d;
@ -24,9 +24,9 @@ static void handler(void* handle, void* user, void* data, int frames) {
d.data_out = to;
d.input_frames = from_frames;
d.output_frames = frames;
d.src_ratio = (double)MDEAudioRate / queue[queue_seek].sfi.samplerate;
d.src_ratio = (double)MDEAudioRate / queue[queue_seek].sound->context->sample_rate;
f = sf_readf_float(queue[queue_seek].sf, from, from_frames);
f = MDESoundReadFloat(queue[queue_seek].sound, from, from_frames);
src_simple(&d, SRC_SINC_BEST_QUALITY, 2);
src_float_to_short_array(to, data, frames * 2);
queue[queue_seek].frames += f;
@ -55,7 +55,7 @@ void audio_init(void) {
void audio_queue(const char* path) {
queue_t q;
q.path = MDEFileAbsolutePath(path);
q.sf = sf_open(q.path, SFM_READ, &q.sfi);
q.sound = MDESoundOpen(q.path);
q.frames = 0;
pthread_mutex_lock(&audio_mutex);

View file

@ -61,8 +61,7 @@ int db_init(void) {
}
static int db_bind(sqlite3_stmt* stmt, const char* path) {
SF_INFO sfi;
SNDFILE* sf = sf_open(path, SFM_READ, &sfi);
MDESound sound = MDESoundOpen(path);
char* p;
const char* s_title;
const char* s_artist;
@ -70,13 +69,13 @@ static int db_bind(sqlite3_stmt* stmt, const char* path) {
const char* s_genre;
int s_length;
struct stat s;
if(sf == NULL) return 1;
if(sound == NULL) return 1;
s_title = sf_get_string(sf, SF_STR_TITLE);
s_artist = sf_get_string(sf, SF_STR_ARTIST);
s_album = sf_get_string(sf, SF_STR_ALBUM);
s_genre = sf_get_string(sf, SF_STR_GENRE);
s_length = sfi.frames / sfi.samplerate;
s_title = sound->context->title;
s_artist = sound->context->artist;
s_album = sound->context->album;
s_genre = sound->context->genre;
s_length = sound->context->frames / sound->context->sample_rate;
if(s_title == NULL) s_title = path;
if(s_artist == NULL) s_artist = "<unknown>";
@ -95,7 +94,7 @@ static int db_bind(sqlite3_stmt* stmt, const char* path) {
sqlite3_bind_int(stmt, 6, s_length);
sqlite3_bind_int64(stmt, 7, s.st_mtime);
sf_close(sf);
MDESoundClose(sound);
free(p);

View file

@ -8,7 +8,6 @@
#include <Mw/Milsko.h>
/* External */
#include <sndfile.h>
/* Standard */
#include <sys/stat.h>
@ -31,8 +30,7 @@ typedef struct numkv {
typedef struct queue {
char* path;
SNDFILE* sf;
SF_INFO sfi;
MDESound sound;
int frames;
} queue_t;

View file

@ -190,7 +190,7 @@ static void list_activate(MwWidget handle, void* user, void* client) {
pthread_mutex_lock(&audio_mutex);
queue_seek = (*(int*)client) - 1;
queue[queue_seek].frames = 0;
sf_seek(queue[queue_seek].sf, 0, SEEK_SET);
MDESoundSeek(queue[queue_seek].sound, 0);
pthread_mutex_unlock(&audio_mutex);
} else if(ui_last == all_music) {
audio_queue(db_musics[(*(int*)client) - 1].key);
@ -223,7 +223,7 @@ static void window_tick(MwWidget handle, void* user, void* client) {
MwNtext, buf,
NULL);
MwVaApply(seekbar,
MwNmaxValue, queue[queue_seek].sfi.frames / queue[queue_seek].sfi.samplerate,
MwNmaxValue, queue[queue_seek].sound->context->frames / queue[queue_seek].sound->context->sample_rate,
NULL);
free(buf);
@ -233,8 +233,8 @@ static void window_tick(MwWidget handle, void* user, void* client) {
NULL);
}
if(arrlen(queue) > 0 && queue_seek != -1) {
int elsec = queue[queue_seek].frames / queue[queue_seek].sfi.samplerate;
int rmsec = (queue[queue_seek].sfi.frames / queue[queue_seek].sfi.samplerate) - elsec;
int elsec = queue[queue_seek].frames / queue[queue_seek].sound->context->sample_rate;
int rmsec = (queue[queue_seek].sound->context->frames / queue[queue_seek].sound->context->sample_rate) - elsec;
char buf[64];
sprintf(buf, "%d:%02d", elsec / 60, elsec % 60);
@ -248,7 +248,7 @@ static void window_tick(MwWidget handle, void* user, void* client) {
NULL);
if(changed) {
sf_seek(queue[queue_seek].sf, (queue[queue_seek].frames = MwGetInteger(seekbar, MwNvalue) * queue[queue_seek].sfi.samplerate), SEEK_SET);
MDESoundSeek(queue[queue_seek].sound, (queue[queue_seek].frames = MwGetInteger(seekbar, MwNvalue) * queue[queue_seek].sound->context->sample_rate));
changed = 0;
} else {
MwVaApply(seekbar,
@ -280,7 +280,7 @@ static void bskipback_activate(MwWidget handle, void* user, void* client) {
}
if(arrlen(queue) > 0) {
queue[queue_seek].frames = 0;
sf_seek(queue[queue_seek].sf, 0, SEEK_SET);
MDESoundSeek(queue[queue_seek].sound, 0);
} else {
queue_seek = -1;
}
@ -303,7 +303,7 @@ static void bstop_activate(MwWidget handle, void* user, void* client) {
pthread_mutex_lock(&audio_mutex);
if(queue_seek != -1) {
queue[queue_seek].frames = 0;
sf_seek(queue[queue_seek].sf, 0, SEEK_SET);
MDESoundSeek(queue[queue_seek].sound, 0);
}
queue_seek = -1;
pthread_mutex_unlock(&audio_mutex);
@ -318,7 +318,7 @@ static void bskipfwd_activate(MwWidget handle, void* user, void* client) {
}
if(arrlen(queue) > 0) {
queue[queue_seek].frames = 0;
sf_seek(queue[queue_seek].sf, 0, SEEK_SET);
MDESoundSeek(queue[queue_seek].sound, 0);
} else {
queue_seek = -1;
}