/* * --- GSMP-COPYRIGHT-NOTE-BEGIN --- * * This copyright note is auto-generated by ./scripts/Create-CopyPatch. * Please add additional copyright information _after_ the line containing * the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by * the ./scripts/Create-CopyPatch script. Do not edit this copyright text! * * GSMP: pcm/include/template/PcmBuffer.tcc * General Sound Manipulation Program is Copyright (C) 2000 - 2004 * Valentin Ziegler and René Rebe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2. A copy of the GNU General * Public License can be found in the file LICENSE. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT- * ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * --- GSMP-COPYRIGHT-NOTE-END --- */ #ifndef LOWLEVEL__PCMBUFFER_TMPL__ #error "This file is included by PcmBuffer.hh." #error "Include that file instead." #endif #include "Logger.hh" namespace GSMP { template PcmBuffer::PcmBuffer(local_index i_size) { m_size = i_size; m_used_size = 0; data = new T [m_size]; } template PcmBuffer::~PcmBuffer () { delete [] data; } template template PcmBuffer& PcmBuffer::operator= (PcmBuffer& src) { } template template void PcmBuffer::ReadData (local_index index, local_index read_size, PcmBuffer& destination) const { // enought data available?? if (index + read_size > m_used_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "not enought data available - limitted!" << std::endl; read_size = m_used_size - index; } // destination buffer holds enought empty space? if (read_size > destination.FreeSize () ) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "not enought free destination space available - limitted!" << std::endl; read_size = destination.FreeSize (); } local_index di = destination.UsedSize (); local_index si = index; for (; si < index + read_size; ++si, ++di) { destination.data [di] = data [si]; } } template template void PcmBuffer::WriteData (local_index write_size, const PcmBuffer & source) { typedef typename PcmBuffer ::pcm_type src_type; // buffer big enough?? if (m_used_size + write_size > m_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "buffer too small - limitted!" << std::endl; write_size = m_size - m_used_size; } for (local_index i = 0; i < write_size; ++i) { data [m_used_size + i] = PcmConvert::Convert (source.data [i]) ; } m_used_size += write_size; } template void PcmBuffer::WriteZero (local_index zero_size) { // bounds checking ... if (m_used_size + zero_size > m_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "buffer too small - limitted!" << std::endl; zero_size = m_size - m_used_size; } ZeroImpl (m_used_size, zero_size); m_used_size += zero_size; } template void PcmBuffer::WriteZeroUnused () { ZeroImpl (m_used_size, m_size - m_used_size); m_used_size = m_size; } template void PcmBuffer::SetUsedSize (local_index new_used_size) { if (new_used_size > m_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "buffer too small - limitted!" << std::endl; new_used_size = m_size; } m_used_size = new_used_size; } template T& PcmBuffer::operator[] (local_index index) { if (0 /* debug */) if (index < m_used_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "out of bounds - skipped!!" << std::endl; m_zero = PcmTraits::Zero (); return m_zero; } return data [index]; } template const T& PcmBuffer::operator[] (local_index index) const { if (0 /* debug */) if (index < m_used_size) { Q_WARN(LowlevelLog) << __PRETTY_FUNCTION__ << "out of bounds - skipped!!" << std::endl; return PcmTraits::Zero (); } return data [index]; } template void PcmBuffer::ZeroImpl (local_index start, local_index size) { if (PcmTraits::IsInteger) { memset (data + (start * PcmTraits::Size()), size * PcmTraits::Size(), 0); } else { for (local_index i = start; i < start + size; ++i) data [i] = PcmTraits::Zero(); } } } // end namespace GSMP