00001 /* 00002 Copyright (C) 2005 The Pentagram team 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License 00006 as published by the Free Software Foundation; either version 2 00007 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "pent_include.h" 00020 #include "RawAudioSample.h" 00021 #include "IDataSource.h" 00022 00023 namespace Pentagram { 00024 00025 RawAudioSample::RawAudioSample(uint8* buffer_, uint32 size_, uint32 rate_, 00026 bool signeddata_, bool stereo_) 00027 : AudioSample(buffer_, size_), signeddata(signeddata_) 00028 { 00029 sample_rate = rate_; 00030 bits = 8; 00031 stereo = stereo_; 00032 frame_size = 512; 00033 decompressor_size = sizeof(RawDecompData); 00034 length = size_; 00035 } 00036 00037 RawAudioSample::~RawAudioSample() 00038 { 00039 00040 } 00041 00042 void RawAudioSample::initDecompressor(void *DecompData) const 00043 { 00044 RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData); 00045 decomp->pos = 0; 00046 } 00047 00048 void RawAudioSample::rewind(void *DecompData) const 00049 { 00050 initDecompressor(DecompData); 00051 } 00052 00053 uint32 RawAudioSample::decompressFrame(void *DecompData, void *samples) const 00054 { 00055 RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData); 00056 00057 if (decomp->pos == buffer_size) return 0; 00058 00059 uint32 count = frame_size; 00060 if (decomp->pos + count > buffer_size) 00061 count = buffer_size - decomp->pos; 00062 00063 if (!signeddata) { 00064 std::memcpy(samples, buffer+decomp->pos, count); 00065 } else { 00066 uint8* dest = static_cast<uint8*>(samples); 00067 for (unsigned int i = 0; i < count; ++i) 00068 dest[i] = buffer[decomp->pos+i] + 128; 00069 } 00070 00071 decomp->pos += count; 00072 00073 return count; 00074 } 00075 00076 00077 00078 }