11// ------------------------------------------------------------------------------
22//
3- // Copyright 2013-2023 BBC Research and Development
3+ // Copyright 2013-2024 BBC Research and Development
44//
55// Author: Chris Needham
66//
5151
5252// ------------------------------------------------------------------------------
5353
54- static std::string getFileExtension (const boost::filesystem::path& filename)
55- {
56- std::string extension = filename.extension ().string ();
57-
58- // Remove leading "."
59- if (!extension.empty ()) {
60- extension.erase (0 , 1 );
61- }
62-
63- return extension;
64- }
65-
66- // ------------------------------------------------------------------------------
67-
68- static FileFormat::FileFormat getFormatFromFileExtension (
69- const boost::filesystem::path& filename)
70- {
71- return FileFormat::fromString (getFileExtension (filename));
72- }
73-
74- // ------------------------------------------------------------------------------
75-
76- static FileFormat::FileFormat getInputFormat (
77- const Options& options,
78- const boost::filesystem::path& filename)
79- {
80- return options.hasInputFormat () ?
81- FileFormat::fromString (options.getInputFormat ()) :
82- getFormatFromFileExtension (filename);
83- }
84-
85- // ------------------------------------------------------------------------------
86-
87- static FileFormat::FileFormat getOutputFormat (
88- const Options& options,
89- const boost::filesystem::path& filename)
90- {
91- return options.hasOutputFormat () ?
92- FileFormat::fromString (options.getOutputFormat ()) :
93- getFormatFromFileExtension (filename);
94- }
95-
96- // ------------------------------------------------------------------------------
97-
9854static std::unique_ptr<AudioFileReader> createAudioFileReader (
9955 const boost::filesystem::path& input_filename,
10056 const FileFormat::FileFormat input_format,
@@ -113,14 +69,13 @@ static std::unique_ptr<AudioFileReader> createAudioFileReader(
11369 }
11470 else if (input_format == FileFormat::Raw) {
11571 SndFileAudioFileReader* sndfile_audio_file_reader = new SndFileAudioFileReader;
72+ reader.reset (sndfile_audio_file_reader);
11673
11774 sndfile_audio_file_reader->configure (
11875 options.getRawAudioChannels (),
11976 options.getRawAudioSampleRate (),
12077 options.getRawAudioFormat ()
12178 );
122-
123- reader.reset (sndfile_audio_file_reader);
12479 }
12580 else {
12681 throwError (" Unknown file type: %1%" , input_filename);
@@ -184,7 +139,7 @@ static std::pair<bool, double> getDuration(
184139 const Options& options)
185140{
186141 bool verbose = !options.getQuiet ();
187-
142+
188143 std::unique_ptr<AudioFileReader> audio_file_reader (
189144 createAudioFileReader (input_filename, input_format, options)
190145 );
@@ -736,17 +691,17 @@ bool OptionHandler::run(const Options& options)
736691 bool success = true ;
737692
738693 try {
739- const boost::filesystem::path input_filename =
694+ const boost::filesystem::path& input_filename =
740695 options.getInputFilename ();
741696
742- const boost::filesystem::path output_filename =
697+ const boost::filesystem::path& output_filename =
743698 options.getOutputFilename ();
744699
745700 const FileFormat::FileFormat input_format =
746- getInputFormat (options, input_filename );
701+ options. getInputFormat ();
747702
748703 const FileFormat::FileFormat output_format =
749- getOutputFormat (options, output_filename );
704+ options. getOutputFormat ();
750705
751706 if (shouldConvertAudioFormat (input_format, output_format)) {
752707 success = convertAudioFormat (
0 commit comments