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