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@225: This file copyright 2005-2006 Christian Landone. c@225: All rights reserved. c@225: */ c@225: c@225: #include "Framer.h" c@225: #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: { c@225: if( m_dataFrame != NULL ) c@225: delete [] m_dataFrame; c@225: c@225: if( m_strideFrame != NULL ) c@225: delete [] m_strideFrame; 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: c@225: if( m_dataFrame != NULL ) c@225: { c@225: delete [] m_dataFrame; c@225: m_dataFrame = NULL; c@225: } c@225: m_dataFrame = new double[ m_frameLength ]; c@225: c@225: if( m_strideFrame != NULL ) c@225: { c@225: delete [] m_strideFrame; c@225: 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: c@225: if( (m_ulSrcIndex + ( m_frameLength) ) < m_ulSampleLen ) c@225: { c@225: for( unsigned int u = 0; u < m_frameLength; u++) c@225: { c@225: dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ]; c@225: } c@225: m_ulSrcIndex -= ( m_frameLength - m_stepSize ); c@225: } c@225: else c@225: { c@225: unsigned int rem = (m_ulSampleLen - m_ulSrcIndex ); c@225: unsigned int zero = m_frameLength - rem; c@225: c@225: for( unsigned int u = 0; u < rem; u++ ) c@225: { c@225: dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ]; c@225: } c@225: c@225: for( unsigned int u = 0; u < zero; u++ ) c@225: { c@225: dst[ rem + u ] = 0; c@225: } c@225: c@225: 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: }