graph.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import numpy as np
  2. from cmsisdsp.sdf.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. sched = g.computeSchedule()
  25. print("Schedule length = %d" % sched.scheduleLength)
  26. print("Memory usage %d bytes" % sched.memory)
  27. #
  28. conf=Configuration()
  29. conf.debugLimit=1
  30. conf.cOptionalArgs="arm_mfcc_instance_f32 *mfccConfig"
  31. #conf.codeArray=True
  32. sched.ccode("generated",config=conf)
  33. with open("test.dot","w") as f:
  34. sched.graphviz(f)