graph.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import numpy as np
  2. from cmsisdsp.cg.scheduler import *
  3. from sharedconfig import *
  4. floatType = CType(F32)
  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=FileSource("src",NBCHANNELS*AUDIO_INTERRUPT_LENGTH)
  11. src.addLiteralArg("input_example6.txt")
  12. slidingAudio=SlidingBuffer("audioWin",floatType,FFTSize,FFTSize>>1)
  13. slidingMFCC=SlidingBuffer("mfccWin",floatType,2*numOfDctOutputs,numOfDctOutputs)
  14. mfcc=MFCC("mfcc",floatType,FFTSize,numOfDctOutputs)
  15. mfcc.addVariableArg("mfccConfig")
  16. sink=FileSink("sink",numOfDctOutputs)
  17. sink.addLiteralArg("output_example6.txt")
  18. g = Graph()
  19. g.connect(src.o, slidingAudio.i)
  20. g.connect(slidingAudio.o, mfcc.i)
  21. g.connect(mfcc.o,slidingMFCC.i)
  22. g.connect(slidingMFCC.o,sink.i)
  23. print("Generate graphviz and code")
  24. conf=Configuration()
  25. #conf.dumpSchedule = True
  26. sched = g.computeSchedule(conf)
  27. print("Schedule length = %d" % sched.scheduleLength)
  28. print("Memory usage %d bytes" % sched.memory)
  29. #
  30. conf.debugLimit=1
  31. conf.cOptionalArgs="arm_mfcc_instance_f32 *mfccConfig"
  32. #conf.codeArray=True
  33. sched.ccode("generated",config=conf)
  34. with open("test.dot","w") as f:
  35. sched.graphviz(f)