Skip to content

Commit 8deb079

Browse files
committed
Add tests
1 parent 70ac31e commit 8deb079

File tree

6 files changed

+484
-0
lines changed

6 files changed

+484
-0
lines changed

test/decoders/test_ops.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
NASA_AUDIO_MP3,
4545
NASA_VIDEO,
4646
needs_cuda,
47+
SINE_MONO_S32,
48+
SINE_MONO_S32_44100,
49+
SINE_MONO_S32_8000,
4750
)
4851

4952
torch._dynamo.config.capture_dynamic_output_shape_ops = True
@@ -880,6 +883,37 @@ def test_decode_before_frame_start(self):
880883
# TODO fix this. `frames` should be empty.
881884
torch.testing.assert_close(frames, all_frames)
882885

886+
def test_sample_rate_conversion(self):
887+
def get_all_frames(asset, sample_rate=None):
888+
decoder = create_from_file(str(asset.path), seek_mode="approximate")
889+
add_audio_stream(decoder, sample_rate=sample_rate)
890+
frames, *_ = get_frames_by_pts_in_range_audio(
891+
decoder, start_seconds=0, stop_seconds=None
892+
)
893+
return frames
894+
895+
# Upsample
896+
assert SINE_MONO_S32_44100.sample_rate == 44_100
897+
frames_44100_native = get_all_frames(SINE_MONO_S32_44100)
898+
899+
assert SINE_MONO_S32.sample_rate == 16_000
900+
frames_upsampled_to_44100 = get_all_frames(SINE_MONO_S32, sample_rate=44_100)
901+
902+
torch.testing.assert_close(
903+
frames_upsampled_to_44100, frames_44100_native, atol=1e-4, rtol=1e-6
904+
)
905+
906+
# Downsample
907+
assert SINE_MONO_S32_8000.sample_rate == 8000
908+
frames_8000_native = get_all_frames(SINE_MONO_S32_8000)
909+
910+
assert SINE_MONO_S32.sample_rate == 16_000
911+
frames_downsampled_to_8000 = get_all_frames(SINE_MONO_S32, sample_rate=8000)
912+
913+
torch.testing.assert_close(
914+
frames_downsampled_to_8000, frames_8000_native, atol=1e-4, rtol=1e-6
915+
)
916+
883917

