graph.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import numpy as np
  2. from cmsisdsp.sdf.scheduler import *
  3. from sharedconfig import *
  4. q15Type = CType(Q15)
  5. ### The feature computed by the graph is one second of MFCCs.
  6. ### So the nbMFCCOutputs is computed from this and with the additional
  7. ### assumption that it must be even.
  8. ### Because the MFCC slising window is sliding by half a second
  9. ### each time (half number of MFCCs)
  10. src=WavSource("src",NBCHANNELS*AUDIO_INTERRUPT_LENGTH)
  11. src.addLiteralArg(True)
  12. src.addLiteralArg("test_stereo.wav")
  13. toMono=StereoToMono("toMono",q15Type,AUDIO_INTERRUPT_LENGTH)
  14. slidingAudio=SlidingBuffer("audioWin",q15Type,FFTSize,AudioOverlap)
  15. slidingMFCC=SlidingBuffer("mfccWin",q15Type,numOfDctOutputs*nbMFCCOutputs,numOfDctOutputs*nbMFCCOutputs>>1)
  16. mfcc=MFCC("mfcc",q15Type,FFTSize,numOfDctOutputs)
  17. mfcc.addVariableArg("mfccConfig")
  18. sink=NumpySink("sink",q15Type,nbMFCCOutputs * numOfDctOutputs)
  19. sink.addVariableArg("dispbuf")
  20. g = Graph()
  21. g.connect(src.o, toMono.i)
  22. g.connect(toMono.o, slidingAudio.i)
  23. g.connect(slidingAudio.o, mfcc.i)
  24. g.connect(mfcc.o,slidingMFCC.i)
  25. g.connect(slidingMFCC.o,sink.i)
  26. print("Generate graphviz and code")
  27. sched = g.computeSchedule()
  28. print("Schedule length = %d" % sched.scheduleLength)
  29. print("Memory usage %d bytes" % sched.memory)
  30. #
  31. conf=Configuration()
  32. conf.debugLimit=12
  33. conf.pyOptionalArgs="mfccConfig,dispbuf"
  34. sched.pythoncode(".",config=conf)
  35. with open("test.dot","w") as f:
  36. sched.graphviz(f)