This isn’t perfect because there are still some inconsistencies in how the exports act when applied to the current project, but it’s a better solution than just changing the default to 24-bit. It adds two new Macro commands, “Export as WAV (24-bit)” and “Export as WAV (32-bit float)”.
Note that this diff is against the current Audacity 2.3.3 alpha code.
Note also that the current alpha code has some new bugs and is NOT recommended for production work. I think it should be reasonably easy to adapt this to work with the Audacity 2.3.2 source code, or to the release version of 2.3.3 when it comes out.
diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp
index e748cf2..aa460ed 100644
--- a/src/BatchCommands.cpp
+++ b/src/BatchCommands.cpp
@@ -71,6 +71,12 @@ static const std::pair<const wxChar*, CommandID> SpecialCommands[] = {
/* i18n-hint: FLAC names an audio file format */
{ XO("Export as FLAC"), wxT("ExportFLAC") },
+ /* i18n-hint: WAV (24-bit) names an audio file format */
+ { XO("Export as WAV (24-bit)"), wxT("ExportWAV_24") },
+
+ /* i18n-hint: WAV (32-bit float) names an audio file format */
+ { XO("Export as WAV (32-bit float)"), wxT("ExportWAV_FLT") },
+
// MP3 OGG and WAV already handled by menu items.
#if 0
/* i18n-hint: MP3 names an audio file format */
@@ -552,6 +558,30 @@ wxString MacroCommands::BuildCleanFileName(const FilePath &fileName,
return cleanedName;
}
+
+bool MacroCommands::WriteWAVFile( const wxString & Name, int bits )
+{
+ wxString type = "WAV";
+ unsigned numChannels = 2;
+ if (IsMono()) {
+ numChannels = 1;
+ }
+
+ double endTime = GetEndTime();
+ if( endTime <= 0.0f )
+ return false;
+
+ AudacityProject *project = GetActiveProject();
+ if (bits == 24)
+ type = "WAV24";
+ else if (bits == 32)
+ type = "WAVFLT";
+
+ bool rc;
+ rc = mExporter.Process(project, numChannels, type, Name, false, 0.0, endTime);
+ return rc;
+}
+
// TODO Move this out of Batch Commands
bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
{ //check if current project is mono or stereo
@@ -624,6 +654,10 @@ bool MacroCommands::ApplySpecialCommand(
wxString extension; // required for correct message
if (command == wxT("ExportWAV"))
extension = wxT(".wav");
+ else if (command == wxT("ExportWAV_24"))
+ extension = wxT(".wav");
+ else if (command == wxT("ExportWAV_FLT"))
+ extension = wxT(".wav");
else if (command == wxT("ExportOgg"))
extension = wxT(".ogg");
else if (command == wxT("ExportFLAC"))
@@ -669,6 +703,12 @@ bool MacroCommands::ApplySpecialCommand(
return false;
}
return mExporter.Process(project, numChannels, wxT("WAV"), filename, false, 0.0, endTime);
+ } else if (command == wxT("ExportWAV_24")) {
+ filename.Replace(wxT(".mp3"), wxT(".wav"), false);
+ return WriteWAVFile(filename, 24);
+ } else if (command == wxT("ExportWAV_FLT")) {
+ filename.Replace(wxT(".mp3"), wxT(".wav"), false);
+ return WriteWAVFile(filename, 32);
} else if (command == wxT("ExportOgg")) {
#ifdef USE_LIBVORBIS
filename.Replace(wxT(".mp3"), wxT(".ogg"), false);
diff --git a/src/BatchCommands.h b/src/BatchCommands.h
index 6428409..2287132 100644
--- a/src/BatchCommands.h
+++ b/src/BatchCommands.h
@@ -82,6 +82,7 @@ class MacroCommands final {
static wxString BuildCleanFileName(const FilePath &fileName,
const FileExtension &extension);
bool WriteMp3File( const wxString & Name, int bitrate );
+ bool WriteWAVFile( const wxString & Name, int bits );
double GetEndTime();
static bool IsMono();