Debian Codegraph @

BambooTracker/io/export_io.hpp

raw
1 /*
2 * Copyright (C) 2019-2022 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #pragma once
27
28 #include <vector>
29 #include <string>
30 #include <cmath>
31 #include <cstdint>
32
33 namespace io
34 {
35 class BinaryContainer;
36
37 // VGM ----------
38 struct GD3Tag
39 {
40 std::string trackNameEn, trackNameJp;
41 std::string gameNameEn, gameNameJp;
42 std::string systemNameEn, systemNameJp;
43 std::string authorEn, authorJp;
44 std::string releaseDate;
45 std::string vgmCreator;
46 std::string notes;
47 };
48
49 /**
50 * @brief Helper struct of SSG volume level for VGM export.
51 */
52 struct VgmMix
53 {
54 const uint16_t ssgMultiplier;
55
56 VgmMix(double fmLevel, double ssgLevel, double gain)
57 : ssgMultiplier(static_cast<uint16_t>(std::pow(10.0, (ssgLevel + gain - fmLevel) / 20.0) * 0x100) | 0x8000) {}
58 };
59
60 void writeVgm(BinaryContainer& container, int target, const std::vector<uint8_t>& samples,
61 uint32_t clock, uint32_t rate, bool loopFlag, uint32_t loopPoint,
62 uint32_t loopSamples, uint32_t totalSamples, const GD3Tag* tag, const VgmMix* mix);
63
64 // S98 ----------
65 struct S98Tag
66 {
67 std::string title;
68 std::string artist;
69 std::string game;
70 std::string year;
71 std::string genre;
72 std::string comment;
73 std::string copyright;
74 std::string s98by;
75 std::string system;
76 };
77
78 void writeS98(BinaryContainer& container, int target, const std::vector<uint8_t>& samples,
79 uint32_t clock, uint32_t rate, bool loopFlag, uint32_t loopPoint,
80 bool tagEnabled, const S98Tag& tag);
81
82 enum ExportTargetFlag
83 {
84 /* target bits 0-3 : FM type */
85 Export_NoneFm = 0,
86 Export_YM2608 = 1,
87 Export_YM2612 = 2,
88 Export_YM2203 = 4,
89 Export_YM2610B = 8,
90 Export_FmMask = Export_NoneFm | Export_YM2608 | Export_YM2612 | Export_YM2203 | Export_YM2610B,
91 /* target bit 4-5 : SSG type */
92 Export_InternalSsg = 0,
93 Export_AY8910Psg = 16,
94 Export_YM2149Psg = 32,
95 Export_SsgMask = Export_InternalSsg|Export_AY8910Psg|Export_YM2149Psg,
96 };
97 }