Advertisement
pleasedontcode

Audio Recording rev_01

Sep 11th, 2024
123
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 Recording
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-12 04:53:54
  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. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <tinyI2S.h>    // https://github.com/chrmlinux/tinyI2S
  26. #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t button_PushButton_PIN_D4 = 4;
  34.  
  35. /***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  36. tinyI2S tI2S; // Create an instance of tinyI2S
  37. EasyButton button(button_PushButton_PIN_D4); // Create an instance of EasyButton with the defined pin
  38.  
  39. void setup(void)
  40. {
  41.     Serial.begin(115200); // Initialize serial communication at 115200 baud rate
  42.     // Initialize the button
  43.     button.begin(); // Set up the button
  44.     pinMode(button_PushButton_PIN_D4, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
  45.  
  46.     // Initialize the tinyI2S library
  47.     tI2S.begin(RECORD_BUFSIZE_80K, SAMPLING_RATE_16K); // Start the I2S with specified buffer size and sampling rate
  48.     tI2S.setMode(MODE_MIC); // Set the mode to microphone
  49. }
  50.  
  51. void loop(void)
  52. {
  53.     // Update the button state
  54.     button.read(); // Update the button state for debouncing
  55.  
  56.     // Check if the button is pressed
  57.     if (button.isPressed()) { // Use isPressed() method to check if the button is currently pressed
  58.         // Button is pressed, perform actions here
  59.         tI2S.record(); // Start recording
  60.         Serial.println("Recording started..."); // Notify that recording has started
  61.     }
  62.  
  63.     // Update the tinyI2S state
  64.     tI2S.update(); // Update the tinyI2S state
  65.  
  66.     // Check if the recording buffer is full
  67.     if (tI2S.isBufFull()) {
  68.         Serial.println("Buffer full, processing audio..."); // Notify that the buffer is full
  69.  
  70.         // Process the audio data (this is just an example, actual processing will depend on your requirements)
  71.         int16_t audioData[RECORD_BUFSIZE_80K]; // Create an array to hold the audio data
  72.         tI2S.read(audioData, RECORD_BUFSIZE_80K); // Read the audio data from the buffer
  73.  
  74.         // Display audio data on the serial monitor
  75.         for (int i = 0; i < RECORD_BUFSIZE_80K; i++) {
  76.             Serial.println(audioData[i]); // Print each audio sample to the serial monitor
  77.         }
  78.  
  79.         tI2S.reset(); // Reset the I2S to prepare for the next recording
  80.     }
  81. }
  82.  
  83. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement