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 #include "ultima/ultima8/misc/pent_include.h"
24 #include "ultima/ultima8/audio/raw_audio_sample.h"
25
26 namespace Ultima {
27 namespace Ultima8 {
28
RawAudioSample(const uint8 * buffer,uint32 size,uint32 rate,bool signedData,bool stereo)29 RawAudioSample::RawAudioSample(const uint8 *buffer, uint32 size, uint32 rate,
30 bool signedData, bool stereo)
31 : AudioSample(buffer, size, 8, stereo, false), _signedData(signedData) {
32 _sampleRate = rate;
33 _frameSize = 512;
34 _decompressorSize = sizeof(RawDecompData);
35 _length = size;
36 }
37
~RawAudioSample()38 RawAudioSample::~RawAudioSample() {
39 }
40
initDecompressor(void * DecompData) const41 void RawAudioSample::initDecompressor(void *DecompData) const {
42 RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData);
43 decomp->_pos = 0;
44 }
45
rewind(void * DecompData) const46 void RawAudioSample::rewind(void *DecompData) const {
47 initDecompressor(DecompData);
48 }
49
decompressFrame(void * DecompData,void * samples) const50 uint32 RawAudioSample::decompressFrame(void *DecompData, void *samples) const {
51 RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData);
52
53 if (decomp->_pos == _bufferSize) return 0;
54
55 uint32 count = _frameSize;
56 if (decomp->_pos + count > _bufferSize)
57 count = _bufferSize - decomp->_pos;
58
59 if (!_signedData) {
60 memcpy(samples, _buffer + decomp->_pos, count);
61 } else {
62 uint8 *dest = static_cast<uint8 *>(samples);
63 for (unsigned int i = 0; i < count; ++i)
64 dest[i] = _buffer[decomp->_pos + i] + 128;
65 }
66
67 decomp->_pos += count;
68
69 return count;
70 }
71
72 } // End of namespace Ultima8
73 } // End of namespace Ultima
74