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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef TITANIC_AUDIO_BUFFER_H 24 #define TITANIC_AUDIO_BUFFER_H 25 26 #include "titanic/support/fixed_queue.h" 27 #include "common/mutex.h" 28 29 namespace Titanic { 30 31 #define AUDIO_SAMPLING_RATE 22050 32 33 class CAudioBuffer { 34 private: 35 Common::Mutex _mutex; 36 FixedQueue<int16, AUDIO_SAMPLING_RATE * 4> _data; 37 private: 38 /** 39 * Enters a critical section 40 */ 41 void enterCriticalSection(); 42 43 /** 44 * Leave a critical section 45 */ 46 void leaveCriticalSection(); 47 private: 48 bool _finished; 49 public: 50 CAudioBuffer(int maxSize); 51 52 /** 53 * Resets the audio buffer 54 */ 55 void reset(); 56 57 /** 58 * Returns true if the buffer is empty 59 */ empty()60 bool empty() const { return _data.empty(); } 61 62 /** 63 * Returns the number of 16-bit entries in the buffer 64 */ size()65 int size() const { return _data.size(); } 66 67 /** 68 * Returns the number of entries free in the buffer 69 */ freeSize()70 int freeSize() const { return _data.freeSize(); } 71 72 /** 73 * Returns true if the buffer is full 74 */ full()75 bool full() const { return _data.full(); } 76 77 /** 78 * Returns true if the audio buffering is finished 79 */ isFinished()80 bool isFinished() const { return _finished && empty(); } 81 82 /** 83 * Adds a value to the buffer 84 */ 85 void push(int16 value); 86 87 /** 88 * Adds a value to the buffer 89 */ 90 void push(const int16 *values, int count); 91 92 /** 93 * Removes a value from the buffer 94 */ 95 int16 pop(); 96 97 /** 98 * Reads out a specified number of samples 99 */ 100 int read(int16 *values, int count); 101 102 /** 103 * Marks the buffer as finishing, and that no more new data will arrive 104 */ finalize()105 void finalize() { _finished = true; } 106 }; 107 108 } // End of namespace Titanic 109 110 #endif /* TITANIC_AUDIO_BUFFER_H */ 111