Add fft() function

This commit is contained in:
Bartłomiej Pluta
2019-09-08 22:56:24 +02:00
parent 55adf616c5
commit f5c72dd8a5
4 changed files with 21 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ sounddevice = "*"
soundfile = "*"
numpy = "*"
matplotlib = "*"
tkinter = "*"
[requires]
python_version = "3.7"

View File

@@ -1,4 +1,4 @@
from smnp.module.synth.function import synth, pause, plot, compile
from smnp.module.synth.function import synth, pause, plot, compile, fft
functions = [ synth.function, pause.function, plot.function, compile.function ]
functions = [ synth.function, pause.function, plot.function, compile.function, fft.function ]
methods = []

View File

@@ -0,0 +1,17 @@
import numpy as np
from smnp.function.model import Function
from smnp.function.signature import signature
from smnp.type.model import Type
from smnp.type.signature.matcher.list import listOf
_signature = signature(listOf(Type.FLOAT))
def _function(env, signal):
raw = [ x.value for x in signal.value ]
N = len(raw)
fft = np.fft.fft(raw)/N
fft = fft[range(int(N/2))]
return Type.list([ Type.float(float(abs(x))) for x in fft ])
function = Function(_signature, _function, 'fft')

View File

@@ -10,4 +10,4 @@ def _function(env, wave):
plot(rawWave)
function = Function(_signature, _function, 'plotWave')
function = Function(_signature, _function, 'plot')