Created
January 4, 2015 23:51
-
-
Save RaD/926636196a50e9cf02aa to your computer and use it in GitHub Desktop.
Test framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from wavebender import * | |
| from itertools import * | |
| formanta = [0, 10, 19, 28, 36, 44, 50, 55, 60, 62, 64, 64, 62, 60, 55, 50, 44, | |
| 36, 28, 19, 10, 0, -10, -19, -28, -36, -44, -50, -55, -60, -62, | |
| -64, -64, -62, -60, -55, -50, -44, -36, -28, -19, -10] | |
| oberton = [0, 12, 23, 32, 38, 41, 42, 42, 42, 40, 38, 36, 34, 32, 30, 28, 26, | |
| 24, 22, 20, 18, 16, 15, 13, 12, 10, 9, 7, 6, 4, 3, 1, 0, -1, -3, -4, | |
| -6, -7, -9, -10, -12, -13] | |
| formanta_init_amp = 180 | |
| oberton_init_amp = 200 | |
| formanta_fade_step = 200 | |
| oberton_fade_step = 150 | |
| def fastmul(a, b): | |
| return (a * b) >> 8 | |
| def bell_wave(): | |
| pos = f_step = o_step = f_amp = o_amp = 0 | |
| period = len(formanta) | |
| while True: | |
| if 0 == f_step: | |
| f_step = formanta_fade_step | |
| if 0 == f_amp: | |
| f_amp = formanta_init_amp | |
| o_amp = oberton_init_amp | |
| o_step = oberton_fade_step | |
| pos = 0 | |
| else: | |
| f_amp -= 1 | |
| else: | |
| f_step -= 1 | |
| if 0 == o_step: | |
| o_step = oberton_fade_step | |
| if 0 < o_amp: | |
| o_amp -= 1 | |
| else: | |
| o_step -= 1 | |
| sample = 128 + \ | |
| fastmul(formanta[pos], f_amp) + \ | |
| fastmul(oberton[pos], o_amp) | |
| yield sample | |
| pos = (pos + 1) % period | |
| channels = ((bell_wave(),),) | |
| samples = compute_samples(channels, None) | |
| write_wavefile(sys.stdout, samples, None, | |
| nchannels=1, sampwidth=1, framerate=9600000/256/4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment