33 lines
686 B
Python
33 lines
686 B
Python
|
import numpy as np
|
||
|
import sounddevice as sd
|
||
|
|
||
|
# Physical freq to "sample", must be integer
|
||
|
F_1 = 1000
|
||
|
# Volume must be between 0 and 100, may be float
|
||
|
volume = 20
|
||
|
# Sampling freq, must be integer
|
||
|
F_s = 6000
|
||
|
# Time how long a sample should last, must be integer
|
||
|
duration = 4
|
||
|
|
||
|
# Calculation of constants
|
||
|
volume = volume / 100
|
||
|
totalSamples = F_s * duration
|
||
|
|
||
|
# Comment out the last decleration if you want to use a fixed f1
|
||
|
f_1 = 0.3
|
||
|
#f_1 = F_1 / F_s
|
||
|
|
||
|
def GenSound(f1, noSamples, vol):
|
||
|
x = np.empty(noSamples)
|
||
|
for n in range(noSamples):
|
||
|
x[n] = np.cos(2*np.pi * f1 * n) * vol
|
||
|
return x
|
||
|
|
||
|
x = GenSound(f_1, totalSamples, volume)
|
||
|
|
||
|
print(x)
|
||
|
|
||
|
sd.play(x, F_s)
|
||
|
sd.wait()
|
||
|
sd.stop()
|