• Audio
  • Opening audio files

Hello, I am doing audio processing on audio wav files and it works fine. Now I am downloading freesound audio sample with the following command: sound.retrieve_preview()
This works well and downloads the audio with the wav format I specified in the query and plays fine on the IDE. However, when I try to open the file using this:

gSampleBufferLength = getNumFrames(gFilename);
if(gSampleBufferLength <= 0) {
rt_printf("Error loading audio file '%s'\n", gFilename.c_str());
return false;
}


gSampleBuffer = new float[gSampleBufferLength];

if(gSampleBuffer == 0) {
    rt_printf("Error allocating memory for the audio buffer.\n");
    return false;
}


// Load the sound into the file (note: this example assumes a mono audio file)
getSamples(gFilename, gSampleBuffer, 0, 0, gSampleBufferLength);

rt_printf("Loaded the audio file '%s' with %d frames (%.1f seconds)\n",
          gFilename.c_str(), gSampleBufferLength,
          gSampleBufferLength / context->audioSampleRate);

I get the following error:

"Couldn't open file audio_sample.wav: File contains data in an unknown format.
Error loading audio file 'audio_sample.wav'"

It also doesn't play on my computer but it still says that the type is wav.
Is there any extra information I should look out for? Does it have to do with compressed/uncompressed?

Thank you in advance!

    cynthiak sound.retrieve_preview()

    not sure what this is. Does it connect to freesound and download a file? Is it actually a wav file? If you copy the file to your computer, can you play it with a regular media player?

      giuliomoro It's a function in freesound's API that let's me download the file (another method is to write a script for http requests to GET or download the sound)
      I can't play it in Audacity, Logic Pro or iTunes but it plays when I press the enter bar on mac after selecting the file from Finder (so it previews). It also plays on the IDE when I press play.
      What's weird is that Mac files info told me it's wav file while an online analyzer tool said it was some MP3 type. I converted it from mp3 to wav and it worked.

      So I'd guess that it's actually an mp3, which is why it doesn't work on Bela (there is no mp3 codec installed). In fact, I would have found it strange if the preview was a wav file ...

      You could see if a different function allows you to download a supported file format, or look into installing an mp3 codec on Bela.