Debian Codegraph @

src/openmpt/soundfile_write/wav_write.hpp

raw
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */
3
4
5 #pragma once
6
7 #include "openmpt/all/BuildSettings.hpp"
8
9 #include "mpt/io/base.hpp"
10 #include "mpt/io/io_virtual_wrapper.hpp"
11 #include "mpt/string/types.hpp"
12
13 #include "openmpt/base/Types.hpp"
14 #include "openmpt/soundfile_data/tags.hpp"
15 #include "openmpt/soundfile_data/wav.hpp"
16
17
18
19 OPENMPT_NAMESPACE_BEGIN
20
21
22
23 class WAVWriter
24 {
25 protected:
26 // Output stream
27 mpt::IO::OFileBase &s;
28
29 // Currently written chunk
30 mpt::IO::Offset chunkHeaderPos = 0;
31 RIFFChunk chunkHeader;
32 bool finalized = false;
33
34 public:
35 // Output to stream: Initialize with std::ostream*.
36 WAVWriter(mpt::IO::OFileBase &stream);
37
38 // Begin writing a new chunk to the file.
39 void StartChunk(RIFFChunk::ChunkIdentifiers id);
40
41 protected:
42 // End current chunk by updating the chunk header and writing a padding byte if necessary.
43 void FinalizeChunk();
44
45 public:
46 // Write the WAV format to the file.
47 void WriteFormat(uint32 sampleRate, uint16 bitDepth, uint16 numChannels, WAVFormatChunk::SampleFormats encoding);
48
49 // Write text tags to the file.
50 void WriteMetatags(const FileTags &tags);
51
52 protected:
53 // Write a single tag into a open idLIST chunk
54 void WriteTag(RIFFChunk::ChunkIdentifiers id, const mpt::ustring &utext);
55
56 public:
57 // Finalize the file by closing the last open chunk and updating the file header. Returns total size of file.
58 mpt::IO::Offset Finalize();
59
60 ~WAVWriter();
61 };
62
63
64
65 OPENMPT_NAMESPACE_END