diff --git a/tests/test_AudioClips.py b/tests/test_AudioClips.py index fe5dd4e70..40e0ce2d7 100644 --- a/tests/test_AudioClips.py +++ b/tests/test_AudioClips.py @@ -14,12 +14,11 @@ from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.utils import close_all_clips -from tests.test_helper import TMP_DIR +from tests.test_helper import TMP_DIR, get_mono_wave, get_stereo_wave def test_audioclip(): - make_frame = lambda t: [np.sin(440 * 2 * np.pi * t)] - audio = AudioClip(make_frame, duration=2, fps=22050) + audio = AudioClip(get_mono_wave(440), duration=2, fps=22050) audio.write_audiofile(os.path.join(TMP_DIR, "audioclip.mp3"), bitrate="16") assert os.path.exists(os.path.join(TMP_DIR, "audioclip.mp3")) @@ -58,11 +57,8 @@ def test_concatenate_audioclips_render(): """Concatenated AudioClips through ``concatenate_audioclips`` should return a clip that can be rendered to a file. """ - make_frame_440 = lambda t: [np.sin(440 * 2 * np.pi * t)] - make_frame_880 = lambda t: [np.sin(880 * 2 * np.pi * t)] - - clip_440 = AudioClip(make_frame_440, duration=0.01, fps=44100) - clip_880 = AudioClip(make_frame_880, duration=0.000001, fps=22050) + clip_440 = AudioClip(get_mono_wave(440), duration=0.01, fps=44100) + clip_880 = AudioClip(get_mono_wave(880), duration=0.000001, fps=22050) concat_clip = concatenate_audioclips((clip_440, clip_880)) concat_clip.write_audiofile(os.path.join(TMP_DIR, "concatenate_audioclips.mp3")) @@ -154,12 +150,11 @@ def test_CompositeAudioClip_by__init__(): def test_concatenate_audioclip_with_audiofileclip(): - # stereo A note - make_frame = lambda t: np.array( - [np.sin(440 * 2 * np.pi * t), np.sin(880 * 2 * np.pi * t)] - ).T - - clip1 = AudioClip(make_frame, duration=1, fps=44100) + clip1 = AudioClip( + get_stereo_wave(left_freq=440, right_freq=880), + duration=1, + fps=44100, + ) clip2 = AudioFileClip("media/crunching.mp3") concat_clip = concatenate_audioclips((clip1, clip2)) @@ -185,9 +180,7 @@ def test_concatenate_audiofileclips(): def test_audioclip_mono_max_volume(): - # mono - make_frame_440 = lambda t: np.sin(440 * 2 * np.pi * t) - clip = AudioClip(make_frame_440, duration=1, fps=44100) + clip = AudioClip(get_mono_wave(440), duration=1, fps=44100) max_volume = clip.max_volume() assert isinstance(max_volume, float) assert max_volume > 0 diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py index 9c866f3ee..a5e7116a5 100644 --- a/tests/test_ffmpeg_reader.py +++ b/tests/test_ffmpeg_reader.py @@ -17,7 +17,7 @@ from moviepy.video.io.VideoFileClip import VideoFileClip from moviepy.video.VideoClip import BitmapClip -from tests.test_helper import TMP_DIR +from tests.test_helper import TMP_DIR, get_mono_wave def test_ffmpeg_parse_infos(): @@ -107,19 +107,8 @@ def test_ffmpeg_parse_infos_multiple_audio_streams(): TMP_DIR, "ffmpeg_parse_infos_multiple_streams.mp4" ) - make_frame_440 = lambda t: np.array( - [ - np.sin(440 * 2 * np.pi * t), - ] - ) - make_frame_880 = lambda t: np.array( - [ - np.sin(880 * 2 * np.pi * t), - ] - ) - - clip_440 = AudioClip(make_frame_440, fps=22050, duration=0.01) - clip_880 = AudioClip(make_frame_880, fps=22050, duration=0.01) + clip_440 = AudioClip(get_mono_wave(440), fps=22050, duration=0.01) + clip_880 = AudioClip(get_mono_wave(880), fps=22050, duration=0.01) clip_440.write_audiofile(clip_440_filepath) clip_880.write_audiofile(clip_880_filepath) @@ -177,9 +166,7 @@ def test_ffmpeg_parse_infos_metadata(): os.remove(filepath) # create video with 2 streams, video and audio - audioclip = AudioClip( - lambda t: np.sin(440 * 2 * np.pi * t), fps=22050 - ).with_duration(1) + audioclip = AudioClip(get_mono_wave(440), fps=22050).with_duration(1) videoclip = BitmapClip([["RGB"]], fps=1).with_duration(1).with_audio(audioclip) # build metadata key-value pairs which will be passed to ``ffmpeg_params`` diff --git a/tests/test_fx.py b/tests/test_fx.py index 66c642c14..cf35a9192 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -52,7 +52,7 @@ time_symmetrize, ) -from tests.test_helper import TMP_DIR, get_test_video +from tests.test_helper import TMP_DIR, get_mono_wave, get_stereo_wave, get_test_video def test_accel_decel(): @@ -1473,13 +1473,12 @@ def test_audio_delay(duration, offset, n_repeats, decay): assert duration <= offset # avoid wave distorsion assert not offset * 1000000 % 2 # odd offset -> no accurate muted chunk size - # stereo A note - make_frame = lambda t: np.array( - [np.sin(440 * 2 * np.pi * t), np.sin(880 * 2 * np.pi * t)] - ).T.copy(order="C") - # stereo audio clip - clip = AudioClip(make_frame=make_frame, duration=duration, fps=44100) + clip = AudioClip( + make_frame=get_stereo_wave(left_freq=440, right_freq=880), + duration=duration, + fps=44100, + ) clip_array = clip.to_soundarray() # stereo delayed clip @@ -1547,11 +1546,9 @@ def test_audio_delay(duration, offset, n_repeats, decay): ) def test_audio_fadein(sound_type, fps, clip_duration, fadein_duration): if sound_type == "stereo": - make_frame = lambda t: np.array( - [np.sin(440 * 2 * np.pi * t), np.sin(160 * 2 * np.pi * t)] - ).T.copy(order="C") + make_frame = get_stereo_wave(left_freq=440, right_freq=160) else: - make_frame = lambda t: np.sin(440 * 2 * np.pi * t) + make_frame = get_mono_wave(440) clip = AudioClip(make_frame, duration=clip_duration, fps=fps) new_clip = audio_fadein(clip, fadein_duration) @@ -1608,11 +1605,9 @@ def test_audio_fadein(sound_type, fps, clip_duration, fadein_duration): ) def test_audio_fadeout(sound_type, fps, clip_duration, fadeout_duration): if sound_type == "stereo": - make_frame = lambda t: np.array( - [np.sin(440 * 2 * np.pi * t), np.sin(160 * 2 * np.pi * t)] - ).T.copy(order="C") + make_frame = get_stereo_wave(left_freq=440, right_freq=160) else: - make_frame = lambda t: np.sin(440 * 2 * np.pi * t) + make_frame = get_mono_wave(440) clip = AudioClip(make_frame, duration=clip_duration, fps=fps) new_clip = audio_fadeout(clip, fadeout_duration)