Simplification of code and structure in the area of the file export

Pull the class OutputSettings out of the class ProjectRenderer so that
it can be used in other contexts as well. Also move the enum
ProjectRenderer::Depth into the new class OutputSettings and rename it
to BitDepth. Adjust all places that referenced
ProjectRenderer::OutputSettings accordingly.

Adjust the two places where an instance of OutputSettings is created:
the main function and ExportProjectDialog::startExport.

Store an instance of OutputSettings in AudioFileDevice and remove
several members and methods which are now replaced by this instance. Add
a getter for the OutputSettings to AudioFileDevice. Storing an instance
of OutputSettings in the base class AudioFileDevice enables the
simplification of the following constructors and general code in the
following classes:
* AudioFileDevice
* AudioFileOgg
* AudioFileWave

Because OutputSettings contains everything related to sample rate, bit
rate settings and bit depth these parameters could be removed from the
parameter list of the aforementioned constructors.

Simplify the signature of the factory method AudioFileDeviceInstantiaton
(defined in AudioFileDevice.h) and reorder the parameters by significance.

Move the logic of how the minimum and maximum bitrate is calculated
using the nominal bitrate into AudioFileOgg::minBitrate() and
AudioFileOgg::maxBitrate(). Previously this was defined in the
constructor of ProjectRenderer where it does not belong as it an
implementation detail of the OGG export.

Remove the code that converted the bit depth enum to an integer from
ProjectRenderer as it is now solely represented as an enum.

Remove class members for the minimum and maximum bit rate from
AudioFileOgg and adjust the code in the implementation to use the values
stored in OutputSettings.
This commit is contained in:
Michael Gregorius
2017-04-29 15:00:54 +02:00
parent 4196a30415
commit d5fc38ebd9
13 changed files with 213 additions and 236 deletions

View File

@@ -60,51 +60,32 @@ const ProjectRenderer::FileEncodeDevice ProjectRenderer::fileEncodeDevices[] =
ProjectRenderer::ProjectRenderer( const Mixer::qualitySettings & _qs,
const OutputSettings & _os,
ExportFileFormats _file_format,
const QString & _out_file ) :
ProjectRenderer::ProjectRenderer( const Mixer::qualitySettings & qualitySettings,
const OutputSettings & outputSettings,
ExportFileFormats exportFileFormat,
const QString & outputFilename ) :
QThread( Engine::mixer() ),
m_fileDev( NULL ),
m_qualitySettings( _qs ),
m_qualitySettings( qualitySettings ),
m_oldQualitySettings( Engine::mixer()->currentQualitySettings() ),
m_progress( 0 ),
m_abort( false )
{
if( fileEncodeDevices[_file_format].m_getDevInst == NULL )
{
return;
}
AudioFileDeviceInstantiaton audioEncoderFactory = fileEncodeDevices[exportFileFormat].m_getDevInst;
int depth;
switch (_os.depth)
if (audioEncoderFactory)
{
case Depth_16Bit:
depth = 16;
break;
case Depth_24Bit:
depth = 24;
break;
case Depth_32Bit:
depth = 32;
break;
default:
// If this line is reached the enum has been extended without taking care here
Q_ASSERT(false);
}
bool successful = false;
bool successful = false;
m_fileDev = fileEncodeDevices[_file_format].m_getDevInst(
_os.samplerate, DEFAULT_CHANNELS, successful,
_out_file, _os.vbr,
_os.bitrate, _os.bitrate - 64, _os.bitrate + 64,
depth, Engine::mixer() );
if( !successful )
{
delete m_fileDev;
m_fileDev = NULL;
m_fileDev = audioEncoderFactory(
outputFilename, outputSettings, DEFAULT_CHANNELS,
Engine::mixer(), successful );
if( !successful )
{
delete m_fileDev;
m_fileDev = NULL;
}
}
}

View File

@@ -30,9 +30,10 @@
#include "BBTrackContainer.h"
#include "BBTrack.h"
RenderManager::RenderManager(
const Mixer::qualitySettings & qualitySettings,
const ProjectRenderer::OutputSettings & outputSettings,
const OutputSettings & outputSettings,
ProjectRenderer::ExportFileFormats fmt,
QString outputPath) :
m_qualitySettings(qualitySettings),

View File

