Skip to content

Commit

Permalink
Enable MP3 format in sample polling hack
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Jun 11, 2024
1 parent f39dcbd commit 25ae314
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ARENA_IMPLEMENTATION
#include "arena.h"
#include "external/dr_wav.h"
#include "external/dr_mp3.h"

#include <raylib.h>
#include <rlgl.h>
Expand Down Expand Up @@ -1243,6 +1244,7 @@ extern int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels,

#define SUPPORT_FILEFORMAT_WAV
#define SUPPORT_FILEFORMAT_OGG
#define SUPPORT_FILEFORMAT_MP3
int poll_samples_from_music(Arena *a, Music music, float *buffer, size_t num_floats)
{
switch (music.ctxType)
Expand Down Expand Up @@ -1281,14 +1283,9 @@ int poll_samples_from_music(Arena *a, Music music, float *buffer, size_t num_flo
#if defined(SUPPORT_FILEFORMAT_MP3)
case MUSIC_AUDIO_MP3:
{
while (true)
{
int frameCountRead = (int)drmp3_read_pcm_frames_f32((drmp3 *)music.ctxData, frameCountStillNeeded, (float *)((char *)AUDIO.System.pcmBuffer + frameCountReadTotal*frameSize));
frameCountReadTotal += frameCountRead;
frameCountStillNeeded -= frameCountRead;
if (frameCountStillNeeded == 0) break;
else drmp3_seek_to_start_of_stream((drmp3 *)music.ctxData);
}
size_t num_samples = num_floats/music.stream.channels;
int frameCountRead = (int)drmp3_read_pcm_frames_f32((drmp3 *)music.ctxData, num_samples, buffer);
return frameCountRead;
} break;
#endif
#if defined(SUPPORT_FILEFORMAT_QOA)
Expand Down

0 comments on commit 25ae314

Please sign in to comment.