Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/wave/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/wave/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/wave/header_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/wave/header_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class HeaderList {
};

Error Init(const std::string& path);
Error Init(const std::wstring& path);
Iterator begin();
Iterator end();

Expand Down