-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (68 loc) · 3.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
from pianokeyfreq import PianoNotes
if sys.platform != 'win32':
print('Currently only Windows is supported.')
exit()
import winsound
from samples import *
import tempfile
def play_freq(waves, secs, file=tempfile.mktemp()):
wav = write_wav(file, create_samples(waves, 44100 * secs), 44100 * secs)
winsound.PlaySound(wav, flags=winsound.SND_FILENAME)
def main():
# winsound.Beep(19950, 1000)
# winsound.PlaySound(sine_wave(64, 1/440, 44100, 16), flags=winsound.SND_MEMORY)
print('Main')
sinewave = sine_wave()
sinewave2 = sine_wave()
print("Sine wave:", list(itertools.islice(sinewave, 44100 // 440)))
print("Added waves:", list(itertools.islice(add_waves(sinewave, sinewave2), 44100 // 440)))
print("Mono:", len([list(i) for i in create_samples((sinewave,), 44100)]))
print("Stereo:", len([list(i) for i in create_samples((sinewave, sinewave), 44100)]))
# wav = write_wave(tempfile.mktemp(), create_samples((sinewave,), 44100), 44100)
# wav2 = write_wave(tempfile.mktemp(), create_samples((sine_wave(0.5, 130.8128),), 44100), 44100)
# winsound.PlaySound(wav, flags=winsound.SND_FILENAME)
# winsound.PlaySound(wav2, flags=winsound.SND_FILENAME)
# Play the C scale, starting from C3
# base = PianoNotes.C3.value
# x = 'TTSTTTS' # Major scale
# for i in range(8):
# wav = write_wave(tempfile.mktemp(),
# create_samples((triangle_wave(0.125, base), triangle_wave(0.125, base)), 44100), 44100)
# winsound.PlaySound(wav, flags=winsound.SND_FILENAME)
# if i == 7:
# continue
# if x[i] == 'T':
# base = one_tone_up(base)
# else:
# base = one_semitone_up(base)
# for i in range(6, -2, -1):
# wav = write_wave(tempfile.mktemp(), create_samples((sine_wave(0.25, base), sine_wave(0.25, base)), 44100),
# 44100)
# winsound.PlaySound(wav, flags=winsound.SND_FILENAME)
# if i == -1:
# continue
# if x[i] == 'T':
# base = one_tone_down(base)
# else:
# base = one_semitone_down(base)
# print('Playing Cmaj 3 seconds, merged with E4 for the first second, merged with C4 in the third second.')
# # Create Cmaj
cmaj = avg_waves(sine_wave(frequency=PianoNotes.C3.value), sine_wave(frequency=PianoNotes.E3.value),
sine_wave(frequency=PianoNotes.G2.value))
cmaj_sample = create_samples((cmaj,), 44100 * 3)
# Create E
e = sine_wave(frequency=PianoNotes.E4.value)
e_sample = create_samples((e,), 44100)
# Create C sample
c = sine_wave(frequency=PianoNotes.C4.value)
c_sample = create_samples((c,), 44100)
# Prepend 2 seconds of blank sound to the C sample
chained = add_delay(c_sample, 1, 2)
# Merge them all together
merged = merge_samples((cmaj_sample, e_sample, chained), 1)
# Create WAV file and play
w = write_wav(tempfile.mktemp(), merged, 44100 * 2)
winsound.PlaySound(w, flags=winsound.SND_FILENAME)
if __name__ == '__main__':
main()