libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiSoundOggPlayer.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiSoundOggPlayer.h
5 ***************************************************************************/
6#pragma once
7#include <stdint.h>
8#include <tremor/ivorbisfile.h>
9#include "../drivers/ThreadDriver.h"
10
17class GuiSoundOggPlayer {
18 public:
19 GuiSoundOggPlayer();
20 ~GuiSoundOggPlayer();
21
31 bool play(const uint8_t *data, int32_t length, int time_pos, bool loop);
33 void stop();
35 void pause(bool pause);
36
39 bool isPlaying() const {
40 return threadRunning;
41 }
42
43 bool isPaused() const {
44 return streamPaused;
45 }
46
47 int getSampleRate() const {
48 return sampleRate;
49 }
50
51 int getChannels() const {
52 return channels;
53 }
54
58 const uint8_t* getReadyBuffer(int32_t *outSize);
61 void consumeBuffer();
62
63 private:
64 static void* threadEntry(void *arg);
65 void threadLoop();
66
67 static size_t readOgg(void *ptr, size_t size, size_t nmemb, void *datasource);
68 static int seekOgg(void *datasource, ogg_int64_t offset, int whence);
69 static int closeOgg(void *datasource);
70 static long tellOgg(void *datasource);
71
72 struct MemFile {
73 const uint8_t *data;
74 int32_t size;
75 int32_t pos;
76 };
77
78 MemFile memFile;
79 OggVorbis_File vf;
80 bool vfOpen;
81 Thread decodeThread;
82
83 volatile bool threadRunning;
84 volatile bool streamPaused;
85 volatile bool streamLoop;
86
87 int sampleRate;
88 int channels;
89
90 static const int BUFFER_SIZE = 16384;
91 uint8_t *pcmBuffer[2];
92 int32_t pcmBufferSize[2];
93 volatile bool bufferReady[2];
94
95 volatile int decodeIndex;
96 volatile int playIndex;
97};
void consumeBuffer()
Releases the buffer last returned by getReadyBuffer(), letting the decode thread reuse that ring slot...
void pause(bool pause)
Pauses or resumes the decode thread without stopping it.
const uint8_t * getReadyBuffer(int32_t *outSize)
bool play(const uint8_t *data, int32_t length, int time_pos, bool loop)
Starts decoding data on a new thread.
int getSampleRate() const
void stop()
Stops playback and joins the decode thread.