()
| 101 | |
| 102 | @attr("sanitizer_skip") |
| 103 | def test_decoded_vs_generated(): |
| 104 | pipeline = DecoderPipeline() |
| 105 | idx = 0 |
| 106 | for iter in range(1): |
| 107 | out = pipeline.run() |
| 108 | for i in range(len(out[0])): |
| 109 | plain = out[0].at(i) |
| 110 | res = out[1].at(i) |
| 111 | mix = out[2].at(i)[:, np.newaxis] |
| 112 | res_mix = out[3].at(i)[:, np.newaxis] |
| 113 | |
| 114 | ref_len = [0, 0, 0, 0] |
| 115 | ref_len[0] = lengths[idx] |
| 116 | ref_len[1] = lengths[idx] * rate1 / rates[idx] |
| 117 | ref_len[2] = lengths[idx] |
| 118 | ref_len[3] = lengths[idx] * rate2 / rates[idx] |
| 119 | |
| 120 | ref0 = generate_waveforms(ref_len[0], freqs[idx]) * 32767 |
| 121 | ref1 = generate_waveforms(ref_len[1], freqs[idx] * (rates[idx] / rate1)) * 32767 |
| 122 | ref2 = generate_waveforms(ref_len[2], freqs[idx]) * 32767 |
| 123 | ref2 = ref2.mean(axis=1, keepdims=1) |
| 124 | ref3 = generate_waveforms(ref_len[3], freqs[idx] * (rates[idx] / rate2)) |
| 125 | ref3 = ref3.mean(axis=1, keepdims=1) |
| 126 | |
| 127 | assert out[4].at(i) == rates[idx] |
| 128 | assert out[5].at(i) == rate1 |
| 129 | assert out[6].at(i) == rates[idx] |
| 130 | assert out[7].at(i) == rate2 |
| 131 | |
| 132 | # just reading - allow only for rounding |
| 133 | assert np.allclose(plain, ref0, rtol=0, atol=0.5) |
| 134 | # resampling - allow for 1e-3 dynamic range error |
| 135 | assert np.allclose(res, ref1, rtol=0, atol=32767 * 1e-3) |
| 136 | # downmixing - allow for 2 bits of error |
| 137 | # - one for quantization of channels, one for quantization of result |
| 138 | assert np.allclose(mix, ref2, rtol=0, atol=2) |
| 139 | # resampling with weird ratio - allow for 3e-3 dynamic range error |
| 140 | assert np.allclose(res_mix, ref3, rtol=0, atol=3e-3) |
| 141 | |
| 142 | rosa_in1 = plain.astype(np.float32) |
| 143 | rosa1 = rosa_resample(rosa_in1, rates[idx], rate1) |
| 144 | rosa_in3 = rosa_in1 / 32767 |
| 145 | rosa3 = rosa_resample(rosa_in3.mean(axis=1, keepdims=1), rates[idx], rate2) |
| 146 | |
| 147 | assert np.allclose(res, rosa1, rtol=0, atol=32767 * 1e-3) |
| 148 | assert np.allclose(res_mix, rosa3, rtol=0, atol=3e-3) |
| 149 | |
| 150 | idx = (idx + 1) % len(names) |
| 151 | |
| 152 | |
| 153 | batch_size_alias_test = 16 |
nothing calls this directly
no test coverage detected