diff options
author | quou <quou@disroot.org> | 2024-06-03 21:05:14 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-06-03 21:05:22 +1000 |
commit | 6589107006fd4fc06bdb7d02cb4b1eef45395458 (patch) | |
tree | af196448b28aa4a1ec612e2c1b1578465c203c12 /library.c | |
parent | 62b4a3ededd237f4b4850d91c052585e2f687499 (diff) |
Basic audio playback with pulseaudio.
Diffstat (limited to 'library.c')
-rw-r--r-- | library.c | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -1,3 +1,4 @@ +#include "config.h" #include "library.h" #include "plat.h" #include <string.h> @@ -103,7 +104,6 @@ void flac_meta( drflac_vorbis_comment_iterator i; drflac_uint32 len; const char* c; - int size; switch (m->type) { case DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT: drflac_init_vorbis_comment_iterator( @@ -137,5 +137,51 @@ int get_song_meta(const char* path, Song* s) { return 0; } +int sound_mix( + void* uptr, + unsigned char* buf, + int size +) { + Player* p; + drflac* f; + int r; + (void)size; + p = uptr; + f = p->f; + r = drflac_read_pcm_frames_s32( + f, + size / p->channels / 4, + (int*)buf + ); + return r * p->channels * 4; +} + +void init_player(Player* p) { + p->seek = 0; + p->song = 0; + p->play = 0; +} + +void play_song(Player* p, Song* song) { + drflac* f; + int sr, channels; + f = drflac_open_file( + song->path, + 0 + ); + /* todo errors and stuff */ + if (!f) return; + channels = f->channels; + sr = f->sampleRate; + p->f = f; + p->channels = channels; + stop_audio(); + init_audio( + p, + sr, + channels + ); +} + #define DR_FLAC_IMPLEMENTATION #include "dr_flac.h" |