-1

I am using oboe lib for sound playback

https://github.com/google/oboe/blob/master/docs/FullGuide.md

as a sound file I am using .wav file. As far as I know there is a way to get from .wav file header - sample rate.

So, question is - how to pro grammatically in C++ read the sample rate from an arbitrary .wav file?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • Is the question how to programmatically in C++ read the sample rate from an arbitrary wav file? – foolo Dec 17 '19 at 17:44
  • Are you asking how to read a file, where the header is in a WAV file, or how to understand a WAV file header? – user253751 Dec 17 '19 at 17:44
  • @foolo yes, edited my question – Sirop4ik Dec 17 '19 at 17:45
  • 1
    Start by learning about the structure of the [wav format/header](http://tiny.systems/software/soundProgrammer/WavFormatDocs.pdf). Then write code to read and parse it. – Jesper Juhl Dec 17 '19 at 17:55
  • According to the [documentation](https://google.github.io/oboe/reference/classoboe_1_1_audio_stream_base.html#ae9d32f3e09174bad69e74f147ee33087), you can get the sample rate of an `AudioStream` with `getSampleRate()`, but it is maybe not the best way in your case. – TGrif Dec 17 '19 at 18:19

2 Answers2

1

There is no standard functionality in C++ for parsing wav files.

The bytes at indices 24-27 of the header represent a 32 bit integer that is the sample rate in Hz.

eerorika
  • 232,697
  • 12
  • 197
  • 326
1

If you want to write your own WAV parser, perhaps look at this question (note one error in the code which is corrected in my answer): printing of a wav header in c

But probably it is more convenient to use a library. For instance, libsndfile has an API sf_open that returns an SF_INFO struct, that includes the sample rate.

mtrw
  • 34,200
  • 7
  • 63
  • 71