884918
if __name__ == "__main__":
885919
pytest.main()
345 KB
Binary file not shown.
Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
[
2+
{
3+
"duration_time": "0.046440",
4+
"pts_time": "0.000000"
5+
},
6+
{
7+
"duration_time": "0.046440",
8+
"pts_time": "0.046440"
9+
},
10+
{
11+
"duration_time": "0.046440",
12+
"pts_time": "0.092880"
13+
},
14+
{
15+
"duration_time": "0.046440",
16+
"pts_time": "0.139320"
17+
},
18+
{
19+
"duration_time": "0.046440",
20+
"pts_time": "0.185760"
21+
},
22+
{
23+
"duration_time": "0.046440",
24+
"pts_time": "0.232200"
25+
},
26+
{
27+
"duration_time": "0.046440",
28+
"pts_time": "0.278639"
29+
},
30+
{
31+
"duration_time": "0.046440",
32+
"pts_time": "0.325079"
33+
},
34+
{
35+
"duration_time": "0.046440",
36+
"pts_time": "0.371519"
37+
},
38+
{
39+
"duration_time": "0.046440",
40+
"pts_time": "0.417959"
41+
},
42+
{
43+
"duration_time": "0.046440",
44+
"pts_time": "0.464399"
45+
},
46+
{
47+
"duration_time": "0.046440",
48+
"pts_time": "0.510839"
49+
},
50+
{
51+
"duration_time": "0.046440",
52+
"pts_time": "0.557279"
53+
},
54+
{
55+
"duration_time": "0.046440",
56+
"pts_time": "0.603719"
57+
},
58+
{
59+
"duration_time": "0.046440",
60+
"pts_time": "0.650159"
61+
},
62+
{
63+
"duration_time": "0.046440",
64+
"pts_time": "0.696599"
65+
},
66+
{
67+
"duration_time": "0.046440",
68+
"pts_time": "0.743039"
69+
},
70+
{
71+
"duration_time": "0.046440",
72+
"pts_time": "0.789478"
73+
},
74+
{
75+
"duration_time": "0.046440",
76+
"pts_time": "0.835918"
77+
},
78+
{
79+
"duration_time": "0.046440",
80+
"pts_time": "0.882358"
81+
},
82+
{
83+
"duration_time": "0.046440",
84+
"pts_time": "0.928798"
85+
},
86+
{
87+
"duration_time": "0.046440",
88+
"pts_time": "0.975238"
89+
},
90+
{
91+
"duration_time": "0.046440",
92+
"pts_time": "1.021678"
93+
},
94+
{
95+
"duration_time": "0.046440",
96+
"pts_time": "1.068118"
97+
},
98+
{
99+
"duration_time": "0.046440",
100+
"pts_time": "1.114558"
101+
},
102+
{
103+
"duration_time": "0.046440",
104+
"pts_time": "1.160998"
105+
},
106+
{
107+
"duration_time": "0.046440",
108+
"pts_time": "1.207438"
109+
},
110+
{
111+
"duration_time": "0.046440",
112+
"pts_time": "1.253878"
113+
},
114+
{
115+
"duration_time": "0.046440",
116+
"pts_time": "1.300317"
117+
},
118+
{
119+
"duration_time": "0.046440",
120+
"pts_time": "1.346757"
121+
},
122+
{
123+
"duration_time": "0.046440",
124+
"pts_time": "1.393197"
125+
},
126+
{
127+
"duration_time": "0.046440",
128+
"pts_time": "1.439637"
129+
},
130+
{
131+
"duration_time": "0.046440",
132+
"pts_time": "1.486077"
133+
},
134+
{
135+
"duration_time": "0.046440",
136+
"pts_time": "1.532517"
137+
},
138+
{
139+
"duration_time": "0.046440",
140+
"pts_time": "1.578957"
141+
},
142+
{
143+
"duration_time": "0.046440",
144+
"pts_time": "1.625397"
145+
},
146+
{
147+
"duration_time": "0.046440",
148+
"pts_time": "1.671837"
149+
},
150+
{
151+
"duration_time": "0.046440",
152+
"pts_time": "1.718277"
153+
},
154+
{
155+
"duration_time": "0.046440",
156+
"pts_time": "1.764717"
157+
},
158+
{
159+
"duration_time": "0.046440",
160+
"pts_time": "1.811156"
161+
},
162+
{
163+
"duration_time": "0.046440",
164+
"pts_time": "1.857596"
165+
},
166+
{
167+
"duration_time": "0.046440",
168+
"pts_time": "1.904036"
169+
},
170+
{
171+
"duration_time": "0.046440",
172+
"pts_time": "1.950476"
173+
},
174+
{
175+
"duration_time": "0.046440",
176+
"pts_time": "1.996916"
177+
},
178+
{
179+
"duration_time": "0.046440",
180+
"pts_time": "2.043356"
181+
},
182+
{
183+
"duration_time": "0.046440",
184+
"pts_time": "2.089796"
185+
},
186+
{
187+
"duration_time": "0.046440",
188+
"pts_time": "2.136236"
189+
},
190+
{
191+
"duration_time": "0.046440",
192+
"pts_time": "2.182676"
193+
},
194+
{
195+
"duration_time": "0.046440",
196+
"pts_time": "2.229116"
197+
},
198+
{
199+
"duration_time": "0.046440",
200+
"pts_time": "2.275556"
201+
},
202+
{
203+
"duration_time": "0.046440",
204+
"pts_time": "2.321995"
205+
},
206+
{
207+
"duration_time": "0.046440",
208+
"pts_time": "2.368435"
209+
},
210+
{
211+
"duration_time": "0.046440",
212+
"pts_time": "2.414875"
213+
},
214+
{
215+
"duration_time": "0.046440",
216+
"pts_time": "2.461315"
217+
},
218+
{
219+
"duration_time": "0.046440",
220+
"pts_time": "2.507755"
221+
},
222+
{
223+
"duration_time": "0.046440",
224+
"pts_time": "2.554195"
225+
},
226+
{
227+
"duration_time": "0.046440",
228+
"pts_time": "2.600635"
229+
},
230+
{
231+
"duration_time": "0.046440",
232+
"pts_time": "2.647075"
233+
},
234+
{
235+
"duration_time": "0.046440",
236+
"pts_time": "2.693515"
237+
},
238+
{
239+
"duration_time": "0.046440",
240+
"pts_time": "2.739955"
241+
},
242+
{
243+
"duration_time": "0.046440",
244+
"pts_time": "2.786395"
245+
},
246+
{
247+
"duration_time": "0.046440",
248+
"pts_time": "2.832834"
249+
},
250+
{
251+
"duration_time": "0.046440",
252+
"pts_time": "2.879274"
253+
},
254+
{
255+
"duration_time": "0.046440",
256+
"pts_time": "2.925714"
257+
},
258+
{
259+
"duration_time": "0.046440",
260+
"pts_time": "2.972154"
261+
},
262+
{
263+
"duration_time": "0.046440",
264+
"pts_time": "3.018594"
265+
},
266+
{
267+
"duration_time": "0.046440",
268+
"pts_time": "3.065034"
269+
},
270+
{
271+
"duration_time": "0.046440",
272+
"pts_time": "3.111474"
273+
},
274+
{
275+
"duration_time": "0.046440",
276+
"pts_time": "3.157914"
277+
},
278+
{
279+
"duration_time": "0.046440",
280+
"pts_time": "3.204354"
281+
},
282+
{
283+
"duration_time": "0.046440",
284+
"pts_time": "3.250794"
285+
},
286+
{
287+
"duration_time": "0.046440",
288+
"pts_time": "3.297234"
289+
},
290+
{
291+
"duration_time": "0.046440",
292+
"pts_time": "3.343673"
293+
},
294+
{
295+
"duration_time": "0.046440",
296+
"pts_time": "3.390113"
297+
},
298+
{
299+
"duration_time": "0.046440",
300+
"pts_time": "3.436553"
301+
},
302+
{
303+
"duration_time": "0.046440",
304+
"pts_time": "3.482993"
305+
},
306+
{
307+
"duration_time": "0.046440",
308+
"pts_time": "3.529433"
309+
},
310+
{
311+
"duration_time": "0.046440",
312+
"pts_time": "3.575873"
313+
},
314+
{
315+
"duration_time": "0.046440",
316+
"pts_time": "3.622313"
317+
},
318+
{
319+
"duration_time": "0.046440",
320+
"pts_time": "3.668753"
321+
},
322+
{
323+
"duration_time": "0.046440",
324+
"pts_time": "3.715193"
325+
},
326+
{
327+
"duration_time": "0.046440",
328+
"pts_time": "3.761633"
329+
},
330+
{
331+
"duration_time": "0.046440",
332+
"pts_time": "3.808073"
333+
},
334+
{
335+
"duration_time": "0.046440",
336+
"pts_time": "3.854512"
337+
},
338+
{
339+
"duration_time": "0.046440",
340+
"pts_time": "3.900952"
341+
},
342+
{
343+
"duration_time": "0.046440",
344+
"pts_time": "3.947392"
345+
},
346+
{
347+
"duration_time": "0.006168",
348+
"pts_time": "3.993832"
349+
}
350+
]

test/resources/sine_mono_s32_8000.wav

62.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)