/* aKode: Converter Copyright (C) 2005,2006 Allan Sandfeld Jensen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "arithmetic.h" #include "audioframe.h" #include "converter.h" namespace aKode { Converter::Converter(int sample_width) : m_sample_width(sample_width) {} template class ArithmT, template class ArithmS> static bool __doFrameFP(AudioFrame* in, AudioFrame* out, int sample_width) { AudioConfiguration config = *in; config.sample_width = sample_width; if (out) out->reserveSpace(&config, in->length); else out = in; // ### Use doubles if double sized or 32bit samples are used. float scale = 1.0; scale = ArithmS::max(sample_width)/(float)ArithmT::max(in->sample_width); int channels = in->channels; int length = in->length; T** indata = (T**)in->data; S** outdata = (S**)out->data; for(int i=0; i static bool __doFrame(AudioFrame* in, AudioFrame* out, int sample_width) { AudioConfiguration config = *in; config.sample_width = sample_width; if (out) out->reserveSpace(&config, in->length); else out = in; int width_T = sizeof(T)*8; int shift = width_T - sample_width; int channels = in->channels; uint32_t length = in->length; T** indata = (T**)in->data; S** outdata = (S**)out->data; for(int i=0; i> shift); out->sample_width = sample_width; return true; } template static inline bool _doFrameFP(AudioFrame* in, AudioFrame* out, int sample_width) { if (in->sample_width == -64) { return __doFrameFP(in, out, sample_width); } else if (in->sample_width == -32) { return __doFrameFP(in, out, sample_width); } else if (in->sample_width <= 8) { return __doFrameFP(in, out, sample_width); } else if (in->sample_width <= 16) { return __doFrameFP(in, out, sample_width); } else return __doFrameFP(in, out, sample_width); } template static inline bool _doFrame(AudioFrame* in, AudioFrame* out, int sample_width) { if (in->sample_width == -64) { return __doFrameFP(in, out, sample_width); } else if (in->sample_width == -32) { return __doFrameFP(in, out, sample_width); } else if (in->sample_width <= 8) { return __doFrame(in, out, sample_width); } else if (in->sample_width <= 16) { return __doFrame(in, out, sample_width); } else return __doFrame(in, out, sample_width); } bool Converter::doFrame(AudioFrame* in, AudioFrame* out) { if (m_sample_width == 0) return false; if (!out && in->sample_width == m_sample_width) return true; if (m_sample_width < 0) { if (m_sample_width == -64) return _doFrameFP(in, out, m_sample_width); else return _doFrameFP(in, out, m_sample_width); } else if (m_sample_width <= 8) { return _doFrame(in, out, m_sample_width); } else if (m_sample_width <= 16) { return _doFrame(in, out, m_sample_width); } else return _doFrame(in, out, m_sample_width); return false; } void Converter::setSampleWidth(int sample_width) { m_sample_width = sample_width; } } // namespace