@@ -30,24 +30,15 @@
#include "GuiApplication.h"
AudioFileDevice::AudioFileDevice( const sample_rate_t _sample_rate,
AudioFileDevice::AudioFileDevice( OutputSettings const & outputSettings,
const ch_cnt_t _channels,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate,
const int _depth,
Mixer* _mixer ) :
AudioDevice( _channels, _mixer ),
m_outputFile( _file ),
m_useVbr( _use_vbr ),
m_nomBitrate( _nom_bitrate ),
m_minBitrate( _min_bitrate ),
m_maxBitrate( _max_bitrate ),
m_depth( _depth )
m_outputSettings(outputSettings)
{
setSampleRate( _sample_rate );
setSampleRate( outputSettings.getSampleRate() );
if( m_outputFile.open( QFile::WriteOnly | QFile::Truncate ) == false )
{

View File

@@ -36,21 +36,14 @@
#include "Mixer.h"
AudioFileOgg::AudioFileOgg( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
bool & _success_ful,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate,
const int _depth,
Mixer* _mixer ) :
AudioFileDevice( _sample_rate, _channels, _file, _use_vbr,
_nom_bitrate, _min_bitrate, _max_bitrate,
_depth, _mixer )
AudioFileOgg::AudioFileOgg( OutputSettings const & outputSettings,
const ch_cnt_t channels,
bool & successful,
const QString & file,
Mixer* mixer ) :
AudioFileDevice( outputSettings, channels, file, mixer )
{
m_ok = _success_ful = outputFileOpened() && startEncoding();
m_ok = successful = outputFileOpened() && startEncoding();
}
@@ -89,18 +82,18 @@ bool AudioFileOgg::startEncoding()
vc.vendor = NULL;
m_channels = channels();
// vbr enabled?
if( useVBR() == 0 )
bool useVariableBitRate = getOutputSettings().getBitRateSettings().isVariableBitRate();
bitrate_t minimalBitrate = nominalBitrate();
bitrate_t maximumBitrate = nominalBitrate();
if( useVariableBitRate )
{
m_minBitrate = nominalBitrate(); // min for vbr
m_maxBitrate = nominalBitrate(); // max for vbr
}
else
{
m_minBitrate = minBitrate(); // min for vbr
m_maxBitrate = maxBitrate(); // max for vbr
minimalBitrate = minBitrate(); // min for vbr
maximumBitrate = maxBitrate(); // max for vbr
}
m_rate = sampleRate(); // default-samplerate
if( m_rate > 48000 )
{
@@ -114,9 +107,9 @@ bool AudioFileOgg::startEncoding()
vorbis_info_init( &m_vi );
if( vorbis_encode_setup_managed( &m_vi, m_channels, m_rate,
( m_maxBitrate > 0 )? m_maxBitrate * 1000 : -1,
( maximumBitrate > 0 )? maximumBitrate * 1000 : -1,
nominalBitrate() * 1000,
( m_minBitrate > 0 )? m_minBitrate * 1000 : -1 ) )
( minimalBitrate > 0 )? minimalBitrate * 1000 : -1 ) )
{
printf( "Mode initialization failed: invalid parameters for "
"bitrate\n" );
@@ -125,15 +118,15 @@ bool AudioFileOgg::startEncoding()
return false;
}
if( useVBR() == false )
{
vorbis_encode_ctl( &m_vi, OV_ECTL_RATEMANAGE_AVG, NULL );
}
else if( useVBR() == true )
if( useVariableBitRate )
{
// Turn off management entirely (if it was turned on).
vorbis_encode_ctl( &m_vi, OV_ECTL_RATEMANAGE_SET, NULL );
}
else
{
vorbis_encode_ctl( &m_vi, OV_ECTL_RATEMANAGE_AVG, NULL );
}
vorbis_encode_setup_init( &m_vi );

View File

@@ -28,21 +28,14 @@
#include "Mixer.h"
AudioFileWave::AudioFileWave( const sample_rate_t _sample_rate,
const ch_cnt_t _channels, bool & _success_ful,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate,
const int _depth,
Mixer* _mixer ) :
AudioFileDevice( _sample_rate, _channels, _file, _use_vbr,
_nom_bitrate, _min_bitrate, _max_bitrate,
_depth, _mixer ),
AudioFileWave::AudioFileWave( OutputSettings const & outputSettings,
const ch_cnt_t channels, bool & successful,
const QString & file,
Mixer* mixer ) :
AudioFileDevice( outputSettings, channels, file, mixer ),
m_sf( NULL )
{
_success_ful = outputFileOpened() && startEncoding();
successful = outputFileOpened() && startEncoding();
}
@@ -66,15 +59,15 @@ bool AudioFileWave::startEncoding()
m_si.format = SF_FORMAT_WAV;
switch( depth() )
switch( getOutputSettings().getBitDepth() )
{
case 32:
case OutputSettings::Depth_32Bit:
m_si.format |= SF_FORMAT_FLOAT;
break;
case 24:
case OutputSettings::Depth_24Bit:
m_si.format |= SF_FORMAT_PCM_24;
break;
case 16:
case OutputSettings::Depth_16Bit:
default:
m_si.format |= SF_FORMAT_PCM_16;
break;
@@ -97,7 +90,9 @@ void AudioFileWave::writeBuffer( const surroundSampleFrame * _ab,
const fpp_t _frames,
const float _master_gain )
{
if( depth() == 32 || depth() == 24 )
OutputSettings::BitDepth bitDepth = getOutputSettings().getBitDepth();
if( bitDepth == OutputSettings::Depth_32Bit || bitDepth == OutputSettings::Depth_24Bit )
{
float * buf = new float[_frames*channels()];
for( fpp_t frame = 0; frame < _frames; ++frame )

View File

@@ -65,6 +65,7 @@
#include "GuiApplication.h"
#include "ImportFilter.h"
#include "MainWindow.h"
#include "OutputSettings.h"
#include "ProjectRenderer.h"
#include "RenderManager.h"
#include "Song.h"
@@ -259,8 +260,7 @@ int main( int argc, char * * argv )
new MainApplication( argc, argv );
Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality );
ProjectRenderer::OutputSettings os( 44100, false, 160,
ProjectRenderer::Depth_16Bit );
OutputSettings os( 44100, OutputSettings::BitRateSettings(160, false), OutputSettings::Depth_16Bit );
ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile;
// second of two command-line parsing stages
@@ -414,7 +414,7 @@ int main( int argc, char * * argv )
sample_rate_t sr = QString( argv[i] ).toUInt();
if( sr >= 44100 && sr <= 192000 )
{
os.samplerate = sr;
os.setSampleRate(sr);
}
else
{
@@ -439,7 +439,9 @@ int main( int argc, char * * argv )
if( br >= 64 && br <= 384 )
{
os.bitrate = br;
OutputSettings::BitRateSettings bitRateSettings = os.getBitRateSettings();
bitRateSettings.setBitRate(br);
os.setBitRateSettings(bitRateSettings);
}
else
{
@@ -450,7 +452,7 @@ int main( int argc, char * * argv )
}
else if( arg =="--float" || arg == "-a" )
{
os.depth = ProjectRenderer::Depth_32Bit;
os.setBitDepth(OutputSettings::Depth_32Bit);
}
else if( arg == "--interpolation" || arg == "-i" )
{

View File

@@ -31,6 +31,7 @@
#include "Song.h"
#include "GuiApplication.h"
#include "MainWindow.h"
#include "OutputSettings.h"
ExportProjectDialog::ExportProjectDialog( const QString & _file_name,
@@ -137,13 +138,13 @@ void ExportProjectDialog::startExport()
static_cast<Mixer::qualitySettings::Oversampling>(oversamplingCB->currentIndex()) );
const int samplerates[5] = { 44100, 48000, 88200, 96000, 192000 };
const int bitrates[6] = { 64, 128, 160, 192, 256, 320 };
const bitrate_t bitrates[6] = { 64, 128, 160, 192, 256, 320 };
ProjectRenderer::OutputSettings os = ProjectRenderer::OutputSettings(
OutputSettings::BitRateSettings bitRateSettings(bitrates[ bitrateCB->currentIndex() ], false);
OutputSettings os = OutputSettings(
samplerates[ samplerateCB->currentIndex() ],
false,
bitrates[ bitrateCB->currentIndex() ],
static_cast<ProjectRenderer::Depths>( depthCB->currentIndex() ) );
bitRateSettings,
static_cast<OutputSettings::BitDepth>( depthCB->currentIndex() ) );
m_renderManager = new RenderManager( qs, os, m_ft, m_fileName );