graph.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import numpy as np
  2. from cmsisdsp.cg.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=InterleavedStereoToMono("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. conf=Configuration()
  28. #conf.dumpSchedule = True
  29. sched = g.computeSchedule(conf)
  30. print("Schedule length = %d" % sched.scheduleLength)
  31. print("Memory usage %d bytes" % sched.memory)
  32. #
  33. conf.debugLimit=12
  34. conf.pyOptionalArgs="mfccConfig,dispbuf"
  35. sched.pythoncode(".",config=conf)
  36. with open("test.dot","w") as f:
  37. sched.graphviz(f)