forked from Ancurio/mkxp
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathalstream.h
125 lines (97 loc) · 2.29 KB
/
alstream.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
** alstream.h
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <[email protected]>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** mkxp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ALSTREAM_H
#define ALSTREAM_H
#include "al-util.h"
#include "aldatasource.h"
#include "sdl-util.h"
#include <string>
#include <SDL_rwops.h>
#define STREAM_BUFS 3
/* State-machine like audio playback stream.
* This class is NOT thread safe */
struct ALStream
{
enum State
{
Closed,
Stopped,
Playing,
Paused
};
bool looped;
State state;
ALDataSource *source;
SDL_Thread *thread;
std::string threadName;
SDL_mutex *pauseMut;
bool preemptPause;
/* When this flag isn't set and alSrc is
* in 'STOPPED' state, stream isn't over
* (it just hasn't started yet) */
AtomicFlag streamInited;
AtomicFlag sourceExhausted;
AtomicFlag threadTermReq;
AtomicFlag needsRewind;
float startOffset;
float pitch;
AL::Source::ID alSrc;
AL::Buffer::ID alBuf[STREAM_BUFS];
uint64_t procFrames;
AL::Buffer::ID lastBuf;
SDL_RWops srcOps;
struct
{
ALenum format;
ALsizei freq;
} stream;
enum LoopMode
{
Looped,
NotLooped
};
ALStream(LoopMode loopMode,
const std::string &threadId);
~ALStream();
void close();
void open(const std::string &filename);
void stop();
void play(float offset = 0);
void pause();
void setVolume(float value);
void setPitch(float value);
State queryState();
float queryOffset();
bool queryNativePitch();
void update();
private:
void closeSource();
void openSource(const std::string &filename);
void stopStream();
void startStream(float offset);
void pauseStream();
void resumeStream();
void checkStopped();
/* thread func */
void streamData();
ALDataSource::Status status;
};
#endif // ALSTREAM_H