/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: Audio Recording - Source Code NOT compiled for: ESP32 DevKit V1 - Source Code created on: 2024-09-12 04:53:54 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Digitally input stereo audio from i2sadc and */ /* display it on the serial monitor. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // https://github.com/chrmlinux/tinyI2S #include // https://github.com/evert-arias/EasyButton /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button_PushButton_PIN_D4 = 4; /***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/ tinyI2S tI2S; // Create an instance of tinyI2S EasyButton button(button_PushButton_PIN_D4); // Create an instance of EasyButton with the defined pin void setup(void) { Serial.begin(115200); // Initialize serial communication at 115200 baud rate // Initialize the button button.begin(); // Set up the button pinMode(button_PushButton_PIN_D4, INPUT_PULLUP); // Set the button pin as input with pull-up resistor // Initialize the tinyI2S library tI2S.begin(RECORD_BUFSIZE_80K, SAMPLING_RATE_16K); // Start the I2S with specified buffer size and sampling rate tI2S.setMode(MODE_MIC); // Set the mode to microphone } void loop(void) { // Update the button state button.read(); // Update the button state for debouncing // Check if the button is pressed if (button.isPressed()) { // Use isPressed() method to check if the button is currently pressed // Button is pressed, perform actions here tI2S.record(); // Start recording Serial.println("Recording started..."); // Notify that recording has started } // Update the tinyI2S state tI2S.update(); // Update the tinyI2S state // Check if the recording buffer is full if (tI2S.isBufFull()) { Serial.println("Buffer full, processing audio..."); // Notify that the buffer is full // Process the audio data (this is just an example, actual processing will depend on your requirements) int16_t audioData[RECORD_BUFSIZE_80K]; // Create an array to hold the audio data tI2S.read(audioData, RECORD_BUFSIZE_80K); // Read the audio data from the buffer // Display audio data on the serial monitor for (int i = 0; i < RECORD_BUFSIZE_80K; i++) { Serial.println(audioData[i]); // Print each audio sample to the serial monitor } tI2S.reset(); // Reset the I2S to prepare for the next recording } } /* END CODE */