def main(): parser = get_cmd_line_parser(description=__doc__) parser = ParserArguments.filename(parser) parser = ParserArguments.plot(parser) parser = ParserArguments.framerate(parser) parser = ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate sig_gen = Generator(verbose=args.debug) print('0.2 second waveform at 1000Hz and 0.2 seconds at 440Hz ' '(starting 0.1 second in)') signal = Waveform([]) signal = signal.insert(0, sig_gen.sin_constant(1000, length=0.2)) signal = signal.insert(seconds_to_frame(0.1), sig_gen.sin_constant(440, length=0.2)) if args.plot: plot.plot_waveform(signal.frames, 1, 0, 4000) else: with wav_file_context('signal.wav') as fout: fout.write_frames(signal.frames) spectrum = analyze_whole_waveform(signal) print("Frequency Powers found by STFT: ") timeslices = [(time, spec) for time, spec in spectrum.items()] timeslices.sort(key=lambda x: x[0]) for timeslice in timeslices: print(timeslice) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) parser = ParserArguments.filename(parser) parser = ParserArguments.plot(parser) parser = ParserArguments.framerate(parser) parser = ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate sig_gen = Generator(verbose=args.debug) print('1 second waveform at 1000Hz') frequency_powers = analyze_window( sig_gen.sin_constant(1000)) print("Frequency Powers found by FFT: ", frequency_powers) print('\n0.5 second waveform at 880Hz') frequency_powers = analyze_window( sig_gen.sin_constant(880, length=0.5)) print("Frequency Powers found by FFT: ", frequency_powers) print('\n0.75 second waveform at 1234Hz') frequency_powers = analyze_window( sig_gen.sin_constant(1234, length=0.75)) tmp = list(frequency_powers.items()) tmp.sort(key=lambda x: x[1], reverse=True) print('{} present non-zero frequencies in signal. The most ' 'powerfull frequencies are:\n{}'.format( len(frequency_powers), '\n'.join([str(t) for t in tmp[:10]]))) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) parser = ParserArguments.filename(parser) parser = ParserArguments.plot(parser) parser = ParserArguments.framerate(parser) parser = ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate sig_gen = Generator(verbose=args.debug) print('1 second waveform at 1000Hz') frequency_powers = analyze_window(sig_gen.sin_constant(1000)) print("Frequency Powers found by FFT: ", frequency_powers) print('\n0.5 second waveform at 880Hz') frequency_powers = analyze_window(sig_gen.sin_constant(880, length=0.5)) print("Frequency Powers found by FFT: ", frequency_powers) print('\n0.75 second waveform at 1234Hz') frequency_powers = analyze_window(sig_gen.sin_constant(1234, length=0.75)) tmp = list(frequency_powers.items()) tmp.sort(key=lambda x: x[1], reverse=True) print('{} present non-zero frequencies in signal. The most ' 'powerfull frequencies are:\n{}'.format( len(frequency_powers), '\n'.join([str(t) for t in tmp[:10]]))) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.tempo(parser) ParserArguments.framerate(parser) ParserArguments.set_defaults(parser) ParserArguments.best(parser) args = parser.parse_args() defaults.framerate = args.framerate song = Stream() roots = 'ABCDEFG' scales = [scale.MajorScale, scale.MinorScale, scale.WholeToneScale, scale.ChromaticScale] print('Choosing a random scale from Major, Minor, Whole Tone, Chromatic.') rscale = random.choice(scales)(Pitch(random.choice(roots))) print('Using: %s' % rscale.name) print('Generating a score...') random_note_count = 50 random_note_speeds = [0.5, 1] print('100 Random 1/8th and 1/4th notes in rapid succession...') for i in range(random_note_count): note = Note(random.choice(rscale.pitches)) note.duration.quarterLength = random.choice(random_note_speeds) song.append(note) scale_practice_count = 4 print('Do the scale up and down a few times... maybe %s' % scale_practice_count) rev = rscale.pitches[:] rev.reverse() updown_scale = rscale.pitches[:] updown_scale.extend(rev[1:-1]) print('updown scale: %s' % updown_scale) for count, pitch in enumerate(cycle(updown_scale)): print(' note %s, %s' % (count, pitch)) song.append(Note(pitch)) if count >= scale_practice_count * len(updown_scale): break print('Composition finished:') song.show('txt') if args.best: print('Audifying the song to file "{}"...') wave = audify_to_file(song, args.tempo, args.filename, verbose=True) else: wave = audify_basic(song, args.tempo, verbose=True) print('Writing Song to file "{}"...'.format(args.filename)) with wav_file_context(args.filename) as fout: fout.write_frames(wave.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.tempo(parser) ParserArguments.framerate(parser) ParserArguments.set_defaults(parser) ParserArguments.best(parser) args = parser.parse_args() defaults.framerate = args.framerate print('Generating Signal:') sig_gen = Generator() song = Waveform([]) qnl = quarter_note_length(args.tempo) # work = corpus.parse(numpy.random.choice(corpus.getComposer('bach'))) work = corpus.parse(numpy.random.choice(corpus.getCorePaths())) notes = work.flat.notes if args.best: audify_to_file(notes, args.tempo, args.filename, args.verbose) return 0 note_count = len(notes) try: for count, note in enumerate(notes): print('{}/{}: {} [{}]: {} {}'.format(count, note_count, note.offset, note.duration.quarterLength, note.pitch, note.pitch.frequency)) note_length = qnl * note.quarterLength start = seconds_to_frame(qnl * note.offset) print(' inserting {} seconds into frame {}'.format( note_length, start)) song = song.insert( start, sig_gen.sin_constant(note.pitch.frequency, length=note_length)) except KeyboardInterrupt: print('Stopping song generating here...') print('Writing Song {} to file {}...'.format(work.corpusFilepath, args.filename)) with wav_file_context(args.filename) as fout: fout.write_frames(song.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) parser = ParserArguments.filename(parser) parser = ParserArguments.plot(parser) parser = ParserArguments.framerate(parser) parser = ParserArguments.set_defaults(parser) parser.add_argument('--phase', help="Run the experiment with a given phase value.", type=float, default=0.0) args = parser.parse_args() defaults.framerate = args.framerate sig_gen = Generator(verbose=args.debug) phase = 0 if not hasattr(args, 'phase') else args.phase signal = sig_gen.sin_constant(440, length=0.05, phase=phase % (2 * pi)) freq, power_domain, freq_domain = do_fft(signal) try: _, subplots = pyplot.subplots(1, 2) subplots[0].plot(power_domain) subplots[0].set_title('Power Domain') subplots[1].plot(freq_domain) subplots[1].set_title('Freq Domain') pyplot.show() _, subplots = pyplot.subplots(1, 2) subplots[0].plot(real(freq_domain)) subplots[0].set_title('Real Freq. Domain') subplots[1].plot(imag(freq_domain)) subplots[1].set_title('Imaginary Freq. Domain') pyplot.show() finally: pyplot.close() return 0
def main(): parser = get_cmd_line_parser(description=__doc__) parser = ParserArguments.filename(parser) parser = ParserArguments.plot(parser) parser = ParserArguments.framerate(parser) parser = ParserArguments.set_defaults(parser) parser.add_argument( '--phase', help="Run the experiment with a given phase value.", type=float, default=0.0) args = parser.parse_args() defaults.framerate = args.framerate sig_gen = Generator(verbose=args.debug) phase = 0 if not hasattr(args, 'phase') else args.phase signal = sig_gen.sin_constant(440, length=0.05, phase=phase % (2 * pi)) freq, power_domain, freq_domain = do_fft(signal) try: _, subplots = pyplot.subplots(1, 2) subplots[0].plot(power_domain) subplots[0].set_title('Power Domain') subplots[1].plot(freq_domain) subplots[1].set_title('Freq Domain') pyplot.show() _, subplots = pyplot.subplots(1, 2) subplots[0].plot(real(freq_domain)) subplots[0].set_title('Real Freq. Domain') subplots[1].plot(imag(freq_domain)) subplots[1].set_title('Imaginary Freq. Domain') pyplot.show() finally: pyplot.close() return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.tempo(parser) ParserArguments.framerate(parser) parser.add_argument('-r', '--repo', help='The git repository to use.') ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate repo_data = scrape_repository_data(args.repo) song = compose_repository_song(repo_data) notes = song.flat.notes waveform = audify(notes, args.tempo, args.verbose) with wav_file_context(args.filename) as fout: fout.write_frames(waveform.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.length(parser) ParserArguments.modify_argument(parser, 'length', 'help', 'Length per pitch clip.') ParserArguments.set_defaults(parser, length=0.75) args = parser.parse_args() sg = Generator(length=args.length / 2.0, verbose=args.debug) with wav_file_context(args.filename) as fout: for tone, temperament in itertools.product( range(Interval.max() + 1), Temperament.iter()): key = Key(temperament=temperament) waveform = sg.sin_constant(key.interval(tone)) fout.write_frames(waveform.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.length(parser) ParserArguments.modify_argument(parser, 'length', 'help', 'Length per pitch clip.') ParserArguments.set_defaults(parser, length=0.75) args = parser.parse_args() sg = Generator(length=args.length / 2.0, verbose=args.debug) with wav_file_context(args.filename) as fout: for tone, temperament in itertools.product(range(Interval.max() + 1), Temperament.iter()): key = Key(temperament=temperament) waveform = sg.sin_constant(key.interval(tone)) fout.write_frames(waveform.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.tempo(parser) ParserArguments.framerate(parser) ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate print('Generating Signal:') work = corpus.parse(numpy.random.choice(corpus.getCorePaths())) notes = work.flat.notes waveform = audify(notes, args.tempo, args.verbose) print('Writing Song {} to file {}...'.format(work.corpusFilepath, args.filename)) with wav_file_context(args.filename) as fout: fout.write_frames(waveform.frames) return 0
def main(): parser = get_cmd_line_parser(description=__doc__) ParserArguments.filename(parser) ParserArguments.tempo(parser) ParserArguments.framerate(parser) ParserArguments.set_defaults(parser) args = parser.parse_args() defaults.framerate = args.framerate print('Generating Signal:') work = corpus.parse(numpy.random.choice(corpus.getCorePaths())) notes = work.flat.notes waveform = audify(notes, args.tempo, args.verbose) print('Writing Song {} to file {}...'.format( work.corpusFilepath, args.filename)) with wav_file_context(args.filename) as fout: fout.write_frames(waveform.frames) return 0