Example #1
0
def main():

    if len(sys.argv) < 3:
        sys.exit("Usage: python main.py <input .wav file name> <output .wav file name>")

    _, input_filename, output_filename = sys.argv

    pcm_audio = PcmAudio.from_wave_file(input_filename)
    synthesized_pcm_audio = resynthesize(pcm_audio)
    synthesized_pcm_audio.to_wave_file(output_filename)
Example #2
0
def resynthesize(reference_pcm_audio):

    Spectrogram(reference_pcm_audio.samples).to_tga_file(
        "reference_spectrogram.tga")

    algorithm = GeneticAlgorithm()

    best_score = None
    pcm_audio = None
    sounds = []

    if os.path.exists("base.wav"):
        print "Using 'base.wav' as a base sound for additive sythesis"
        pcm_audio = PcmAudio.from_wave_file("base.wav")

    for index in xrange(20):

        genome_factory = get_sound_factory(reference_pcm_audio, pcm_audio)
        population = Population(genome_factory, 80)
        best_sound = algorithm.run(population)

        if best_score is not None and best_sound.score < best_score:
            print "The algorithm failed to produce a better sound on this step"
            break

        print best_sound
        pcm_audio = best_sound.to_pcm_audio()
        pcm_audio.to_wave_file("debug%d.wav" % index)

        Spectrogram(pcm_audio.samples).to_tga_file()

        best_score = best_sound.score

        sounds.append(best_sound)

    construct_csound_file(sounds, pcm_audio)

    return pcm_audio