1 | /* |
2 | Copyright 2018 Google Inc. All Rights Reserved. |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS-IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | |
17 | #ifndef RESONANCE_AUDIO_UTILS_WAV_H_ |
18 | #define RESONANCE_AUDIO_UTILS_WAV_H_ |
19 | |
20 | #include <cstdint> |
21 | #include <memory> |
22 | #include <vector> |
23 | |
24 | namespace vraudio { |
25 | |
26 | // Wraps WavReader class to decode a wav file into memory. |
27 | class Wav { |
28 | public: |
29 | ~Wav(); |
30 | |
31 | // Reads a RIFF WAVE from an opened binary stream. |
32 | static std::unique_ptr<const Wav> CreateOrNull(std::istream* binary_stream); |
33 | |
34 | // Returns reference to interleaved samples. |
35 | const std::vector<int16_t>& interleaved_samples() const { |
36 | return interleaved_samples_; |
37 | } |
38 | |
39 | // Returns number of channels. |
40 | size_t GetNumChannels() const { return num_channels_; } |
41 | |
42 | // Returns sample rate. |
43 | int GetSampleRateHz() const { return sample_rate_; } |
44 | |
45 | private: |
46 | // Private constructor used by static factory methods. |
47 | // |
48 | // @param num_channels Number of audio channels. |
49 | // @param sample_rate Sample rate. |
50 | // @param interleaved_samples Decoded interleaved samples. |
51 | Wav(size_t num_channels, int sample_rate, |
52 | std::vector<int16_t>&& interleaved_samples); |
53 | |
54 | // Number of channels. |
55 | size_t num_channels_; |
56 | |
57 | // Sample rate. |
58 | int sample_rate_; |
59 | |
60 | // Interleaved samples. |
61 | std::vector<int16_t> interleaved_samples_; |
62 | }; |
63 | |
64 | } // namespace vraudio |
65 | |
66 | #endif // RESONANCE_AUDIO_UTILS_WAV_H_ |
67 | |