Upload of all solutions and assigment 1
parent
bf91256310
commit
b5ae8eb7a5
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "/home/oyvind/miniconda3/bin/python"
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,33 @@
|
||||||
|
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()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue