Mercurial > hg > qm-dsp
annotate dsp/tonal/TCSgram.cpp @ 241:a98dd8ec96f8
* Move dsp/maths to maths ; bring PCA and HMM across from Soundbite
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 09 Jan 2008 10:31:29 +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 2006 Martin Gasser. |
c@225 | 8 All rights reserved. |
c@225 | 9 */ |
c@225 | 10 |
c@225 | 11 #include "TCSgram.h" |
c@225 | 12 |
c@225 | 13 #include <valarray> |
c@225 | 14 #include <cmath> |
c@225 | 15 #include <iostream> |
c@225 | 16 #include <limits> |
c@225 | 17 |
c@241 | 18 #include "maths/MathUtilities.h" |
c@225 | 19 |
c@225 | 20 TCSGram::TCSGram() : |
c@225 | 21 m_uNumBins(6) |
c@225 | 22 { |
c@225 | 23 } |
c@225 | 24 |
c@225 | 25 TCSGram::~TCSGram() |
c@225 | 26 { |
c@225 | 27 } |
c@225 | 28 |
c@225 | 29 |
c@225 | 30 void TCSGram::getTCSVector(int iPosition, TCSVector& rTCSVector) const |
c@225 | 31 { |
c@225 | 32 if (iPosition < 0) |
c@225 | 33 rTCSVector = TCSVector(); |
c@225 | 34 else if (iPosition >= m_VectorList.size()) |
c@225 | 35 rTCSVector = TCSVector(); |
c@225 | 36 else |
c@225 | 37 rTCSVector = m_VectorList[iPosition].second; |
c@225 | 38 } |
c@225 | 39 |
c@225 | 40 long TCSGram::getTime(size_t uPosition) const |
c@225 | 41 { |
c@225 | 42 return m_VectorList[uPosition].first; |
c@225 | 43 } |
c@225 | 44 |
c@225 | 45 |
c@225 | 46 void TCSGram::addTCSVector(const TCSVector& rTCSVector) |
c@225 | 47 { |
c@225 | 48 size_t uSize = m_VectorList.size(); |
c@225 | 49 long lMilliSeconds = static_cast<long>(uSize*m_dFrameDurationMS); |
c@225 | 50 std::pair<long, TCSVector> p; |
c@225 | 51 p.first = lMilliSeconds; |
c@225 | 52 p.second = rTCSVector; |
c@225 | 53 |
c@225 | 54 m_VectorList.push_back(p); |
c@225 | 55 } |
c@225 | 56 |
c@225 | 57 long TCSGram::getDuration() const |
c@225 | 58 { |
c@225 | 59 size_t uSize = m_VectorList.size(); |
c@225 | 60 return static_cast<long>(uSize*m_dFrameDurationMS); |
c@225 | 61 } |
c@225 | 62 |
c@225 | 63 void TCSGram::printDebug() |
c@225 | 64 { |
c@225 | 65 vectorlist_t::iterator vectorIterator = m_VectorList.begin(); |
c@225 | 66 |
c@225 | 67 while (vectorIterator != m_VectorList.end()) |
c@225 | 68 { |
c@225 | 69 vectorIterator->second.printDebug(); |
c@225 | 70 vectorIterator++; |
c@225 | 71 } |
c@225 | 72 } |