Skip to content

Commit

Permalink
test vamp
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellkammer committed Feb 18, 2024
1 parent b4ba111 commit b67187a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion maelzel/snd/sndfiletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ def maxPeak(filename: str, start: float = 0, end: float = 0, resolution=0.01
maximum_peak = 0
max_pos = 0
info = sndfileio.sndinfo(filename)
for data, pos in readChunks(filename, start=start, end=end, chunksize=int(info.sr*resolution)):
chunksize = int(info.samplerate * resolution)
for data, pos in readChunks(filename, start=start, end=end, chunksize=chunksize):
np.abs(data, data)
peak = np.max(data)
if peak > maximum_peak:
Expand Down
2 changes: 1 addition & 1 deletion maelzel/snd/vamptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,4 @@ def pyinSmoothPitch(samples: np.ndarray,
step_size=stepSize, parameters=params)
dt, freqs = result1['vector']
freqsarray = np.array(freqs, dtype=float)
return (dt, freqsarray)
return (float(dt), freqsarray)
Binary file removed maelzel/test/snd/finneganswake.wav
Binary file not shown.
18 changes: 0 additions & 18 deletions maelzel/test/test_soundfiletools.py

This file was deleted.

File renamed without changes.
Binary file added test/snd/finneganswake-fragm.wav
Binary file not shown.
Binary file added test/snd/finneganswake.flac
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added test/snd/tuning-fork--A4--44100.flac
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
import sys


def testvamp():
print("Testing included vamp plugins")
import sndfileio
import numpy as np
samples, sr = sndfileio.sndread("snd/sine440.flac")
dur = len(samples) / sr
from maelzel.snd import vamptools
print(" Testing pyin")
assert vamptools.pyinAvailable()
arr = vamptools.pyinPitchTrack(samples=samples, sr=sr)
for row in arr:
print(f"time={row[0]:.3f}, freq: {row[1]:.3f} Hz, voiced: {row[2]:.3f}")


exiterr = 0
errors = dependencies.checkDependencies(fix=True)
if errors:
Expand All @@ -18,6 +32,9 @@
print(f"lilypond binary: {lily}")
print(f"lilypond version: {lilytools.getLilypondVersion()}")

testvamp()

dependencies.printReport()


sys.exit(exiterr)
20 changes: 20 additions & 0 deletions test/test-sndfiletools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from maelzel.snd import sndfiletools
import pitchtools as pt
import matplotlib.pyplot as plt
import time


def peakbpf():
peaks = sndfiletools.peakbpf("snd/finneganswake.wav", channel=1, resolution=0.05)
t, maxpeak = sndfiletools.maxPeak("snd/finneganswake.wav")
print(f"Max. peak: {maxpeak} at {t} seconds")
for t, peak in zip(*peaks.points()):
db = pt.amp2db(peak)
print(f"{t=:.3f}, {peak=:.4f} ({db:.1f} dB)")
peaks.plot()


if __name__ == "__main__":
peakbpf()
plt.show()

0 comments on commit b67187a

Please sign in to comment.