From 53eb72103daf813046286ca499467cb1216bd148 Mon Sep 17 00:00:00 2001 From: James Crook Date: Mon, 15 Jul 2019 11:38:24 +0100 Subject: [PATCH] Bug 2099 - 24-bit WAV (and AIFF) export is wrongly limited to 3GB Bug 2100 - AIFF exports GT 4GB are trapped but error message is only "WAV" --- src/FileFormats.cpp | 23 +++++++++++++++++++++++ src/FileFormats.h | 1 + src/export/ExportPCM.cpp | 15 ++------------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/FileFormats.cpp b/src/FileFormats.cpp index 4baf0e31b..28341da5a 100644 --- a/src/FileFormats.cpp +++ b/src/FileFormats.cpp @@ -202,6 +202,29 @@ bool sf_subtype_is_integer(unsigned int format) subtype == SF_FORMAT_PCM_32); } +int sf_subtype_bytes_per_sample(unsigned int format){ + unsigned int subtype = format & SF_FORMAT_SUBMASK; + if( subtype == SF_FORMAT_PCM_S8 ) + return 1; + if( subtype == SF_FORMAT_PCM_U8 ) + return 1; + if( subtype == SF_FORMAT_PCM_16 ) + return 2; + if( subtype == SF_FORMAT_PCM_24 ) + return 3; + if( subtype == SF_FORMAT_PCM_32 ) + return 4; + if( subtype == SF_FORMAT_FLOAT ) + return 4; + if( subtype == SF_FORMAT_DOUBLE ) + return 8; + + // might be different to 2, but this is good enough for + // WAV and AIFF file size error trapping. + return 2; +} + + FileExtensions sf_get_all_extensions() { FileExtensions exts; diff --git a/src/FileFormats.h b/src/FileFormats.h index d459c9e36..9fc346cc5 100644 --- a/src/FileFormats.h +++ b/src/FileFormats.h @@ -96,6 +96,7 @@ SF_FORMAT_INFO *sf_simple_format(int i); bool sf_subtype_more_than_16_bits(unsigned int format); bool sf_subtype_is_integer(unsigned int format); +int sf_subtype_bytes_per_sample(unsigned int format); extern FileExtensions sf_get_all_extensions(); diff --git a/src/export/ExportPCM.cpp b/src/export/ExportPCM.cpp index ded2a9de3..9d45c4c30 100644 --- a/src/export/ExportPCM.cpp +++ b/src/export/ExportPCM.cpp @@ -396,22 +396,12 @@ ExportPCM::ExportPCM() SetMaxChannels(255, format); } -// Bug 2057 -// This function is not yet called anywhere. -// It is provided to get the translation strings. -// We can hook it in properly whilst translation happens. void ExportPCM::ReportTooBigError(wxWindow * pParent) { //Temporary translation hack, to say 'WAV or AIFF' rather than 'WAV' wxString message = - _("You have attempted to Export a WAV file which would be greater than 4GB.\n" + _("You have attempted to Export a WAV or AIFF file which would be greater than 4GB.\n" "Audacity cannot do this, the Export was abandoned."); - if( message == - "You have attempted to Export a WAV file which would be greater than 4GB.\n" - "Audacity cannot do this, the Export was abandoned.") - { - message.Replace( "WAV", "WAV or AIFF"); - } ShowErrorDialog(pParent, _("Error Exporting"), message, wxT("Size_limits_for_WAV_and_AIFF_files")); @@ -521,8 +511,7 @@ ProgressResult ExportPCM::Export(AudacityProject *project, format = int16Sample; float sampleCount = (float)(t1-t0)*rate*info.channels; - // floatSamples are always 4 byte, even if processor uses more. - float byteCount = sampleCount * ((format==int16Sample)?2:4); + float byteCount = sampleCount * sf_subtype_bytes_per_sample( info.format); // Test for 4 Gibibytes, rather than 4 Gigabytes if( byteCount > 4.295e9) {