Skip to content

Commit

Permalink
Adjust examples
Browse files Browse the repository at this point in the history
- Add examples for NRF52 I2S
- Move platform specific files into Platform folder
  • Loading branch information
TMRh20 committed Oct 18, 2024
1 parent 26c71ac commit c37bdf9
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions examples/Platforms/NRF52/NRF52_PDM_I2STest/NRF52_PDM_I2STest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <AutoAnalogAudio.h>

AutoAnalog aaAudio;

#if defined(USE_TINYUSB)
// Needed for Serial.print on non-MBED enabled or adafruit-based nRF52 cores
#include "Adafruit_TinyUSB.h"
#endif

/*********************************************************/
/* Tested with MAX98357A I2S breakout
/* BCLK connected to Arduino D1 (p0.03)
/* LRCK connected to Arduino D3 (p0.29)
/* DIN connected to Arduino D5 (p0.05)
/* SD connected to Arduino D6 (p1.11)
/*********************************************************/

void setup() {


Serial.begin(115200);
aaAudio.begin(1, 1, 1); //Setup aaAudio using DAC & I2S
aaAudio.adcBitsPerSample = 16; // 16-bit samples input from PDM
aaAudio.dacBitsPerSample = 16; // 16-bit samples output to I2S
aaAudio.setSampleRate(32000); // 32kHz

pinMode(6, OUTPUT); //Connected to SD pin of MAX98357A
digitalWrite(6,HIGH);

}

void loop() {

aaAudio.getADC(6400); // Get data from PDM microphone

memcpy(aaAudio.dacBuffer16, aaAudio.adcBuffer16, 12800); // Copy data into output buffer from input buffer

aaAudio.feedDAC(0,6400); // Feed the data to I2S output
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
AutoAnalogAudio streaming via DAC & ADC by TMRh20
Copyright (C) 2016 TMRh20 - [email protected], github.com/TMRh20
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Auto Analog Audio (Automatic DAC, ADC & Timer) library
Auto Analog Audio Library Information:
http://github.com/TMRh20
http://tmrh20.blogspot.com
*/

#include <SPI.h>
#include <SD.h>
#include <AutoAnalogAudio.h>

AutoAnalog aaAudio;

/*********************************************************/
/* Tested with MAX98357A I2S breakout
/* BCLK connected to Arduino D1 (p0.03)
/* LRCK connected to Arduino D3 (p0.29)
/* DIN connected to Arduino D5 (p0.05)
/* SD connected to Arduino D6 (p1.11)
/*********************************************************/

void setup() {

Serial.begin(115200);

Serial.print("Init SD card...");
if (!SD.begin(10000000, 2)) {
Serial.println("init failed!");
return;
}
Serial.println("init ok");
Serial.println("Analog Audio Begin");
aaAudio.begin(0, 1, 1); //Setup aaAudio using DAC and I2S

//Setup for audio: Use 8 or 16-bit, mono or stereo. Valid sample rates are 16000, 24000, 32000, 44000
aaAudio.dacBitsPerSample = 8; // 8-bit
aaAudio.setSampleRate(24000, 0); // 24khz, mono

pinMode(6,OUTPUT); //Connected to SD pin of MAX98357A
digitalWrite(6,HIGH);

playAudio("brick/brick24.wav"); // 24kHz @ 16-bits is about the maximum when reading from SD card
}

void loop() {

loadBuffer();

}

/*********************************************************/
/* A simple function to handle playing audio files
/*********************************************************/

File myFile;

void playAudio(char *audioFile) {

if (myFile) {
myFile.close();
}
//Open the designated file
myFile = SD.open(audioFile);
//Skip past the WAV header
myFile.seek(44);
}

void loadBuffer() {

if( myFile.available() ){
myFile.read(aaAudio.dacBuffer, 6400); // Change this to dacBuffer16 for 16-bit samples
aaAudio.feedDAC(0, 6400); // change this to 3200 for 16-bit samples
}else{
myFile.seek(44);
}
}

0 comments on commit c37bdf9

Please sign in to comment.