-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvorbis-stream.hpp
63 lines (41 loc) · 1.17 KB
/
vorbis-stream.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <string>
#include "audio/audio.hpp"
#include "engine/file.hpp"
#include "music-stream.hpp"
#include "music-tags.hpp"
struct stb_vorbis;
class VorbisStream final : public MusicStream
{
public:
VorbisStream();
~VorbisStream();
bool load(std::string filename);
//MusicTags parseTags(std::string filename);
void play(int channel);
void pause();
bool getPlaying() const;
void update();
int getCurrentSample() const;
int getDurationMs() const;
const MusicTags &getTags() const;
bool getFileSupported() const;
private:
void decode(int bufIndex);
uint64_t calcDuration(std::string filename);
static void staticCallback(blit::AudioChannel &channel);
void callback(blit::AudioChannel &channel);
int channel = -1;
stb_vorbis *vorbis;
unsigned int channels, sampleRate;
bool needConvert = false;
static const int audioBufSize = 1024 * 4;
int16_t audioBuf[2][audioBufSize];
int16_t *currentSample = nullptr, *endSample = nullptr;
int dataSize[2]{};
int curAudioBuf = 0;
int bufferedSamples = 0;
int durationMs = 0;
MusicTags tags;
bool supported = true;
};