Beispiel #1
0
def fitness(individual, target_features):
    """
        Fitness function based on features
        Computes the mean squared error between the feature
        vectors of two signals
    """
    pred_synth = synth.Synth(sr=sr)
    pred_params = individual_to_params(individual)
    pred_synth.set_parameters(**pred_params)

    pred_signal = pred_synth.get_sound_array()
    pred_features = extract_features(pred_signal)
    return np.mean(np.square(pred_features - target_features)),
Beispiel #2
0
 def __init__(self, seed=1337):
     super().__init__()
     self.synth = synth.Synth(sr=44100)
     self.r = random.Random(seed)
Beispiel #3
0
Licensed under the MIT license.

All text above must be included in any redistribution.
"""

import os
import parser
import sequencer
import synth
import adafruit_trellism4

trellis = adafruit_trellism4.TrellisM4Express(rotation=0)
trellis.pixels.brightness = 0.1
trellis.pixels.fill(0)

syn = synth.Synth()
seq = sequencer.Sequencer(syn)
p = parser.MidiParser()

voices = sorted([
    f.split('.')[0] for f in os.listdir('/samples')
    if f.endswith('.txt') and not f.startswith('.')
])
print('Voices found: ', voices)
tunes = sorted([
    f for f in os.listdir('/midi')
    if f.endswith('.mid') and not f.startswith('.')
])
print('Midi files found: ', tunes)

selected_voice = None
Beispiel #4
0
import synth as Synth
import numpy as np
import math
import threading
import pyaudio

note_data = json.loads(open('./notes.json').read())

midi_to_note = {}
for note in note_data:
    midi_to_note[note_data[note]['midi']] = note

mid = mido.MidiFile('./midi/DancingQueen.mid')

output_io = pyaudio.PyAudio()
S = Synth.Synth(output_io)

for i, msg in enumerate(mid.play()):

    try:
        midnote = msg.note
        _type = msg.type
        duration = msg.time
        velocity = msg.velocity

        if midnote not in midi_to_note:
            continue
        freq = note_data[midi_to_note[midnote]]['frequency']

        if msg.type == 'note_on':
            S.play(freq)