CMSIS-DSP: SDFTools corrections

Small issue in MFCC node.
Corrected how literal and variable arguments are used.
(Now it is more general in any order given by user).
pull/19/head
Christophe Favergeon 4 years ago
parent 9bdaa9d9ea
commit 6d159f6085

@ -17,8 +17,8 @@ q15Type = CType(Q15)
### Because the MFCC slising window is sliding by half a second
### each time (half number of MFCCs)
src=WavSource("src",NBCHANNELS*AUDIO_INTERRUPT_LENGTH)
src.addLiteralArg("test_stereo.wav")
src.addLiteralArg(True)
src.addLiteralArg("test_stereo.wav")
toMono=StereoToMono("toMono",q15Type,AUDIO_INTERRUPT_LENGTH)

@ -60,7 +60,7 @@ def scheduler(mfccConfig,dispbuf):
mfcc = MFCC(1024,13,fifo2,fifo3,mfccConfig)
mfccWin = SlidingBuffer(754,377,fifo3,fifo4)
sink = NumpySink(754,fifo4,dispbuf)
src = WavSource(384,fifo0,"test_stereo.wav",True)
src = WavSource(384,fifo0,True,"test_stereo.wav")
toMono = StereoToMono(384,192,fifo0,fifo1)
while((sdfError==0) and (debugCounter > 0)):

@ -34,7 +34,7 @@ import cmsisdsp as dsp
class CFFT(GenericNode):
def __init__(self,inputSize,outSize,fifoin,fifoout):
GenericNode.__init__(self,inputSize,outSize,fifoin,fifoout)
if fifoin.type == np.dtype(np.float):
if fifoin.type == np.dtype(np.float32):
self._cfft=dsp.arm_cfft_instance_f32()
status=dsp.arm_cfft_init_f32(self._cfft,inputSize>>1)
if fifoin.type == np.dtype(np.int16):
@ -46,7 +46,7 @@ class CFFT(GenericNode):
b=self.getWriteBuffer()
# Copy arrays (not just assign references)
b[:]=a[:]
if self._src.type == np.dtype(np.float):
if self._src.type == np.dtype(np.float32):
dsp.arm_cfft_f32(self._cfft,b,0,1)
if self._src.type == np.dtype(np.int16):
dsp.arm_cfft_q15(self._cfft,b,0,1)

@ -32,7 +32,7 @@ import cmsisdsp as dsp
class ICFFT(GenericNode):
def __init__(self,inputSize,outSize,fifoin,fifoout):
GenericNode.__init__(self,inputSize,outSize,fifoin,fifoout)
if fifoin.type == np.dtype(np.float):
if fifoin.type == np.dtype(np.float32):
self._icfft=dsp.arm_cfft_instance_f32()
status=dsp.arm_cfft_init_f32(self._icfft,inputSize>>1)
if fifoin.type == np.dtype(np.int16):
@ -44,7 +44,7 @@ class ICFFT(GenericNode):
b=self.getWriteBuffer()
# Copy arrays (not just assign references)
b[:]=a[:]
if self._src.type == np.dtype(np.float):
if self._src.type == np.dtype(np.float32):
dsp.arm_cfft_f32(self._icfft,b,1,1)
if self._src.type == np.dtype(np.int16):
dsp.arm_cfft_q15(self._icfft,b,1,1)

@ -35,13 +35,16 @@ class MFCC(GenericNode):
def __init__(self,inputSize,outSize,fifoin,fifoout,mfccConfig):
GenericNode.__init__(self,inputSize,outSize,fifoin,fifoout)
self._config=mfccConfig
self._tmp=np.zeros(2*inputSize,dtype=np.int32)
if self._src.type == np.dtype(np.float32):
self._tmp=np.zeros(2*inputSize,dtype=np.float32)
else:
self._tmp=np.zeros(2*inputSize,dtype=np.int32)
def run(self):
a=self.getReadBuffer()
b=self.getWriteBuffer()
if self._src.type == np.dtype(np.float):
if self._src.type == np.dtype(np.float32):
res=dsp.arm_mfcc_f32(self._config,a,self._tmp)
errorStatus = 0
if self._src.type == np.dtype(np.int32):

@ -32,7 +32,7 @@ import cmsisdsp as dsp
class StereoToMono(GenericNode):
def __init__(self,inputSize,outputSize,fifoin,fifoout):
GenericNode.__init__(self,inputSize,outputSize,fifoin,fifoout)
if fifoin.type == np.dtype(np.float):
if fifoin.type == np.dtype(np.float32):
self._isFloat=True
else:
self._isFloat=False

@ -33,7 +33,7 @@ import wave
# Pad with zero when end of file is reached
class WavSource(GenericSource):
"Read a stereo wav with 16 bits encoding"
def __init__(self,outputSize,fifoout,name,stereo=True):
def __init__(self,outputSize,fifoout,stereo,name):
GenericSource.__init__(self,outputSize,fifoout)
self._file=wave.open(name, 'rb')
self._stereo=stereo

@ -130,7 +130,32 @@ class Constant:
return True
class SchedArg:
"""Class for arguments of the scheduler functions.
They can either be a literal arg like string, boolean
or number or they can be a variable name"""
def __init__(self,name):
self._name=name
class ArgLiteral(SchedArg):
def __init__(self,name):
super().__init__(name)
@property
def arg(self):
if isinstance(self._name,str):
return("\"%s\"" % self._name)
else:
return(str(self._name))
class VarLiteral(SchedArg):
def __init__(self,name):
super().__init__(name)
@property
def arg(self):
return(self._name)
class BaseNode:
"""Root class for all Nodes of a dataflow graph.
@ -149,8 +174,7 @@ class BaseNode:
# The fifo args
self._args=""
# Literal arguments
self.literalArgs=None
self.variableArguments=None
self.schedArgs=None
def __getattr__(self,name):
"""Present inputs / outputs as attributes"""
@ -169,16 +193,16 @@ class BaseNode:
raise IndexError
def addLiteralArg(self,l):
if self.literalArgs:
self.literalArgs.append(l)
if self.schedArgs:
self.schedArgs.append(ArgLiteral(l))
else:
self.literalArgs=[l]
self.schedArgs=[ArgLiteral(l)]
def addVariableArg(self,l):
if self.variableArguments:
self.variableArguments.append(l)
if self.schedArgs:
self.schedArgs.append(VarLiteral(l))
else:
self.variableArguments=[l]
self.schedArgs=[VarLiteral(l)]
@property
def isConstantNode(self):
@ -291,14 +315,9 @@ class BaseNode:
"""String of fifo args for object initialization
with literal argument and variable arguments"""
allArgs=self.listOfargs
if self.literalArgs:
for lit in self.literalArgs:
if isinstance(lit,str):
allArgs.append("\"%s\"" % lit)
else:
allArgs.append(str(lit))
if self.variableArguments:
allArgs += self.variableArguments
if self.schedArgs:
for lit in self.schedArgs:
allArgs.append(lit.arg)
return "".join(joinit(allArgs,","))
@args.setter

Loading…
Cancel
Save