Advertisement
pleasedontcode

Audio Logger rev_03

Sep 12th, 2024
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Audio Logger
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-12 05:02:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Digitally input stereo audio from i2sadc and */
  21.     /* display it on the serial monitor. */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* in stereo display */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <tinyI2S.h>    // https://github.com/chrmlinux/tinyI2S
  28. #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t button_PushButton_PIN_D4 = 4;
  36.  
  37. /***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  38. tinyI2S tI2S; // Instance of tinyI2S for handling I2S functionality
  39. EasyButton button(button_PushButton_PIN_D4); // Instance of EasyButton for button handling
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize Serial for debugging purposes
  44.     Serial.begin(115200); // Set baud rate for serial communication
  45.  
  46.     // Initialize button with pull-up resistor enabled
  47.     pinMode(button_PushButton_PIN_D4, INPUT_PULLUP); // Set the button pin as input with pull-up
  48.     button.begin(); // Call begin to set up the button
  49.  
  50.     // Initialize tinyI2S with buffer size and sampling rate
  51.     tI2S.begin(RECORD_BUFSIZE_80K, SAMPLING_RATE_16K);
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // Update button state
  57.     button.update(); // Update the button state for debouncing
  58.  
  59.     // Check if the button is pressed
  60.     if (button.read()) {
  61.         // Perform actions when the button is pressed
  62.         tI2S.record(); // Start recording
  63.        
  64.         // Display audio data on the serial monitor
  65.         int16_t audioData[2]; // Array to hold stereo audio data
  66.         while (tI2S.isRecording()) { // Continue while recording
  67.             tI2S.read(audioData, sizeof(audioData)); // Read stereo audio data
  68.             Serial.print("Left Channel: "); // Print left channel data
  69.             Serial.print(audioData[0]); // Print left channel audio data
  70.             Serial.print(" | Right Channel: "); // Print right channel data
  71.             Serial.println(audioData[1]); // Print right channel audio data
  72.         }
  73.     }
  74.    
  75.     tI2S.update(); // Update tinyI2S for continuous operation
  76. }
  77.  
  78. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement