ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

audiocd-stream.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  * Original license header:
00022  *
00023  * Cabal - Legacy Game Implementations
00024  *
00025  * Cabal is the legal property of its developers, whose names
00026  * are too numerous to list here. Please refer to the COPYRIGHT
00027  * file distributed with this source distribution.
00028  *
00029  * This program is free software; you can redistribute it and/or
00030  * modify it under the terms of the GNU General Public License
00031  * as published by the Free Software Foundation; either version 2
00032  * of the License, or (at your option) any later version.
00033  *
00034  * This program is distributed in the hope that it will be useful,
00035  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00036  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00037  * GNU General Public License for more details.
00038  *
00039  * You should have received a copy of the GNU General Public License
00040  * along with this program; if not, write to the Free Software
00041  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00042  *
00043  */
00044 
00045 #ifndef BACKENDS_AUDIOCD_AUDIOCD_STREAM_H
00046 #define BACKENDS_AUDIOCD_AUDIOCD_STREAM_H
00047 
00048 #include "audio/audiostream.h"
00049 #include "common/mutex.h"
00050 #include "common/queue.h"
00051 #include "common/timer.h"
00052 
00053 class AudioCDStream : public Audio::SeekableAudioStream {
00054 public:
00055     AudioCDStream();
00056     ~AudioCDStream();
00057 
00058     int readBuffer(int16 *buffer, const int numSamples);
00059     bool isStereo() const { return true; }
00060     int getRate() const { return 44100; }
00061     bool endOfData() const;
00062     bool seek(const Audio::Timestamp &where);
00063     Audio::Timestamp getLength() const;
00064 
00065 protected:
00066     virtual uint getStartFrame() const = 0;
00067     virtual uint getEndFrame() const = 0;
00068     virtual bool readFrame(int frame, int16 *buffer) = 0;
00069 
00070     void startTimer(bool fillBuffer = false);
00071     void stopTimer();
00072 
00073     enum {
00074         kBytesPerFrame = 2352,
00075         kSamplesPerFrame = kBytesPerFrame / 2
00076     };
00077 
00078     enum {
00079         kSecondsPerMinute = 60,
00080         kFramesPerSecond = 75
00081     };
00082 
00083     enum {
00084         // Keep about a second's worth of audio in the buffer
00085         kBufferThreshold = kFramesPerSecond
00086     };
00087 
00088 private:
00089     int16 _buffer[kSamplesPerFrame];
00090     int _frame;
00091     uint _bufferPos;
00092 
00093     Common::Queue<int16 *> _bufferQueue;
00094     int _bufferFrame;
00095     Common::Mutex _mutex;
00096 
00097     bool _forceStop;
00098     bool shouldForceStop() const;
00099     void forceStop();
00100     Common::Mutex _forceStopMutex;
00101 
00102     bool readNextFrame();
00103     static void timerProc(void *refCon);
00104     void onTimer();
00105     void emptyQueue();
00106 };
00107 
00108 #endif


Generated on Sat Feb 16 2019 05:00:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge