PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

73 line
2.1KB

  1. % Talkie library
  2. % Copyright 2011 Peter Knight
  3. % This code is released under GPLv2 license.
  4. %
  5. % Convert model parameter mapping into bitstream for ROM
  6. frames = csvread('tomsDinerStream.csv');
  7. lastFrame = [-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]; % Jumk frame
  8. repeatThreshold = 4;
  9. silentFrames = 0;
  10. repeatFrames = 0;
  11. unvoicedFrames = 0;
  12. voicedFrames = 0;
  13. numFrames = size(frames)(1);
  14. for f = 1:numFrames;
  15. frame = frames(f,:);
  16. % Is this a silent frame?
  17. if frame(1) < 1
  18. % Emit a silent frame
  19. bitEmit(0,4);
  20. silentFrames = silentFrames + 1;
  21. lastFrame = [0,0,0,0,0,0,0,0,0,0,0,0,0];
  22. else
  23. bitEmit(frame(1),4);
  24. coefficientDelta = sum(abs(frame(4:13)-lastFrame(4:13)));
  25. if coefficientDelta <= repeatThreshold
  26. % Emit a repeat frame
  27. bitEmit(1,1);
  28. bitEmit(frame(3),6);
  29. repeatFrames = repeatFrames + 1;
  30. lastFrame(1) = frame(1);
  31. lastFrame(3) = frame(3);
  32. else
  33. bitEmit(0,1);
  34. bitEmit(frame(3),6);
  35. bitEmit(frame(4),5);
  36. bitEmit(frame(5),5);
  37. bitEmit(frame(6),4);
  38. bitEmit(frame(7),4);
  39. if frame(3) < 1
  40. % Emit an unvoiced frame
  41. unvoicedFrames = unvoicedFrames + 1;
  42. lastFrame = frame;
  43. else
  44. % Emit a voiced frame
  45. bitEmit(frame(8),4);
  46. bitEmit(frame(9),4);
  47. bitEmit(frame(10),4);
  48. bitEmit(frame(11),3);
  49. bitEmit(frame(12),3);
  50. bitEmit(frame(13),3);
  51. voicedFrames = voicedFrames + 1;
  52. lastFrame = frame;
  53. end
  54. end
  55. end
  56. end
  57. % Emit a stop frame
  58. bitEmit(15,4);
  59. printf('Frames:\n%d V, %d U, %d R, %d S\n',voicedFrames,unvoicedFrames,repeatFrames,silentFrames);
  60. romSize = 50*voicedFrames + 29*unvoicedFrames + 11*repeatFrames + 4*silentFrames;
  61. printf('Rom size %d bits\n',romSize);
  62. % Output from this needs to be grouped into groups of 8 bits.
  63. % LSB of byte is the first bit to be decoded.
  64. % Then needs to be packaged up as a C snippet for inclusion in the libary.