Add fft() function
This commit is contained in:
1
Pipfile
1
Pipfile
@@ -10,6 +10,7 @@ sounddevice = "*"
|
||||
soundfile = "*"
|
||||
numpy = "*"
|
||||
matplotlib = "*"
|
||||
tkinter = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
||||
@@ -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 = []
|
||||
17
smnp/module/synth/function/fft.py
Normal file
17
smnp/module/synth/function/fft.py
Normal 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')
|
||||
@@ -10,4 +10,4 @@ def _function(env, wave):
|
||||
plot(rawWave)
|
||||
|
||||
|
||||
function = Function(_signature, _function, 'plotWave')
|
||||
function = Function(_signature, _function, 'plot')
|
||||
|
||||
Reference in New Issue
Block a user