0

I've got a ~1s mono .WAV on disk. I would like my OSX (and later iOS) app to read it into a float buffer.

What's the simplest way to achieve this?

P i
  • 29,020
  • 36
  • 159
  • 267

2 Answers2

2

Solution is to use ExtAudioFile()

I found it reading the most excellent Core-Audio bible

P i
  • 29,020
  • 36
  • 159
  • 267
1

The libsndfile way :)

   SF_INFO sfinfo;
   SNDFILE *sf;
   float *buf;
   int err_code;

   sfinfo.format = 0;
   sf = sf_open("/meow.wav", SFM_READ, &sfinfo);
   err_code = sf_error(sf);
   if (err_code == SF_ERR_NO_ERROR) {
      buf = malloc(sfinfo.frames * sfinfo.channels * sizeof(float));
      sf_read(sf, buf, sfinfo.frames * sfinfo.channels);
      printf("Done!\n");
   } else {
      printf("%s\n", sf_error_number(err_code));
   }
omygaudio
  • 631
  • 5
  • 6
  • libsndfile is not "iOS friendly" (or better stated: iOS is not "LGPL friendly"), so I would recommend Extended Audio File Services instead. Read more about libsndfile and iOS here: http://stackoverflow.com/questions/4939268/can-the-libsndfile-library-be-used-on-the-iphone-ios – Oriol Nieto Jun 18 '13 at 13:30