~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/soundtouch/source/example/bpm/PeakFinder.h

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////////////////////
2
 
///
3
 
/// The routine detects highest value on an array of values and calculates the 
4
 
/// precise peak location as a mass-center of the 'hump' around the peak value.
5
 
///
6
 
/// Author        : Copyright (c) Olli Parviainen
7
 
/// Author e-mail : oparviai 'at' iki.fi
8
 
/// SoundTouch WWW: http://www.surina.net/soundtouch
9
 
///
10
 
////////////////////////////////////////////////////////////////////////////////
11
 
//
12
 
// Last changed  : $Date: 2006/09/18 07:31:49 $
13
 
// File revision : $Revision: 1.2 $
14
 
//
15
 
// $Id: PeakFinder.h,v 1.2 2006/09/18 07:31:49 richardash1981 Exp $
16
 
//
17
 
////////////////////////////////////////////////////////////////////////////////
18
 
//
19
 
// License :
20
 
//
21
 
//  SoundTouch audio processing library
22
 
//  Copyright (c) Olli Parviainen
23
 
//
24
 
//  This library is free software; you can redistribute it and/or
25
 
//  modify it under the terms of the GNU Lesser General Public
26
 
//  License as published by the Free Software Foundation; either
27
 
//  version 2.1 of the License, or (at your option) any later version.
28
 
//
29
 
//  This library is distributed in the hope that it will be useful,
30
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32
 
//  Lesser General Public License for more details.
33
 
//
34
 
//  You should have received a copy of the GNU Lesser General Public
35
 
//  License along with this library; if not, write to the Free Software
36
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37
 
//
38
 
////////////////////////////////////////////////////////////////////////////////
39
 
 
40
 
#ifndef _PeakFinder_H_
41
 
#define _PeakFinder_H_
42
 
 
43
 
class PeakFinder
44
 
{
45
 
protected:
46
 
    /// Min, max allowed peak positions within the data vector
47
 
    int minPos, maxPos;
48
 
 
49
 
    /// Calculates the mass center between given vector items.
50
 
    float calcMassCenter(const float *data, ///< Data vector.
51
 
                         int firstPos,      ///< Index of first vector item beloging to the peak.
52
 
                         int lastPos        ///< Index of last vector item beloging to the peak.
53
 
                         ) const;
54
 
 
55
 
    /// Finds the data vector index where the monotoniously decreasing signal crosses the
56
 
    /// given level.
57
 
    int   findCrossingLevel(const float *data,  ///< Data vector.
58
 
                            float level,        ///< Goal crossing level.
59
 
                            int peakpos,        ///< Peak position index within the data vector.
60
 
                            int direction       /// Direction where to proceed from the peak: 1 = right, -1 = left.
61
 
                            ) const;
62
 
 
63
 
    /// Finds the 'ground' level, i.e. smallest level between two neighbouring peaks, to right- 
64
 
    /// or left-hand side of the given peak position.
65
 
    int   findGround(const float *data,     /// Data vector.
66
 
                     int peakpos,           /// Peak position index within the data vector.
67
 
                     int direction          /// Direction where to proceed from the peak: 1 = right, -1 = left.
68
 
                     ) const;
69
 
 
70
 
public:
71
 
    /// Constructor. 
72
 
    PeakFinder();
73
 
 
74
 
    /// Detect exact peak position of the data vector by finding the largest peak 'hump'
75
 
    /// and calculating the mass-center location of the peak hump. 
76
 
    ///
77
 
    /// \return The exact mass-center location of the largest peak hump.
78
 
    float detectPeak(const float *data, /// Data vector to be analyzed. The data vector has
79
 
                                        /// to be at least 'maxPos' items long.
80
 
                     int minPos,        ///< Min allowed peak location within the vector data.
81
 
                     int maxPos         ///< Max allowed peak location within the vector data.
82
 
                     );
83
 
};
84
 
 
85
 
#endif // _PeakFinder_H_