-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added buffer read to `AudioBufferManager` and `I2S`. Example and documentation included. * Update type of words to unsigned in example. * Improve buffered loopback example. * Remove const from read buffer.
- Loading branch information
Showing
6 changed files
with
91 additions
and
2 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
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
39 changes: 39 additions & 0 deletions
39
libraries/I2S/examples/I2SLoopback_Buffer/I2SLoopback_Buffer.ino
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,39 @@ | ||
/* | ||
I2S bi-directional input and output buffered loopback example | ||
Released to the Public Domain by Cooper Dalrymple | ||
*/ | ||
|
||
#include <I2S.h> | ||
|
||
I2S i2s(INPUT_PULLUP); | ||
|
||
#define SIZE 256 | ||
int16_t buffer[SIZE]; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
i2s.setDOUT(0); | ||
i2s.setDIN(1); | ||
i2s.setBCLK(2); // Note: LRCLK = BCLK + 1 | ||
i2s.setBitsPerSample(16); | ||
i2s.setFrequency(22050); | ||
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t)); | ||
i2s.begin(); | ||
|
||
size_t count, index; | ||
while (1) { | ||
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t); | ||
index = 0; | ||
while (index < count) { | ||
// Reduce volume by half | ||
buffer[index++] >>= 1; // right | ||
buffer[index++] >>= 1; // left | ||
} | ||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t)); | ||
} | ||
} | ||
|
||
void loop() { | ||
/* Nothing here */ | ||
} |
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