ScummVM API documentation
audiocd-stream.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Original license header:
21 *
22 * Cabal - Legacy Game Implementations
23 *
24 * Cabal is the legal property of its developers, whose names
25 * are too numerous to list here. Please refer to the COPYRIGHT
26 * file distributed with this source distribution.
27 *
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 2 of the License, or
31 * (at your option) any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 *
41 */
42
43#ifndef BACKENDS_AUDIOCD_AUDIOCD_STREAM_H
44#define BACKENDS_AUDIOCD_AUDIOCD_STREAM_H
45
46#include "audio/audiostream.h"
47#include "common/mutex.h"
48#include "common/queue.h"
49#include "common/timer.h"
50
52public:
55
56 int readBuffer(int16 *buffer, const int numSamples) override;
57 bool isStereo() const override { return true; }
58 int getRate() const override { return 44100; }
59 bool endOfData() const override;
60 bool seek(const Audio::Timestamp &where) override;
61 Audio::Timestamp getLength() const override;
62
63protected:
64 virtual uint getStartFrame() const = 0;
65 virtual uint getEndFrame() const = 0;
66 virtual bool readFrame(int frame, int16 *buffer) = 0;
67
68 void startTimer(bool fillBuffer = false);
69 void stopTimer();
70
71 enum {
72 kBytesPerFrame = 2352,
73 kSamplesPerFrame = kBytesPerFrame / 2
74 };
75
76 enum {
77 kSecondsPerMinute = 60,
78 kFramesPerSecond = 75
79 };
80
81 enum {
82 // Keep about a second's worth of audio in the buffer
83 kBufferThreshold = kFramesPerSecond
84 };
85
86private:
87 int16 _buffer[kSamplesPerFrame];
88 int _frame;
89 uint _bufferPos;
90
91 Common::Queue<int16 *> _bufferQueue;
92 int _bufferFrame;
93 Common::Mutex _mutex;
94
95 bool _forceStop;
96 bool shouldForceStop() const;
97 void forceStop();
98 Common::Mutex _forceStopMutex;
99
100 bool readNextFrame();
101 static void timerProc(void *refCon);
102 void onTimer();
103 void emptyQueue();
104};
105
106#endif
Definition: audiostream.h:212
Definition: timestamp.h:83
Definition: audiocd-stream.h:51
bool isStereo() const override
Definition: audiocd-stream.h:57
bool seek(const Audio::Timestamp &where) override
Audio::Timestamp getLength() const override
bool endOfData() const override
int readBuffer(int16 *buffer, const int numSamples) override
int getRate() const override
Definition: audiocd-stream.h:58
Definition: mutex.h:67