Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

Solution is to use ExtAudioFile()

I found it reading the most excellent Core-Audio bible

share|improve this answer
If you are looking for something cross-platform as well, you can check out libsndfile. – blitz3d Jun 10 at 2:11

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));
   }
share|improve this answer
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: stackoverflow.com/questions/4939268/… – urinieto Jun 18 at 13:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.