summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-10-04 10:37:46 +0200
committerJohn Glover <j@johnglover.net>2012-10-04 10:37:46 +0200
commit6b113d65e5899f2141536ccc987d9e5bd69394d1 (patch)
tree0fe8041b40f1cf86b64f1a966ed82424b0d77e33
parenta47409a1e57e12dc296b890585aa07cddd3c245a (diff)
downloadsimpl-6b113d65e5899f2141536ccc987d9e5bd69394d1.tar.gz
simpl-6b113d65e5899f2141536ccc987d9e5bd69394d1.tar.bz2
simpl-6b113d65e5899f2141536ccc987d9e5bd69394d1.zip
[mq] Bug fixes: check for peak equality in frequency
values rather than comparing objects (which may change).
-rw-r--r--simpl/mq.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/simpl/mq.py b/simpl/mq.py
index 7a7d8d8..3a4e96f 100644
--- a/simpl/mq.py
+++ b/simpl/mq.py
@@ -200,13 +200,14 @@ class MQPartialTracking(simpl.PartialTracking):
Returns the closest unmatched peak in frame_peaks with a frequency
less than peak.frequency.
"""
+ freqs = [p.frequency for p in matched_peaks if p]
for peak_number, p in enumerate(frame_peaks):
- if p == peak:
+ if p.frequency == peak.frequency:
# go back through lower peaks (in order) and
# return the first unmatched
current_peak = peak_number - 1
while current_peak >= 0:
- if not frame_peaks[current_peak] in matched_peaks:
+ if not frame_peaks[current_peak].frequency in freqs:
return frame_peaks[current_peak]
current_peak -= 1
return None
@@ -218,12 +219,13 @@ class MQPartialTracking(simpl.PartialTracking):
with 0 amplitude.
"""
for peak_number, peak in enumerate(self._current_frame.partials):
- if peak == prev_peak:
+ if peak.frequency == prev_peak.frequency:
if peak.amplitude == 0:
partials[peak_number] = None
else:
- partials[peak_number] = simpl.Peak()
- partials[peak_number].frequency = prev_peak.frequency
+ p = simpl.Peak()
+ p.frequency = peak.frequency
+ partials[peak_number] = p
def _extend_partial(self, partials, prev_peak, next_peak):
"""
@@ -231,7 +233,7 @@ class MQPartialTracking(simpl.PartialTracking):
that currently ends with prev_peak.
"""
for peak_number, peak in enumerate(self._current_frame.partials):
- if peak == prev_peak:
+ if peak.frequency == prev_peak.frequency:
partials[peak_number] = next_peak
def update_partials(self, frame):
@@ -276,6 +278,7 @@ class MQPartialTracking(simpl.PartialTracking):
partials = frame.peaks
for i in range(len(frame.peaks), self.max_partials):
partials.append(simpl.Peak())
+ frame.partials = partials
return partials
for peak in self._current_frame.partials: