Go Down

Topic: Recording Audio - Film Name Error (Read 658 times) previous topic - next topic

Tristans5


So I'm making a recording device hooked up to a rotary phone receiver, it is using the TMRpcm Library. Currently, the code I have is working perfectly with my build. The only problem is I want to be able to record an infinite amount of sound files. I had it with a Switch Case earlier but needed to manually name each file and could only reach a case limit of 10 before RAM became an issue. I have tried adding a variable as well as a string into the record line but I receive the error message below. The library states the startRecording() function must be written as such: void startRecording(char *fileName, unsigned int SAMPLE_RATE, byte pin, byte passThrough); and the stopRecording as such: void stopRecording(char *fileName); 

Code: [Select]
/Users/Tristan/Documents/Arduino/SpeakerCorner/SpeakerCorner.ino: In function 'void loop()':
SpeakerCorner:41:63: error: no matching function for call to 'TMRpcm::startRecording(StringSumHelper&, int, const uint8_t&)'
       audio.startRecording(String(audiofile)+".wav", 16000, A0); break;
                                                               ^
In file included from /Users/Tristan/Documents/Arduino/SpeakerCorner/SpeakerCorner.ino:4:0:
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:76:8: note: candidate: void TMRpcm::startRecording(char*, unsigned int, byte)
   void startRecording(char* fileName, unsigned int SAMPLE_RATE, byte pin);
        ^
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:76:8: note:   no known conversion for argument 1 from 'StringSumHelper' to 'char*'
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:77:8: note: candidate: void TMRpcm::startRecording(char*, unsigned int, byte, byte)
   void startRecording(char *fileName, unsigned int SAMPLE_RATE, byte pin, byte passThrough);
        ^
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:77:8: note:   candidate expects 4 arguments, 3 provided
SpeakerCorner:41:66: error: break statement not within loop or switch
       audio.startRecording(String(audiofile)+".wav", 16000, A0); break;
                                                                  ^
SpeakerCorner:153:49: error: no matching function for call to 'TMRpcm::stopRecording(StringSumHelper&)'
     audio.stopRecording(String(audiofile)+".wav"); break;
                                                 ^
In file included from /Users/Tristan/Documents/Arduino/SpeakerCorner/SpeakerCorner.ino:4:0:
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:78:8: note: candidate: void TMRpcm::stopRecording(char*)
   void stopRecording(char *fileName);
        ^
/Users/Tristan/Documents/Arduino/libraries/TMRpcm/TMRpcm.h:78:8: note:   no known conversion for argument 1 from 'StringSumHelper' to 'char*'
SpeakerCorner:153:52: error: break statement not within loop or switch
     audio.stopRecording(String(audiofile)+".wav"); break;


THIS IS MY CODE BELOW

Code: [Select]

//////////////////////////////////////// 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
      audio.startRecording(String(audiofile)+".wav", 16000, A0); break;
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    Serial.println("Hung-Up");
    audio.stopRecording(String(audiofile)+".wav"); break;
  }
}

pert

The TMRpcm library's functions don't work with String. You will need to use regular strings (null terminated char arrays) instead:
http://www.cplusplus.com/reference/cstring/

You shouldn't be using String anyway.

Tristans5

Would the use of an int be a better idea? If so how would I properly implement that into the code as simply adding it before with a "+" is not working.

pert

Also posted at:
https://arduino.stackexchange.com/q/60046
If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.


pert

#4
Dec 27, 2018, 12:15 pm Last Edit: Dec 27, 2018, 12:16 pm by pert Reason: Add strcat link
Would the use of an int be a better idea? If so how would I properly implement that into the code as simply adding it before with a "+" is not working.
Create a buffer with 13 elements (maximum 8 character file name + 1 for the dot + maximum 3 character extension + terminator):
Code: [Select]
char audioFilename[13];
Use itoa to convert the int to its base-10 string representation and put it in the buffer:
Code: [Select]
itoa(audiofile, audioFilename, 10);
use strcat to add the extension:
Code: [Select]
strcat(audioFilename, ".wav");
The buffer now contains the filename as a string, which you can pass to the tmrPCM library.


Tristans5

Create a buffer with 13 elements (maximum 8 character file name + 1 for the dot + maximum 3 character extension + terminator):
Code: [Select]
char audioFilename[13];
Use itoa to convert the int to its base-10 string representation and put it in the buffer:
Code: [Select]
itoa(audiofile, audioFilename, 10);
use strcat to add the extension:
Code: [Select]
strcat(audioFilename, ".wav");
The buffer now contains the filename as a string, which you can pass to the tmrPCM library.


Thank you very much! This worked. Unfortunately, I am now receiving much poorer quality audio with a lot of noise. I am assuming this is something to do with the circuit which may require a capacitor.   

pert

You're very welcome. I'm glad if I was able to be of assistance.

Go Up