qm-dsp  1.8
Framer.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  QM DSP Library
5 
6  Centre for Digital Music, Queen Mary, University of London.
7  This file 2005-2006 Christian Landone.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "Framer.h"
17 #include <math.h>
18 
20 // Construction/Destruction
22 
24 {
25  m_dataFrame = NULL;
27 }
28 
30 {
31  if( m_dataFrame != NULL )
32  delete [] m_dataFrame;
33 
34  if( m_strideFrame != NULL )
35  delete [] m_strideFrame;
36 }
37 
38 void Framer::configure( unsigned int frameLength, unsigned int hop )
39 {
40  m_frameLength = frameLength;
41  m_stepSize = hop;
42 
43  resetCounters();
44 
45  if( m_dataFrame != NULL )
46  {
47  delete [] m_dataFrame;
48  m_dataFrame = NULL;
49  }
50  m_dataFrame = new double[ m_frameLength ];
51 
52  if( m_strideFrame != NULL )
53  {
54  delete [] m_strideFrame;
56  }
57  m_strideFrame = new double[ m_stepSize ];
58 }
59 
60 void Framer::getFrame(double *dst)
61 {
62 
64  {
65  for( unsigned int u = 0; u < m_frameLength; u++)
66  {
67  dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ];
68  }
69  m_ulSrcIndex -= ( m_frameLength - m_stepSize );
70  }
71  else
72  {
73  unsigned int rem = (m_ulSampleLen - m_ulSrcIndex );
74  unsigned int zero = m_frameLength - rem;
75 
76  for( unsigned int u = 0; u < rem; u++ )
77  {
78  dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ];
79  }
80 
81  for( unsigned int u = 0; u < zero; u++ )
82  {
83  dst[ rem + u ] = 0;
84  }
85 
86  m_ulSrcIndex -= (( rem - m_stepSize ) );
87  }
88 
89  m_framesRead++;
90 }
91 
93 {
94  m_framesRead = 0;
95  m_ulSrcIndex = 0;
96 }
97 
98 unsigned int Framer::getMaxNoFrames()
99 {
100  return m_maxFrames;
101 }
102 
103 void Framer::setSource(double *src, unsigned int length)
104 {
105  m_srcBuffer = src;
106  m_ulSampleLen = length;
107 
108  m_maxFrames = (unsigned int)ceil( (double)m_ulSampleLen/(double)m_stepSize ) ;
109 }
void getFrame(double *dst)
Definition: Framer.cpp:60
unsigned long m_ulSampleLen
Definition: Framer.h:38
unsigned int m_frameLength
Definition: Framer.h:44
double * m_srcBuffer
Definition: Framer.h:41
unsigned int m_maxFrames
Definition: Framer.h:47
double * m_dataFrame
Definition: Framer.h:42
void setSource(double *src, unsigned int length)
Definition: Framer.cpp:103
#define NULL
Definition: Filter.h:20
double * m_strideFrame
Definition: Framer.h:43
void configure(unsigned int frameLength, unsigned int hop)
Definition: Framer.cpp:38
unsigned int getMaxNoFrames()
Definition: Framer.cpp:98
Framer()
Definition: Framer.cpp:23
unsigned long m_ulSrcIndex
Definition: Framer.h:49
virtual ~Framer()
Definition: Framer.cpp:29
unsigned int m_framesRead
Definition: Framer.h:39
unsigned int m_stepSize
Definition: Framer.h:45
void resetCounters()
Definition: Framer.cpp:92