c@225: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@225: c@225: /* c@225: QM DSP Library c@225: c@225: Centre for Digital Music, Queen Mary, University of London. c@309: This file 2005-2006 Christian Landone. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@225: */ c@225: c@225: #include "Framer.h" cannam@485: #include cannam@485: #include c@225: c@225: ////////////////////////////////////////////////////////////////////// c@225: // Construction/Destruction c@225: ////////////////////////////////////////////////////////////////////// c@225: c@225: Framer::Framer() c@225: { c@225: m_dataFrame = NULL; c@225: m_strideFrame = NULL; c@225: } c@225: c@225: Framer::~Framer() c@225: { cannam@483: if( m_dataFrame != NULL ) { cannam@483: delete [] m_dataFrame; cannam@483: } c@225: cannam@483: if( m_strideFrame != NULL ) { cannam@483: delete [] m_strideFrame; cannam@483: } c@225: } c@225: c@225: void Framer::configure( unsigned int frameLength, unsigned int hop ) c@225: { c@225: m_frameLength = frameLength; c@225: m_stepSize = hop; c@225: c@225: resetCounters(); c@225: cannam@483: if( m_dataFrame != NULL ) { cannam@483: delete [] m_dataFrame; cannam@483: m_dataFrame = NULL; c@225: } c@225: m_dataFrame = new double[ m_frameLength ]; c@225: cannam@483: if( m_strideFrame != NULL ) { cannam@483: delete [] m_strideFrame; cannam@483: m_strideFrame = NULL; c@225: } c@225: m_strideFrame = new double[ m_stepSize ]; c@225: } c@225: c@225: void Framer::getFrame(double *dst) c@225: { c@225: cannam@483: if( (m_ulSrcIndex + ( m_frameLength) ) < m_ulSampleLen ) { c@225: cannam@483: for( unsigned int u = 0; u < m_frameLength; u++) { cannam@483: dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ]; cannam@483: } cannam@483: m_ulSrcIndex -= ( m_frameLength - m_stepSize ); c@225: cannam@483: } else { cannam@483: cannam@483: unsigned int rem = (m_ulSampleLen - m_ulSrcIndex ); cannam@483: unsigned int zero = m_frameLength - rem; cannam@483: cannam@483: for( unsigned int u = 0; u < rem; u++ ) { cannam@483: dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ]; cannam@483: } cannam@483: cannam@483: for( unsigned int u = 0; u < zero; u++ ) { cannam@483: dst[ rem + u ] = 0; cannam@483: } cannam@483: cannam@483: m_ulSrcIndex -= (( rem - m_stepSize ) ); c@225: } c@225: c@225: m_framesRead++; c@225: } c@225: c@225: void Framer::resetCounters() c@225: { c@225: m_framesRead = 0; c@225: m_ulSrcIndex = 0; c@225: } c@225: c@225: unsigned int Framer::getMaxNoFrames() c@225: { c@225: return m_maxFrames; c@225: } c@225: c@225: void Framer::setSource(double *src, unsigned int length) c@225: { c@225: m_srcBuffer = src; c@225: m_ulSampleLen = length; c@225: c@225: m_maxFrames = (unsigned int)ceil( (double)m_ulSampleLen/(double)m_stepSize ) ; c@225: }