1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_
6 #define MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_
8 #include "base/strings/string_piece.h"
9 #include "media/base/media_export.h"
15 // This class provides the input from wav file format. See
16 // https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
17 class MEDIA_EXPORT WavAudioHandler {
19 explicit WavAudioHandler(const base::StringPiece& wav_data);
20 virtual ~WavAudioHandler();
22 // Returns true when cursor points to the end of the track.
23 bool AtEnd(size_t cursor) const;
25 // Copies the audio data to |bus| starting from the |cursor| and in
26 // the case of success stores the number of written bytes in
27 // |bytes_written|. |bytes_written| should not be NULL.
28 bool CopyTo(AudioBus* bus, size_t cursor, size_t* bytes_written) const;
30 int size() const { return data_.size(); }
31 uint16 num_channels() const { return num_channels_; }
32 uint32 sample_rate() const { return sample_rate_; }
33 uint32 byte_rate() const { return byte_rate_; }
34 uint16 bits_per_sample() const { return bits_per_sample_; }
37 // Parses a chunk of wav format data. Returns the length of the chunk.
38 int ParseSubChunk(const base::StringPiece& data);
40 // Parses the 'fmt' section chunk and stores |params_|.
41 bool ParseFmtChunk(const base::StringPiece& data);
43 // Parses the 'data' section chunk and stores |data_|.
44 bool ParseDataChunk(const base::StringPiece& data);
46 // Data part of the |wav_data_|.
47 base::StringPiece data_;
52 uint16 bits_per_sample_;
53 int bytes_per_sample_;
59 #endif // MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_