annotate dsp/signalconditioning/Framer.cpp @ 298:255e431ae3d4

* Key detector: when returning key strengths, use the peak value of the three underlying chromagram correlations (from 36-bin chromagram) corresponding to each key, instead of the mean. Rationale: This is the same method as used when returning the key value, and it's nice to have the same results in both returned value and plot. The peak performed better than the sum with a simple test set of triads, so it seems reasonable to change the plot to match the key output rather than the other way around. * FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest rather than leaving them (perhaps dangerously) undefined. Fixes an uninitialised data error in chromagram that could cause garbage results from key detector. * Constant Q: remove precalculated values again, I reckon they're not proving such a good tradeoff.
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 05 Jun 2009 15:12:39 +0000
parents 49844bc8a895
children e5907ae6de17
rev   line source
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@225 7 This file copyright 2005-2006 Christian Landone.
c@225 8 All rights reserved.
c@225 9 */
c@225 10
c@225 11 #include "Framer.h"
c@225 12 #include <math.h>
c@225 13
c@225 14 //////////////////////////////////////////////////////////////////////
c@225 15 // Construction/Destruction
c@225 16 //////////////////////////////////////////////////////////////////////
c@225 17
c@225 18 Framer::Framer()
c@225 19 {
c@225 20 m_dataFrame = NULL;
c@225 21 m_strideFrame = NULL;
c@225 22 }
c@225 23
c@225 24 Framer::~Framer()
c@225 25 {
c@225 26 if( m_dataFrame != NULL )
c@225 27 delete [] m_dataFrame;
c@225 28
c@225 29 if( m_strideFrame != NULL )
c@225 30 delete [] m_strideFrame;
c@225 31 }
c@225 32
c@225 33 void Framer::configure( unsigned int frameLength, unsigned int hop )
c@225 34 {
c@225 35 m_frameLength = frameLength;
c@225 36 m_stepSize = hop;
c@225 37
c@225 38 resetCounters();
c@225 39
c@225 40 if( m_dataFrame != NULL )
c@225 41 {
c@225 42 delete [] m_dataFrame;
c@225 43 m_dataFrame = NULL;
c@225 44 }
c@225 45 m_dataFrame = new double[ m_frameLength ];
c@225 46
c@225 47 if( m_strideFrame != NULL )
c@225 48 {
c@225 49 delete [] m_strideFrame;
c@225 50 m_strideFrame = NULL;
c@225 51 }
c@225 52 m_strideFrame = new double[ m_stepSize ];
c@225 53 }
c@225 54
c@225 55 void Framer::getFrame(double *dst)
c@225 56 {
c@225 57
c@225 58 if( (m_ulSrcIndex + ( m_frameLength) ) < m_ulSampleLen )
c@225 59 {
c@225 60 for( unsigned int u = 0; u < m_frameLength; u++)
c@225 61 {
c@225 62 dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ];
c@225 63 }
c@225 64 m_ulSrcIndex -= ( m_frameLength - m_stepSize );
c@225 65 }
c@225 66 else
c@225 67 {
c@225 68 unsigned int rem = (m_ulSampleLen - m_ulSrcIndex );
c@225 69 unsigned int zero = m_frameLength - rem;
c@225 70
c@225 71 for( unsigned int u = 0; u < rem; u++ )
c@225 72 {
c@225 73 dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ];
c@225 74 }
c@225 75
c@225 76 for( unsigned int u = 0; u < zero; u++ )
c@225 77 {
c@225 78 dst[ rem + u ] = 0;
c@225 79 }
c@225 80
c@225 81 m_ulSrcIndex -= (( rem - m_stepSize ) );
c@225 82 }
c@225 83
c@225 84 m_framesRead++;
c@225 85 }
c@225 86
c@225 87 void Framer::resetCounters()
c@225 88 {
c@225 89 m_framesRead = 0;
c@225 90 m_ulSrcIndex = 0;
c@225 91 }
c@225 92
c@225 93 unsigned int Framer::getMaxNoFrames()
c@225 94 {
c@225 95 return m_maxFrames;
c@225 96 }
c@225 97
c@225 98 void Framer::setSource(double *src, unsigned int length)
c@225 99 {
c@225 100 m_srcBuffer = src;
c@225 101 m_ulSampleLen = length;
c@225 102
c@225 103 m_maxFrames = (unsigned int)ceil( (double)m_ulSampleLen/(double)m_stepSize ) ;
c@225 104 }