-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from trylaarsdam/recording
I2S recording functionality
- Loading branch information
Showing
11 changed files
with
33,206 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "Arduino.h" | ||
#include <portenta-i2s.h> | ||
#include "ARTiE_Fork.h" | ||
|
||
#define I2S_BUFFER_SIZE I2S_AUDIOFREQ_8K * 5 * 2 // 5 seconds of audio, 2 channels | ||
|
||
PortentaI2S i2s = PortentaI2S(USE_I2S2, I2S_AUDIOFREQ_8K); | ||
|
||
uint32_t myBuffer[I2S_BUFFER_SIZE]; // RX buffer | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); // Begin serial communication to send file | ||
i2s.begin(); // Initialize I2S | ||
|
||
i2s.play(ARTiE_Fork_raw, ARTiE_Fork_raw_len); // Play the 8bit signed audio file | ||
i2s.record(myBuffer, I2S_BUFFER_SIZE); // Record 32bit signed audio into myBuffer for 5 seconds | ||
|
||
// Print the recorded audio to serial | ||
for(int i = 0; i < I2S_BUFFER_SIZE; i++) | ||
{ | ||
if(i % 1 == 0) // 2 words per sample, 2 channels of data | ||
{ | ||
volatile uint32_t sample = myBuffer[i]; | ||
sample = sample >> 14; | ||
int32_t signedSample = sample; // center at 0 | ||
signedSample = sample * 65534; // scale to 32bit from 16bit | ||
Serial.write((uint8_t*)&signedSample, sizeof(int32_t)); | ||
} | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
// do nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[env:portenta_h7_m7] | ||
build_type = debug | ||
platform = ststm32 | ||
board = portenta_h7_m7 | ||
framework = arduino | ||
upload_protocol = stlink | ||
debug_tool = stlink | ||
|
||
[env:portenta_h7_m4] | ||
platform = ststm32 | ||
board = portenta_h7_m4 | ||
framework = arduino | ||
upload_protocol = stlink | ||
debug_tool = stlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.