Skip to content

Commit c07974e

Browse files
committed
Merge pull request godotengine#107250 from DeeJayLSP/wav-load-no-constructor
AudioStreamWAV: Inline tag remap inside load
2 parents e0ca031 + afcc647 commit c07974e

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

scene/resources/audio_stream_wav.cpp

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,6 @@ Dictionary AudioStreamWAV::get_tags() const {
485485
return tags;
486486
}
487487

488-
HashMap<String, String>::ConstIterator AudioStreamWAV::remap_tag_id(const String &p_tag_id) {
489-
return tag_id_remaps.find(p_tag_id);
490-
}
491-
492488
double AudioStreamWAV::get_length() const {
493489
int len = data_bytes;
494490
switch (format) {
@@ -1146,16 +1142,37 @@ Ref<AudioStreamWAV> AudioStreamWAV::load_from_buffer(const Vector<uint8_t> &p_st
11461142
sample->set_loop_end(loop_end);
11471143
sample->set_stereo(format_channels == 2);
11481144

1149-
Dictionary tag_dictionary;
1150-
for (const KeyValue<String, String> &E : tag_map) {
1151-
HashMap<String, String>::ConstIterator remap = sample->remap_tag_id(E.key);
1152-
if (remap) {
1153-
tag_map.replace_key(E.key, remap->value);
1154-
}
1145+
if (!tag_map.is_empty()) {
1146+
// Used to make the metadata tags more unified across different AudioStreams.
1147+
// See https://www.recordingblogs.com/wiki/list-chunk-of-a-wave-file
1148+
HashMap<String, String> tag_id_remaps;
1149+
tag_id_remaps.reserve(15);
1150+
tag_id_remaps["IARL"] = "location";
1151+
tag_id_remaps["IART"] = "artist";
1152+
tag_id_remaps["ICMS"] = "organization";
1153+
tag_id_remaps["ICMT"] = "comments";
1154+
tag_id_remaps["ICOP"] = "copyright";
1155+
tag_id_remaps["ICRD"] = "date";
1156+
tag_id_remaps["IGNR"] = "genre";
1157+
tag_id_remaps["IKEY"] = "keywords";
1158+
tag_id_remaps["IMED"] = "medium";
1159+
tag_id_remaps["INAM"] = "title";
1160+
tag_id_remaps["IPRD"] = "album";
1161+
tag_id_remaps["ISBJ"] = "description";
1162+
tag_id_remaps["ISFT"] = "software";
1163+
tag_id_remaps["ITRK"] = "tracknumber";
1164+
Dictionary tag_dictionary;
1165+
for (const KeyValue<String, String> &E : tag_map) {
1166+
HashMap<String, String>::ConstIterator remap = tag_id_remaps.find(E.key);
1167+
String tag_key = E.key;
1168+
if (remap) {
1169+
tag_key = remap->value;
1170+
}
11551171

1156-
tag_dictionary[E.key] = E.value;
1172+
tag_dictionary[tag_key] = E.value;
1173+
}
1174+
sample->set_tags(tag_dictionary);
11571175
}
1158-
sample->set_tags(tag_dictionary);
11591176

11601177
return sample;
11611178
}
@@ -1215,22 +1232,3 @@ void AudioStreamWAV::_bind_methods() {
12151232
BIND_ENUM_CONSTANT(LOOP_PINGPONG);
12161233
BIND_ENUM_CONSTANT(LOOP_BACKWARD);
12171234
}
1218-
1219-
AudioStreamWAV::AudioStreamWAV() {
1220-
// Used to make the metadata tags more unified across different AudioStreams.
1221-
// See https://www.recordingblogs.com/wiki/list-chunk-of-a-wave-file
1222-
tag_id_remaps["IARL"] = "location";
1223-
tag_id_remaps["IART"] = "artist";
1224-
tag_id_remaps["ICMS"] = "organization";
1225-
tag_id_remaps["ICMT"] = "comments";
1226-
tag_id_remaps["ICOP"] = "copyright";
1227-
tag_id_remaps["ICRD"] = "date";
1228-
tag_id_remaps["IGNR"] = "genre";
1229-
tag_id_remaps["IKEY"] = "keywords";
1230-
tag_id_remaps["IMED"] = "medium";
1231-
tag_id_remaps["INAM"] = "title";
1232-
tag_id_remaps["IPRD"] = "album";
1233-
tag_id_remaps["ISBJ"] = "description";
1234-
tag_id_remaps["ISFT"] = "software";
1235-
tag_id_remaps["ITRK"] = "tracknumber";
1236-
}

scene/resources/audio_stream_wav.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class AudioStreamWAV : public AudioStream {
124124
LocalVector<uint8_t> data;
125125
uint32_t data_bytes = 0;
126126

127-
HashMap<String, String> tag_id_remaps;
128127
Dictionary tags;
129128

130129
protected:
@@ -155,8 +154,6 @@ class AudioStreamWAV : public AudioStream {
155154
void set_tags(const Dictionary &p_tags);
156155
virtual Dictionary get_tags() const override;
157156

158-
HashMap<String, String>::ConstIterator remap_tag_id(const String &p_tag_id);
159-
160157
virtual double get_length() const override; //if supported, otherwise return 0
161158

162159
virtual bool is_monophonic() const override;
@@ -292,8 +289,6 @@ class AudioStreamWAV : public AudioStream {
292289
dst_ptr += qoa_encode_frame(data16.ptr(), p_desc, frame_len, dst_ptr);
293290
}
294291
}
295-
296-
AudioStreamWAV();
297292
};
298293

299294
VARIANT_ENUM_CAST(AudioStreamWAV::Format)

0 commit comments

Comments
 (0)