Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

90 lines
2.6KB

  1. // Simple sine wave & input level test for WM8731 Audio Codec Board
  2. //
  3. // Requires the MikroElektronika Audio Codec board or similar hardware
  4. // http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
  5. //
  6. // When using AudioInputI2Sslave & AudioOutputI2Sslave with MikroE-506,
  7. // the sample rate will be the crystal frequency divided by 256. The
  8. // MikroE-506 comes with a 12.288 MHz crystal, for 48 kHz sample rate.
  9. // To get 44.1 kHz (as expected by the Teensy Audio Library) the crystal
  10. // should be replaced with 11.2896 MHz.
  11. //
  12. // Recommended connections:
  13. //
  14. // Mikroe Teensy 3.1
  15. // ------ ----------
  16. // SCK 9
  17. // MISO 13
  18. // MOSI 22
  19. // ADCL 23 (yes, ADCL & DACL connect together)
  20. // DACL 23
  21. // SDA 18
  22. // SCL 19
  23. // 3.3V +3.3V
  24. // GND GND
  25. //
  26. // For connection using I2S master mode (WM8731 in slave mode, with MCLK):
  27. // https://forum.pjrc.com/threads/53854?p=198733&viewfull=1#post198733
  28. // https://forum.pjrc.com/threads/55334?p=201494&viewfull=1#post201494
  29. //
  30. // This example code is in the public domain.
  31. #include <Audio.h>
  32. #include <Wire.h>
  33. #include <SPI.h>
  34. #include <SD.h>
  35. #include <SerialFlash.h>
  36. // GUItool: begin automatically generated code
  37. AudioSynthWaveform waveform1; //xy=245,160
  38. AudioInputI2Sslave i2sslave1; //xy=265,252
  39. AudioOutputI2Sslave i2sslave2; //xy=429,158
  40. AudioAnalyzeRMS rms2; //xy=436,323
  41. AudioAnalyzeRMS rms1; //xy=444,265
  42. AudioConnection patchCord1(waveform1, 0, i2sslave2, 0);
  43. AudioConnection patchCord2(waveform1, 0, i2sslave2, 1);
  44. AudioConnection patchCord3(i2sslave1, 0, rms1, 0);
  45. AudioConnection patchCord4(i2sslave1, 1, rms2, 0);
  46. AudioControlWM8731master wm8731m1; //xy=292,379
  47. // GUItool: end automatically generated code
  48. void setup() {
  49. wm8731m1.enable();
  50. AudioMemory(15);
  51. waveform1.begin(WAVEFORM_SINE);
  52. waveform1.frequency(440);
  53. waveform1.amplitude(0.9);
  54. wm8731m1.volume(0.50);
  55. wm8731m1.inputSelect(AUDIO_INPUT_MIC);
  56. // wm8731m1.inputSelect(AUDIO_INPUT_LINEIN); // not connected on MikroE-506
  57. }
  58. elapsedMillis msec;
  59. // Print a simple level meter
  60. void loop() {
  61. if (msec > 40) {
  62. if (rms1.available() && rms2.available()) {
  63. msec = 0;
  64. int level_left = rms1.read() * 30.0;
  65. int level_right = rms2.read() * 30.0;
  66. printchar(' ', 30 - level_left);
  67. printchar('<', level_left);
  68. Serial.print("||");
  69. printchar('>', level_right);
  70. Serial.println();
  71. }
  72. }
  73. }
  74. void printchar(char c, int num) {
  75. for (int i=0; i < num; i++) {
  76. Serial.write(c);
  77. }
  78. }