Skip to content

Commit 0221601

Browse files
committed
Add AudioSampleFormat to SoundTrackFormat
1 parent 0d9133a commit 0221601

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

src/framework/audio/common/audiotypes.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,47 @@ enum class SoundTrackType {
105105
WAV
106106
};
107107

108+
enum class AudioSampleFormat {
109+
Undefined = 0,
110+
Int16,
111+
Int24,
112+
Float32
113+
};
114+
108115
struct SoundTrackFormat {
109116
SoundTrackType type = SoundTrackType::Undefined;
110117
OutputSpec outputSpec;
118+
AudioSampleFormat sampleFormat = AudioSampleFormat::Undefined;
111119
int bitRate = 0;
112120

113121
bool operator==(const SoundTrackFormat& other) const
114122
{
115123
return type == other.type
116124
&& outputSpec == other.outputSpec
125+
&& sampleFormat == other.sampleFormat
117126
&& bitRate == other.bitRate;
118127
}
119128

120129
bool isValid() const
121130
{
122-
return type != SoundTrackType::Undefined && outputSpec.isValid();
131+
if (!outputSpec.isValid()) {
132+
return false;
133+
}
134+
135+
switch (type) {
136+
case SoundTrackType::WAV:
137+
case SoundTrackType::FLAC:
138+
// For lossless/uncompressed, sample format must be defined
139+
return sampleFormat != AudioSampleFormat::Undefined;
140+
141+
case SoundTrackType::MP3:
142+
case SoundTrackType::OGG:
143+
// For lossy, bitrate must be positive
144+
return bitRate > 0;
145+
146+
default:
147+
return false;
148+
}
123149
}
124150
};
125151

src/framework/audio/common/rpc/rpcpacker.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::SoundPreset& value);
6363

6464
void pack_custom(muse::msgpack::Packer& p, const muse::audio::SoundTrackType& value);
6565
void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::SoundTrackType& value);
66+
void pack_custom(muse::msgpack::Packer& p, const muse::audio::AudioSampleFormat& value);
67+
void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::AudioSampleFormat& value);
6668
void pack_custom(muse::msgpack::Packer& p, const muse::audio::SoundTrackFormat& value);
6769
void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::SoundTrackFormat& value);
6870

@@ -259,14 +261,26 @@ inline void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::SoundTrackTyp
259261
value = static_cast<muse::audio::SoundTrackType>(type);
260262
}
261263

264+
inline void pack_custom(muse::msgpack::Packer& p, const muse::audio::AudioSampleFormat& value)
265+
{
266+
p.process(static_cast<int>(value));
267+
}
268+
269+
inline void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::AudioSampleFormat& value)
270+
{
271+
int format = 0;
272+
p.process(format);
273+
value = static_cast<muse::audio::AudioSampleFormat>(format);
274+
}
275+
262276
inline void pack_custom(muse::msgpack::Packer& p, const muse::audio::SoundTrackFormat& value)
263277
{
264-
p.process(value.type, value.outputSpec, value.bitRate);
278+
p.process(value.type, value.outputSpec, value.sampleFormat, value.bitRate);
265279
}
266280

267281
inline void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::SoundTrackFormat& value)
268282
{
269-
p.process(value.type, value.outputSpec, value.bitRate);
283+
p.process(value.type, value.outputSpec, value.sampleFormat, value.bitRate);
270284
}
271285

272286
inline void pack_custom(muse::msgpack::Packer& p, const muse::audio::AudioSignalVal& value)

src/importexport/audioexport/internal/flacwriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ muse::Ret FlacWriter::write(notation::INotationPtr notation, muse::io::IODevice&
3737
configuration()->exportBufferSize(),
3838
2 /* audioChannelsNumber */
3939
},
40-
128 /* bitRate */
40+
AudioSampleFormat::Int16,
41+
0 /* bitRate */
4142
};
4243

4344
return doWriteAndWait(notation, destinationDevice, format);

src/importexport/audioexport/internal/mp3writer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Ret Mp3Writer::write(notation::INotationPtr notation, io::IODevice& destinationD
3737
configuration()->exportBufferSize(),
3838
2 /* audioChannelsNumber */
3939
},
40+
AudioSampleFormat::Undefined,
4041
configuration()->exportMp3Bitrate()
4142
};
4243

src/importexport/audioexport/internal/oggwriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Ret OggWriter::write(notation::INotationPtr notation, io::IODevice& destinationD
3838
configuration()->exportBufferSize(),
3939
2 /* audioChannelsNumber */
4040
},
41+
AudioSampleFormat::Undefined,
4142
128 /* bitRate */
4243
};
4344

src/importexport/audioexport/internal/wavewriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Ret WaveWriter::write(notation::INotationPtr notation, io::IODevice& destination
3737
configuration()->exportBufferSize(),
3838
2 /* audioChannelsNumber */
3939
},
40+
AudioSampleFormat::Float32,
4041
0 /* bitRate */
4142
};
4243

0 commit comments

Comments
 (0)