File: trackframe_op.cpp

package info (click to toggle)
libofa 0.9.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,920 kB
  • ctags: 460
  • sloc: cpp: 24,470; sh: 8,366; makefile: 45; ansic: 14
file content (76 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ------------------------------------------------------------------

   libofa -- the Open Fingerprint Architecture library

   Copyright (C) 2006 MusicIP Corporation
   All rights reserved.

-------------------------------------------------------------------*/
// FILE: "trackframe_op.cpp"
// MODULE: Implementation for class TrackFrame_op
// AUTHOR: Stephen Pope
// DATE CREATED: 01/12/06

#include <math.h>
#include "trackdata_op.h"
#include "trackframe_op.h"

// Constructor

TrackFrame_op::TrackFrame_op(float aTime)
{ 
	FrameTime = aTime;
	NumTracks = 0;
	BaseTr = 0;
	NextFr = 0;
}

// Delete the list of peaks on delete

TrackFrame_op::~TrackFrame_op()
{ 
	TrackData_op* trk = BaseTr;
	while (trk != 0) {
		TrackData_op* next = trk->getHigher();
		delete trk;
		trk = next;
	}
}

// Element add/remove

void 
TrackFrame_op::Add(TrackData_op* td)
{
	if (NumTracks == 0)
		BaseTr = td;
	NumTracks++;
}

// Answer the best-match (in frequency) track to the given value

TrackData_op* 
TrackFrame_op::getTrackNearestFreq(float freq)
{

	double diff;
	double minDiff = 10000;
	TrackData_op* answer;
	answer = 0;
	TrackData_op* ptr = BaseTr;
					// Iterate over the receiver's peaks
	while (ptr != 0) {
		if (!ptr->IsInTrack())
		{
						// Find minimum frequency difference
			diff = fabs (ptr->getPitch() - freq);
			if (diff < minDiff) {
				minDiff = diff;
				answer = ptr;
			}
		}
		ptr = ptr->getHigher();
	}
	return answer;
}