Example #1
0
def test_save_mono_from_file(mono_sound, tmp_path):
    filename = tmp_path / "save_mono_from_file.wav"

    mono_sound.save(filename)
    assert filename.exists()

    resulting_sound = Sound.from_file(filename.as_posix())
    assert np.array_equal(resulting_sound.data, mono_sound.data)
Example #2
0
def test_save_mono_from_function(tmp_path):
    fps, frequency, volume = (44100, 110, 0.5)
    amplitude = np.iinfo(np.int16).max * volume

    def time_to_frame(t):
        return (np.sin(frequency * 2 * np.pi * t) * amplitude).astype(np.int16)

    mono_sound = Sound.from_datatimes(time_to_frame,
                                      fps=fps).with_duration(0.5)

    filename = tmp_path / "save_mono_from_function.wav"
    mono_sound.save(filename)
    assert filename.exists()

    resulting_sound = Sound.from_file(filename)
    assert np.array_equal(resulting_sound.data, mono_sound.data)
Example #3
0
def test_from_file_stereo(stereo_filepath):
    sound = Sound.from_file(stereo_filepath)

    assert sound.n_frames == 55216
    assert sound.n_bytes == 2
    assert sound.n_bits == 16
    assert sound.fps == 44100
    assert sound.n_channels == 2
    assert sound.dtype is np.int16

    assert sound.time_to_frame is None
    assert sound.filename == stereo_filepath.encode("utf-8")
    assert isinstance(sound.f, snd.PySndfile)

    assert isinstance(sound.metadata, dict)
    assert sound.metadata["SF_STR_TITLE"] == b"Bass Drum 1"
    assert sound.metadata["SF_STR_ARTIST"] == b"freewavesamples.com"
    assert sound.metadata["SF_STR_DATE"] == b"2015"
Example #4
0
def test_from_file_mono(mono_filepath):
    sound = Sound.from_file(mono_filepath)

    assert sound.n_frames == 106022
    assert sound.n_bytes == 2
    assert sound.n_bits == 16
    assert sound.fps == 44100
    assert sound.n_channels == 1
    assert sound.dtype is np.int16

    assert sound.time_to_frame is None
    assert sound.filename == mono_filepath.encode("utf-8")
    assert isinstance(sound.f, snd.PySndfile)

    assert isinstance(sound.metadata, dict)
    assert sound.metadata["SF_STR_SOFTWARE"] == (
        b"Adobe Soundbooth CS5 (XMPDocOpsTemporal:2008.08.26)")
    assert sound.metadata["SF_STR_ARTIST"] == b"freewavesamples.com"
    assert sound.metadata["SF_STR_DATE"] == b"2015-05-06T19:28:12-07:00"
Example #5
0
def test_save_stereo_from_function(tmp_path):
    fps, frequencies, volume = (44100, (110, 440), 0.5)
    amplitude = np.iinfo(np.int16).max * volume

    time_to_frame_left = lambda t: (np.sin(frequencies[0] * 2 * np.pi * t) *
                                    amplitude).astype(np.int16)

    time_to_frame_right = lambda t: (np.sin(frequencies[1] * 2 * np.pi * t) *
                                     amplitude).astype(np.int16)

    stereo_sound = Sound.from_datatimes(
        lambda t: [time_to_frame_left(t),
                   time_to_frame_right(t)], fps=fps).with_duration(0.5)

    filename = tmp_path / "save_stereo_from_function.wav"
    stereo_sound.save(filename)
    assert filename.exists()

    resulting_sound = Sound.from_file(filename)
    assert np.array_equal(resulting_sound.data, stereo_sound.data)
Example #6
0
def stereo_sound(stereo_filepath):
    return Sound.from_file(stereo_filepath)
Example #7
0
def mono_sound(mono_filepath):
    return Sound.from_file(mono_filepath)