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.")
Beispiel #3
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 #4
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)
    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 #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)
import synthesizer
from synthesizer import Writer, Synthesizer, Waveform
synthesizer = Synthesizer(osc1_waveform=Waveform.sine,
                          osc1_volume=1.0,
                          use_osc2=False)
writer = Writer()
start = 130.81
mul = [0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23]
for i in range(len(mul)):
    note = 196 * 2**(mul[i] / 12)
    wave = synthesizer.generate_chord([note * 0.5, note], 0.5)
    writer.write_wave("./sounds/short/" + str(i) + ".wav", wave)
    wave = synthesizer.generate_chord([note * 0.5, note], 4)
    writer.write_wave("./sounds/long/" + str(i) + ".wav", wave)
Beispiel #8
0
# https://github.com/yuma-m/synthesizer
from synthesizer import Synthesizer, Waveform, Writer

writer = Writer()
synthesizer = Synthesizer(osc1_waveform=Waveform.sine,
                          osc1_volume=1.0,
                          use_osc2=False)

chord = [261.626, 329.628, 391.996]
writer.write_wave("../audio/output/synthtest.wav",
                  synthesizer.generate_chord(chord, 5.0))
from synthesizer import Synthesizer, Waveform, Writer

synth = Synthesizer(osc1_waveform=Waveform.square,
                    osc1_volume=1.0 * 0.5,
                    use_osc2=False)
writer = Writer()

wave = synth.generate_constant_wave(frequency=440.0, length=0.1)
writer.write_wave("A.wav", wave)
wave = synth.generate_constant_wave(frequency=349.228, length=0.1)
writer.write_wave("F.wav", wave)
wave = synth.generate_constant_wave(frequency=391.995, length=0.1)
writer.write_wave("G.wav", wave)
Beispiel #10
0
from synthesizer import Synthesizer, Waveform, Writer

from pychodelic.synthesis import available_synthesizers, get_synthesizer_by_waveform_type, sheet_to_wave

parser = argparse.ArgumentParser(
    description="Synthesize a given sheet music (in txt format)")

parser.add_argument(
    "sheet",
    type=str,
    help="Path for the sheet music containing instructions for the synthesizer."
)
parser.add_argument(
    "type",
    type=str,
    help="Type of the main waveform of the synthesizer to use: %s." %
    str(available_synthesizers))
parser.add_argument("output", type=str, help="Where to save the composition.")

args = parser.parse_args()

if args.type not in available_synthesizers:
    raise ValueError("Unknown synthesizer type.")

synthesizer = get_synthesizer_by_waveform_type(args.type)

composition = sheet_to_wave(args.sheet, synthesizer)

writer = Writer()
writer.write_wave(args.output, composition)
Beispiel #11
0
synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False)

# Play A4
player.play_wave(synthesizer.generate_constant_wave(440.0, 1.0))

# Play C major
chord = [261.626,  329.628, 391.996]
player.play_wave(synthesizer.generate_chord(chord, 1.0))

# Play exemplary "almost" chord
# C_4
chord = [270.000,  329.628, 370.000]
player.play_wave(synthesizer.generate_chord(chord, 2.0))

# write
writer = Writer()

chord = [170.000,  329.628, 570.000]
wave = synthesizer.generate_chord(chord, 3.0)
writer.write_wave("output_records/synth.wav", wave)

# # generate the sound of a full scale of notes
# scale_dict = scales.fit_frequencies(scales.full_scale)
# scale = [scale_dict[note] for note in scale_dict]
# scale.sort()
# wave = synthesizer.generate_chord(scale, 3.0)
# writer.write_wave("records/scales/full_scale.wav", wave)

# # generate the sound for C major pentatonic
# scale_dict = scales.fit_frequencies(scales.C_Major_pentatonic)
# scale = [scale_dict[note] for note in scale_dict]