def write_chord(f, note_freq, sound_leveler):
    writer = Writer()
    synthesizer = Synthesizer(osc1_waveform=Waveform.sine,
                              osc1_volume=sound_leveler(note_freq),
                              use_osc2=False)
    wave = synthesizer.generate_chord([note_freq], 3.0)
    writer.write_wave(f, wave)
Beispiel #2
0
def test_write_wave():
    writer = Writer()

    synthesizer = Synthesizer(osc1_waveform=Waveform.sine,
                              osc1_volume=1.0,
                              use_osc2=False)
    wave = synthesizer.generate_constant_wave(440.0, 3.0)

    writer.write_wave("./test_wave.wav", wave)
    ok_("write_wave() succeeded.")
    def save_melody(self, melody, bpm):
        """
        Saves the melody as WAV

        Saves each note individually and then concatenate then
        in a sigle WAV file

        Parameters
        ----------
        melody : Melody
            the melody that will be played
        bpm : int
            beats per minute that of the melody
        """

        writer = Writer()
        outfile = "melody.wav"
        next_note = "note.wav"
        data = []

        for note in melody.notes:
            sound = self.generate_waves(note, bpm)

            if note == melody.notes[0]:
                # Generates the first note
                writer.write_wave(outfile, sound)
                continue

            writer.write_wave(next_note, sound)

            infiles = [outfile, next_note]

            for infile in infiles:
                with wave.open(infile, 'rb') as w:
                    data.append([w.getparams(), w.readframes(w.getnframes())])

            self.append_note(outfile, data)

            # Deletes the note file
            os.remove(next_note)
Beispiel #4
0
def main():
    writer = Writer()

    print("write chord sequence")
    synthesizer = Synthesizer(osc1_waveform=Waveform.sine,
                              osc1_volume=1.0,
                              use_osc2=False)
    chord = [
        BASE * 2.0**(2 / 12.0), BASE * 2.0**(5 / 12.0), BASE * 2.0**(9 / 12.0),
        BASE * 2.0**(12 / 12.0)
    ]
    wave1 = synthesizer.generate_chord(chord, 1.0)
    chord = [
        BASE * 2.0**(2 / 12.0), BASE * 2.0**(7 / 12.0), BASE * 2.0**(11 / 12.0)
    ]
    wave2 = synthesizer.generate_chord(chord, 1.0)
    chord = [
        BASE, BASE * 2.0**(4 / 12.0), BASE * 2.0**(7 / 12.0),
        BASE * 2.0**(12 / 12.0)
    ]
    wave3 = synthesizer.generate_chord(chord, 1.0)

    writer.write_waves(os.path.join(DIR, "test.wav"), wave1, wave2, wave3)
Beispiel #5
0
def generate_wave_from_chord_objects(
    chords: List[object],
    filepath: str,
) -> None:
    synthesizer = Synthesizer(osc1_waveform=Waveform.triangle,
                              osc1_volume=1.0,
                              use_osc2=False)

    note_length: int = 2
    root_pitch: int = 3
    chord_waves: list = []
    for chord in chords:
        if type(chord) is list:
            for c in chord:
                notes: list = c.components_with_pitch(root_pitch=root_pitch)
                chord_waves.append(
                    synthesizer.generate_chord(notes,
                                               note_length / len(chord)))
        else:
            notes: list = chord.components_with_pitch(root_pitch=root_pitch)
            chord_waves.append(synthesizer.generate_chord(notes, note_length))
    writer = Writer()
    writer.write_waves(filepath, *chord_waves)
Beispiel #6
0
from synthesizer import Synthesizer, Waveform, Writer

# ここの説明は 音作り を参照
synth = Synthesizer(osc1_waveform=Waveform.sine,
                    osc1_volume=1.0,
                    use_osc2=False)
# 一定音程の波形を生成する
wave = synth.generate_constant_wave(frequency=440.0, length=1.0)
# オーディオファイル出力用クラス
writer = Writer()
writer.write_wave("sine.wav", wave)