user52436: I am working on a circuit that can record audio to an SD when a switch is HIGH and stop recording when the switch is LOW. I am using the TMRpcm library. I previously had an issue solved on these two forumsRecording Audio - Film Name Errorand Trying to save .wav files with new name every loop. These solutions solved my problem but have left me with a new one. Currently the audio recorded on the new code (which I have pasted below) results is a very noisy and muffled audio quality; while the audio recorded on the old code (also posted below) is very clear. Could this be a physical issue and if so what should I do about it? Or is it an issue I am missing in the code?
OLD CODE - provides good quality audio
//////////////////////////////////////// SD CARD
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
int audiofile = 0;     // # of recording
unsigned long i = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {

  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (i < 300000) {
    i++;
  }
  i = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      Serial.println("Recording");

      audiofile++; // To move case
      switch (audiofile) {
        case 1: audio.startRecording("1.wav", 16000, A0); break;
        case 2: audio.startRecording("2.wav", 16000, A0); break;
        case 3: audio.startRecording("3.wav", 16000, A0); break;
        case 4: audio.startRecording("4.wav", 16000, A0); break;
        case 5: audio.startRecording("5.wav", 16000, A0); break;
        case 6: audio.startRecording("6.wav", 16000, A0); break;
        case 7: audio.startRecording("7.wav", 16000, A0); break;
        case 8: audio.startRecording("8.wav", 16000, A0); break;
        case 9: audio.startRecording("9.wav", 16000, A0); break;
        case 10: audio.startRecording("10.wav", 16000, A0); break;
      }
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    Serial.println("Hung-Up");
    switch (audiofile) {
      case 1: audio.stopRecording("1.wav"); break;
      case 2: audio.stopRecording("2.wav"); break;
      case 3: audio.stopRecording("3.wav"); break;
      case 4: audio.stopRecording("4.wav"); break;
      case 5: audio.stopRecording("5.wav"); break;
      case 6: audio.stopRecording("6.wav"); break;
      case 7: audio.stopRecording("7.wav"); break;
      case 8: audio.stopRecording("8.wav"); break;
      case 9: audio.stopRecording("9.wav"); break;
      case 10: audio.stopRecording("10.wav"); break;
    }
  }
}

NEW CODE - poor quality audio
//////////////////////////////////////// SD CARD
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
unsigned int i = 0;     // # of recording
unsigned long d = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  //Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {
  char buffer[50];
  sprintf(buffer, "%i.wav", i++);
  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (d < 300000) {
    d++;
  }
  d = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      //Serial.println("Recording");

      audio.startRecording(buffer, 1600, A0);
      //Serial.println(buffer);
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    //Serial.println("Hung-Up");

    audio.stopRecording(buffer);
  }
}


user4143: Old code:
audio.startRecording("1.wav", 16000, A0);

New code:
audio.startRecording(buffer, 1600, A0);

Spot the typo?

52436: <p>I am working on a circuit that can record audio to an SD when a switch is HIGH and stop recording when the switch is LOW. I am using the TMRpcm library. I previously had an issue solved on these two forums<a href="https://forum.arduino.cc/index.php?topic=587263.0" rel="nofollow noreferrer">Recording Audio - Film Name Error</a>and <a href="https://arduino.stackexchange.com/questions/60046/trying-to-save-wav-files-with-new-name-every-loop">Trying to save .wav files with new name every loop</a>. These solutions solved my problem but have left me with a new one. Currently the audio recorded on the new code (which I have pasted below) results is a very noisy and muffled audio quality; while the audio recorded on the old code (also posted below) is very clear. Could this be a physical issue and if so what should I do about it? Or is it an issue I am missing in the code?</p>

<p>OLD CODE - provides good quality audio</p>

<pre><code>//////////////////////////////////////// SD CARD
#include &lt;SD.h&gt;
#include &lt;SPI.h&gt;
#include &lt;TMRpcm.h&gt;
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
int audiofile = 0;     // # of recording
unsigned long i = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {

  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (i &lt; 300000) {
    i++;
  }
  i = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      Serial.println("Recording");

      audiofile++; // To move case
      switch (audiofile) {
        case 1: audio.startRecording("1.wav", 16000, A0); break;
        case 2: audio.startRecording("2.wav", 16000, A0); break;
        case 3: audio.startRecording("3.wav", 16000, A0); break;
        case 4: audio.startRecording("4.wav", 16000, A0); break;
        case 5: audio.startRecording("5.wav", 16000, A0); break;
        case 6: audio.startRecording("6.wav", 16000, A0); break;
        case 7: audio.startRecording("7.wav", 16000, A0); break;
        case 8: audio.startRecording("8.wav", 16000, A0); break;
        case 9: audio.startRecording("9.wav", 16000, A0); break;
        case 10: audio.startRecording("10.wav", 16000, A0); break;
      }
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    Serial.println("Hung-Up");
    switch (audiofile) {
      case 1: audio.stopRecording("1.wav"); break;
      case 2: audio.stopRecording("2.wav"); break;
      case 3: audio.stopRecording("3.wav"); break;
      case 4: audio.stopRecording("4.wav"); break;
      case 5: audio.stopRecording("5.wav"); break;
      case 6: audio.stopRecording("6.wav"); break;
      case 7: audio.stopRecording("7.wav"); break;
      case 8: audio.stopRecording("8.wav"); break;
      case 9: audio.stopRecording("9.wav"); break;
      case 10: audio.stopRecording("10.wav"); break;
    }
  }
}
</code></pre>

<p>NEW CODE - poor quality audio</p>

<pre><code>//////////////////////////////////////// SD CARD
#include &lt;SD.h&gt;
#include &lt;SPI.h&gt;
#include &lt;TMRpcm.h&gt;
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
unsigned int i = 0;     // # of recording
unsigned long d = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  //Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {
  char buffer[50];
  sprintf(buffer, "%i.wav", i++);
  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (d &lt; 300000) {
    d++;
  }
  d = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      //Serial.println("Recording");

      audio.startRecording(buffer, 1600, A0);
      //Serial.println(buffer);
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    //Serial.println("Hung-Up");

    audio.stopRecording(buffer);
  }
}
</code></pre>
 4143: <p>Old code:</p>

<pre><code>audio.startRecording("1.wav", 16000, A0);
</code></pre>

<p>New code:</p>

<pre><code>audio.startRecording(buffer, 1600, A0);
</code></pre>

<p>Spot the typo?</p>
