Skip to content

Commit f44aa3e

Browse files
authored
Refactor OGG export and always use VBR (LMMS#7697)
Refactors `AudioFileOgg`, a class used to export to OGG files. There were problems reported of the exported OGG file failing to be played back on some systems. To fix this issue as well as to improve code quality, the class was refactored. In addition, VBR (variable bit rate) is always used, with the quality of the export being determined by a ratio of the selected bit rate and the maximum bit rate allowed. This change naturally occurred when refactoring, though the libvorbisenc documentation recommend VBR for improved audio quality.
1 parent c12fd57 commit f44aa3e

File tree

7 files changed

+77
-292
lines changed

7 files changed

+77
-292
lines changed

include/AudioFileOgg.h

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -56,56 +56,16 @@ class AudioFileOgg : public AudioFileDevice
5656
return new AudioFileOgg( outputSettings, channels, successful, outputFilename, audioEngine );
5757
}
5858

59-
6059
private:
6160
void writeBuffer(const SampleFrame* _ab, const fpp_t _frames) override;
62-
63-
bool startEncoding();
64-
void finishEncoding();
65-
inline int writePage();
66-
67-
inline bitrate_t nominalBitrate() const
68-
{
69-
return getOutputSettings().getBitRateSettings().getBitRate();
70-
}
71-
72-
inline bitrate_t minBitrate() const
73-
{
74-
if (nominalBitrate() > 64)
75-
{
76-
return nominalBitrate() - 64;
77-
}
78-
else
79-
{
80-
return 64;
81-
}
82-
}
83-
84-
inline bitrate_t maxBitrate() const
85-
{
86-
return nominalBitrate() + 64;
87-
}
88-
89-
private:
90-
bool m_ok;
91-
ch_cnt_t m_channels;
92-
sample_rate_t m_rate;
93-
94-
uint32_t m_serialNo;
95-
96-
vorbis_comment * m_comments;
97-
98-
// encoding setup - init by init_ogg_encoding
99-
ogg_stream_state m_os;
100-
ogg_page m_og;
101-
ogg_packet m_op;
102-
103-
vorbis_dsp_state m_vd;
104-
vorbis_block m_vb;
105-
vorbis_info m_vi;
106-
107-
} ;
108-
61+
vorbis_info m_vi;
62+
vorbis_dsp_state m_vds;
63+
vorbis_comment m_vc;
64+
vorbis_block m_vb;
65+
ogg_stream_state m_oss;
66+
ogg_packet m_packet;
67+
ogg_page m_page;
68+
};
10969

11070
} // namespace lmms
11171

include/OutputSettings.h

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,50 +49,26 @@ class OutputSettings
4949
Mono
5050
};
5151

52-
class BitRateSettings
53-
{
54-
public:
55-
BitRateSettings(bitrate_t bitRate, bool isVariableBitRate) :
56-
m_bitRate(bitRate),
57-
m_isVariableBitRate(isVariableBitRate)
58-
{}
59-
60-
bool isVariableBitRate() const { return m_isVariableBitRate; }
61-
void setVariableBitrate(bool variableBitRate = true) { m_isVariableBitRate = variableBitRate; }
62-
63-
bitrate_t getBitRate() const { return m_bitRate; }
64-
void setBitRate(bitrate_t bitRate) { m_bitRate = bitRate; }
65-
66-
private:
67-
bitrate_t m_bitRate;
68-
bool m_isVariableBitRate;
69-
};
70-
7152
public:
72-
OutputSettings( sample_rate_t sampleRate,
73-
BitRateSettings const & bitRateSettings,
74-
BitDepth bitDepth,
75-
StereoMode stereoMode ) :
76-
m_sampleRate(sampleRate),
77-
m_bitRateSettings(bitRateSettings),
78-
m_bitDepth(bitDepth),
79-
m_stereoMode(stereoMode),
80-
m_compressionLevel(0.625) // 5/8
53+
OutputSettings(sample_rate_t sampleRate, bitrate_t bitRate, BitDepth bitDepth, StereoMode stereoMode)
54+
: m_sampleRate(sampleRate)
55+
, m_bitRate(bitRate)
56+
, m_bitDepth(bitDepth)
57+
, m_stereoMode(stereoMode)
58+
, m_compressionLevel(0.625) // 5/8
8159
{
8260
}
8361

84-
OutputSettings( sample_rate_t sampleRate,
85-
BitRateSettings const & bitRateSettings,
86-
BitDepth bitDepth ) :
87-
OutputSettings(sampleRate, bitRateSettings, bitDepth, StereoMode::Stereo )
62+
OutputSettings(sample_rate_t sampleRate, bitrate_t bitRate, BitDepth bitDepth)
63+
: OutputSettings(sampleRate, bitRate, bitDepth, StereoMode::Stereo)
8864
{
8965
}
9066

9167
sample_rate_t getSampleRate() const { return m_sampleRate; }
9268
void setSampleRate(sample_rate_t sampleRate) { m_sampleRate = sampleRate; }
9369

94-
BitRateSettings const & getBitRateSettings() const { return m_bitRateSettings; }
95-
void setBitRateSettings(BitRateSettings const & bitRateSettings) { m_bitRateSettings = bitRateSettings; }
70+
bitrate_t bitrate() const { return m_bitRate; }
71+
void setBitrate(bitrate_t bitrate) { m_bitRate = bitrate; }
9672

9773
BitDepth getBitDepth() const { return m_bitDepth; }
9874
void setBitDepth(BitDepth bitDepth) { m_bitDepth = bitDepth; }
@@ -109,7 +85,7 @@ class OutputSettings
10985

11086
private:
11187
sample_rate_t m_sampleRate;
112-
BitRateSettings m_bitRateSettings;
88+
bitrate_t m_bitRate;
11389
BitDepth m_bitDepth;
11490
StereoMode m_stereoMode;
11591
double m_compressionLevel;

src/core/audio/AudioFileMP3.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ bool AudioFileMP3::initEncoder()
113113
lame_set_mode(m_lame, mapToMPEG_mode(stereoMode));
114114

115115
// Handle bit rate settings
116-
OutputSettings::BitRateSettings bitRateSettings = getOutputSettings().getBitRateSettings();
117-
int bitRate = static_cast<int>(bitRateSettings.getBitRate());
116+
int bitRate = static_cast<int>(getOutputSettings().bitrate());
118117

119118
lame_set_VBR(m_lame, vbr_off);
120119
lame_set_brate(m_lame, bitRate);

0 commit comments

Comments
 (0)