forked from rpuntaie/syncstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_syncstart.py
104 lines (91 loc) · 2.11 KB
/
test_syncstart.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
"""
Tests for `syncstart` package.
"""
import pytest
from syncstart import *
from scipy.io import wavfile
import numpy as np
def to_files(fs,s1,s2,p):
wav1 = p / "wav1.wav"
wav2 = p / "wav2.wav"
wavfile.write(wav1, fs, s1.astype(np.int16))
wavfile.write(wav2, fs, s2.astype(np.int16))
return (wav1,wav2)
@pytest.fixture
def rndwav(tmp_path):
rng = np.random.RandomState(0)
fs = 32000
s1 = rng.standard_normal(fs)
s2 = np.concatenate([rng.standard_normal(fs//2), s1])
return to_files(fs,s1,s2,tmp_path)
def test_rnd0(rndwav):
file,offset = file_offset(
in1=rndwav[1]
,in2=rndwav[0]
,take=1.5
,normalize=False
,denoise=False
,lowpass=0
,show=False
)
assert offset==0.5 and file==rndwav[1]
def test_rnd1(rndwav):
file,offset = file_offset(
in1=rndwav[0]
,in2=rndwav[1]
,take=1.5
,normalize=False
,denoise=False
,lowpass=0
,show=False
)
assert offset==0.5 and file==rndwav[1]
def test_rnd00(rndwav):
file,offset = file_offset(
in1=rndwav[0]
,in2=rndwav[0]
,take=1.5
,normalize=False
,denoise=False
,lowpass=0
,show=False
)
assert offset==0.0 and file==rndwav[0]
def test_rnd11(rndwav):
file,offset = file_offset(
in1=rndwav[1]
,in2=rndwav[1]
,take=1.5
,normalize=False
,denoise=False
,lowpass=0
,show=False
)
assert offset==0.0 and file==rndwav[1]
test_wav_offset = 2.3113832199546485
@pytest.fixture
def tstwav(tmp_path):
fs,s = wavfile.read('test.wav')
lens2 = len(s)//2
#lens2/fs # 2.3113832199546485
s1 = s
s2 = np.concatenate([s1[lens2:,:],s1])
#wavfile.write('test2.wav', fs, s2.astype(np.int16))
#mono:
#wavfile.write('test1.wav', fs, s[:,1].astype(np.int16))
return to_files(fs,s1,s2,tmp_path)
def test_tst0(tstwav):
file,offset = file_offset(
in1=tstwav[0]
,in2=tstwav[1]
,show=False
)
assert abs(offset-test_wav_offset)<0.001 and file==tstwav[1]
def test_tst1(tstwav):
file,offset = file_offset(
in1=tstwav[0]
,in2=tstwav[1]
,show=False
)
assert abs(offset-test_wav_offset)<0.001 and file==tstwav[1]