From 3cb47875eb3c545ebb39c8b7fdb8bf8e8da2e854 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 1 Mar 2021 17:15:01 +0100 Subject: [PATCH] PDMSerialPlotter stereo version --- .../PDMSerialPlotter/PDMSerialPlotter.ino | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino diff --git a/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino b/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino old mode 100644 new mode 100755 index 6f836b6a6..3b1e4df33 --- a/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino +++ b/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino @@ -12,8 +12,14 @@ #include +// default number of output channels +static const char channels = 1; + +// default PCM output frequency +static const int frequency = 16000; + // Buffer to read samples into, each sample is 16-bits -short sampleBuffer[256]; +short sampleBuffer[512]; // Number of audio samples read volatile int samplesRead; @@ -33,7 +39,7 @@ void setup() { // - one channel (mono mode) // - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense // - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shield - if (!PDM.begin(1, 16000)) { + if (!PDM.begin(channels, frequency)) { Serial.println("Failed to start PDM!"); while (1); } @@ -45,6 +51,12 @@ void loop() { // Print samples to the serial monitor or plotter for (int i = 0; i < samplesRead; i++) { + if(channels == 2) { + Serial.print("L:"); + Serial.print(sampleBuffer[i]); + Serial.print(" R:"); + i++; + } Serial.println(sampleBuffer[i]); }