diff --git a/src/wave/file.cc b/src/wave/file.cc index f8003f4..4c7518c 100644 --- a/src/wave/file.cc +++ b/src/wave/file.cc @@ -195,6 +195,28 @@ Error File::Open(const std::string& path, OpenMode mode) { return impl_->ReadHeader(&headers); } +Error File::Open(const std::wstring& path, OpenMode mode) { + if (mode == OpenMode::kOut) + { + impl_->ostream.open(path, std::ios::binary | std::ios::trunc); + if (!impl_->ostream.is_open()) { + return Error::kFailedToOpen; + } + return impl_->WriteHeader(0); + } + + impl_->istream.open(path, std::ios::binary); + if (!impl_->istream.is_open()) { + return Error::kFailedToOpen; + } + HeaderList headers; + auto error = headers.Init(path); + if (error != kNoError) { + return error; + } + return impl_->ReadHeader(&headers); +} + uint16_t File::channel_number() const { return impl_->header.fmt.num_channel; } void File::set_channel_number(uint16_t channel_number) { impl_->header.fmt.num_channel = channel_number; diff --git a/src/wave/file.h b/src/wave/file.h index 68f7328..d9f2085 100644 --- a/src/wave/file.h +++ b/src/wave/file.h @@ -27,6 +27,7 @@ class File { * @brief Open wave file at given path */ Error Open(const std::string& path, OpenMode mode); + Error Open(const std::wstring& path, OpenMode mode); /** * @brief Read the entire content of file. diff --git a/src/wave/header_list.cc b/src/wave/header_list.cc index 1fe6393..b3a4ef3 100644 --- a/src/wave/header_list.cc +++ b/src/wave/header_list.cc @@ -41,6 +41,14 @@ Error HeaderList::Init(const std::string& path) { return Error::kNoError; } +Error HeaderList::Init(const std::wstring& path) { + stream_.open(path, std::ios::binary); + if (!stream_.is_open()) { + return Error::kFailedToOpen; + } + return Error::kNoError; +} + HeaderList::Iterator HeaderList::begin() { return HeaderList::Iterator(&stream_, 0); } diff --git a/src/wave/header_list.h b/src/wave/header_list.h index 70e4fe5..aaf49ac 100644 --- a/src/wave/header_list.h +++ b/src/wave/header_list.h @@ -24,6 +24,7 @@ class HeaderList { }; Error Init(const std::string& path); + Error Init(const std::wstring& path); Iterator begin(); Iterator end();