def MiddleSide_test(): import numpy as np from ATK.Core import DoubleInPointerFilter, DoubleOutPointerFilter from ATK.Tools import DoubleMiddleSideFilter from numpy.testing import assert_almost_equal t = np.arange(1000, dtype=np.float64) input = np.sin(np.array((t, t)) * 1000 * 2 * np.pi / 48000) output = np.ascontiguousarray( np.zeros(2000, dtype=np.float64).reshape(2, -1)) inputfilter = DoubleInPointerFilter(input, False) msfilter = DoubleMiddleSideFilter() outputfilter = DoubleOutPointerFilter(output, False) inputfilter.output_sampling_rate = 48000 msfilter.input_sampling_rate = 48000 outputfilter.input_sampling_rate = 48000 msfilter.set_input_port(0, inputfilter, 0) msfilter.set_input_port(1, inputfilter, 1) outputfilter.set_input_port(0, msfilter, 0) outputfilter.set_input_port(1, msfilter, 1) outputfilter.process(1000) assert_almost_equal(input[0] * 2, output[0]) assert_almost_equal(0, output[1])
def MiddleSide_test(): import numpy as np from ATK.Core import DoubleInPointerFilter, DoubleOutPointerFilter from ATK.Tools import DoubleMiddleSideFilter from numpy.testing import assert_almost_equal t = np.arange(1000, dtype=np.float64) input = np.sin(np.array((t, t)) * 1000 * 2 * np.pi / 48000) output = np.ascontiguousarray(np.zeros(2000, dtype=np.float64).reshape(2, -1)) inputfilter = DoubleInPointerFilter(input, False) msfilter = DoubleMiddleSideFilter() outputfilter = DoubleOutPointerFilter(output, False) inputfilter.output_sampling_rate = 48000 msfilter.input_sampling_rate = 48000 outputfilter.input_sampling_rate = 48000 msfilter.set_input_port(0, inputfilter, 0) msfilter.set_input_port(1, inputfilter, 1) outputfilter.set_input_port(0, msfilter, 0) outputfilter.set_input_port(1, msfilter, 1) outputfilter.process(1000) assert_almost_equal(input[0]*2, output[0]) assert_almost_equal(0, output[1])
def filter(inputl, inputr): import numpy as np outputl = np.zeros(inputl.shape, dtype=np.float64) outputr = np.zeros(inputl.shape, dtype=np.float64) infilterL = DoubleInPointerFilter(inputl, False) infilterL.set_input_sampling_rate(sample_rate) infilterR = DoubleInPointerFilter(inputr, False) infilterR.set_input_sampling_rate(sample_rate) mssplitfilter = DoubleMiddleSideFilter() mssplitfilter.set_input_sampling_rate(sample_rate) mssplitfilter.set_input_port(0, infilterL, 0) mssplitfilter.set_input_port(1, infilterR, 0) adaptgainfilter = DoubleVolumeFilter(2) adaptgainfilter.set_input_sampling_rate(sample_rate) adaptgainfilter.set_input_port(0, mssplitfilter, 0) adaptgainfilter.set_input_port(1, mssplitfilter, 1) adaptgainfilter.set_volume(.5) powerfilter1 = DoublePowerFilter() powerfilter1.set_input_sampling_rate(sample_rate) powerfilter1.set_input_port(0, adaptgainfilter, 0) powerfilter1.set_memory(np.exp(-1/(sample_rate*.1e-3))) attackreleasefilter1 = DoubleAttackReleaseFilter() attackreleasefilter1.set_input_sampling_rate(sample_rate) attackreleasefilter1.set_input_port(0, powerfilter1, 0) attackreleasefilter1.set_attack(np.exp(-1/(sample_rate*1e-3))) attackreleasefilter1.set_release(np.exp(-1/(sample_rate*100e-3))) gainfilter1 = DoubleGainCompressorFilter() gainfilter1.set_input_sampling_rate(sample_rate) gainfilter1.set_input_port(0, attackreleasefilter1, 0) gainfilter1.set_threshold(thresholds) gainfilter1.set_ratio(ratios) gainfilter1.set_softness(1) applygainfilter = DoubleApplyGainFilter(2) applygainfilter.set_input_sampling_rate(sample_rate) applygainfilter.set_input_port(0, gainfilter1, 0) applygainfilter.set_input_port(1, mssplitfilter, 0) powerfilter2 = DoublePowerFilter(1) powerfilter2.set_input_sampling_rate(sample_rate) powerfilter2.set_input_port(0, adaptgainfilter, 1) powerfilter2.set_memory(np.exp(-1/(sample_rate*.1e-3))) attackreleasefilter2 = DoubleAttackReleaseFilter() attackreleasefilter2.set_input_sampling_rate(sample_rate) attackreleasefilter2.set_input_port(0, powerfilter1, 0) attackreleasefilter2.set_attack(np.exp(-1/(sample_rate*1e-3))) attackreleasefilter2.set_release(np.exp(-1/(sample_rate*100e-3))) gainfilter2 = DoubleGainCompressorFilter() gainfilter2.set_input_sampling_rate(sample_rate) gainfilter2.set_input_port(0, attackreleasefilter2, 0) gainfilter2.set_threshold(thresholds) gainfilter2.set_ratio(ratios) gainfilter2.set_softness(1) applygainfilter.set_input_port(2, gainfilter2, 0) applygainfilter.set_input_port(3, mssplitfilter, 1) msmergefilter = DoubleMiddleSideFilter() msmergefilter.set_input_sampling_rate(sample_rate) msmergefilter.set_input_port(0, applygainfilter, 0) msmergefilter.set_input_port(1, applygainfilter, 1) volumefilter = DoubleVolumeFilter(2) volumefilter.set_input_sampling_rate(sample_rate) volumefilter.set_volume(.5) volumefilter.set_input_port(0, msmergefilter, 0) volumefilter.set_input_port(1, msmergefilter, 1) outfilterl = DoubleOutPointerFilter(outputl, False) outfilterl.set_input_sampling_rate(sample_rate) outfilterl.set_input_port(0, volumefilter, 0) outfilterr = DoubleOutPointerFilter(outputr, False) outfilterr.set_input_sampling_rate(sample_rate) outfilterr.set_input_port(0, volumefilter, 1) pipelineend = PipelineGlobalSinkFilter() pipelineend.set_input_sampling_rate(sample_rate) pipelineend.add_filter(outfilterl) pipelineend.add_filter(outfilterr) pipelineend.process(inputl.shape[1]) return outputl, outputr