You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
595 B

  1. #! /bin/python
  2. import wave, struct, sys
  3. waveFile = wave.open(sys.argv[1], 'r')
  4. length = waveFile.getnframes()
  5. out = "static const dacsample_t dac_buffer_custom[" + str(int(length / 256)) + "][256] = {"
  6. for i in range(0,length):
  7. if (i % 8 == 0):
  8. out += "\n "
  9. if (i % 256 == 0):
  10. out = out[:-2]
  11. out += "{\n "
  12. waveData = waveFile.readframes(1)
  13. data = struct.unpack("<h", waveData)
  14. out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
  15. if (i % 256 == 255):
  16. out = out[:-2]
  17. out += "\n },"
  18. out = out[:-1]
  19. out += "\n};"
  20. print(out)