blob: bf3b95a5cf67e7532033339e3953fb3648dff2e1 [file] [log] [blame]
// Copyright 2015 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_AUDIO_AUDIO_FILE_READER_WAV_H_
#define COBALT_AUDIO_AUDIO_FILE_READER_WAV_H_
#include <memory>
#include "cobalt/audio/audio_file_reader.h"
#include "cobalt/audio/audio_helpers.h"
namespace cobalt {
namespace audio {
// WAVE Audio File Format Specifications:
// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
class AudioFileReaderWAV : public AudioFileReader {
public:
static std::unique_ptr<AudioFileReader> TryCreate(const uint8* data,
size_t size,
SampleType sample_type);
float sample_rate() const override { return sample_rate_; }
int32 number_of_frames() const override { return number_of_frames_; }
int32 number_of_channels() const override { return number_of_channels_; }
SampleType sample_type() const override { return sample_type_; }
std::unique_ptr<AudioBus> ResetAndReturnAudioBus() override {
return std::move(audio_bus_);
}
private:
AudioFileReaderWAV(const uint8* data, size_t size, SampleType sample_type);
bool ParseRIFFHeader(const uint8* data, size_t size);
void ParseChunks(const uint8* data, size_t size);
bool ParseWAV_fmt(const uint8* data, size_t offset, size_t size,
bool* is_src_sample_in_float);
bool ParseWAV_data(const uint8* data, size_t offset, size_t size,
bool is_src_sample_in_float);
bool is_valid() { return audio_bus_ != NULL; }
std::unique_ptr<AudioBus> audio_bus_;
float sample_rate_;
int32 number_of_frames_;
int32 number_of_channels_;
SampleType sample_type_;
};
} // namespace audio
} // namespace cobalt
#endif // COBALT_AUDIO_AUDIO_FILE_READER_WAV_H_