Read raw audio file and get sample value

Status
Not open for further replies.

urbanspaceman

Well-known member
Hi, im back with an audio project.
I need to read one .raw audio file and get the samples value.

My code now

Code:
File dataFile = SD.open("amen.raw");
int16_t numSamples = (dataFile.size() - (dataFile.size()%256)) >> 1; // return samples_available;
int16_t buf[numSamples] = {0}; // buffer

        
double audio  = dataFile.read();

I should create an array (or two if the file is stereo) with the values of the samples for further use.
right now I don't know how to create the array which I will then use to store the samples values.
 
right now I don't know how to create the array which I will then use to store the samples values.

This line from your own code will create an array.

Code:
int16_t buf[numSamples] = {0}; // buffer

However, this array will be created as a local variable. That's probably not what you want, because the variable will cease to exist when the surrounding function or code block ends (we can't see more of your code, so the best I can do is the very generic advice). Normally arrays for buffers are created as global or static or C++ member variables, so the data is retained and can be reliably used later. Also, it's common practice to use a constant for the array size.
 
Ho Paul, i'm working on this project in the spare time.

the code is this

Code:
uint32_t GET_samples_in_file(uint8_t f)
{
  return Wave.file_samples(name_file[f]);
}

void plotWave(uint8_t n){
  int16_t numSamples = GET_samples_in_file(n);
  File dataFile = SD.open("amen.raw");
  int16_t buf[numSamples] = {0}; // buffer 
  int audio[numSamples]  = dataFile.read(); 

  for(int n=0; n<numSamples; n++){
    ??
  }
}
in included file

Code:
int file_samples(const char *filename)
    {
    File rawfile = SD.open(filename);
    if (!rawfile)
        return 0;
    return (rawfile.size() - (rawfile.size()%256)) >> 1; // return samples_available;
    }
 
Status
Not open for further replies.
Back
Top