traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src audiofileio/encode/AbstractAudioWr...


From: Ben Levitt
Subject: [Traverso-commit] traverso/src audiofileio/encode/AbstractAudioWr...
Date: Wed, 15 Aug 2007 00:18:52 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Ben Levitt <benjie>     07/08/15 00:18:52

Modified files:
        src/audiofileio/encode: AbstractAudioWriter.cpp 
                                WPAudioWriter.cpp WPAudioWriter.h 
        src/commands   : AudioClipExternalProcessing.cpp 
        src/core       : AudioClip.cpp WriteSource.cpp 
        src/traverso   : ExportWidget.cpp 

Log message:
        - change create_audio_writer() to take sndfile and wavpack, instead of 
sf, wp
        - move WPAudioWriter::write_private()'s tmp_buffer to be a member var
        - add wavpack quality settings via WPAudioWriter::set_format_attribute()

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/encode/AbstractAudioWriter.cpp?cvsroot=traverso&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/encode/WPAudioWriter.cpp?cvsroot=traverso&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/encode/WPAudioWriter.h?cvsroot=traverso&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/AudioClipExternalProcessing.cpp?cvsroot=traverso&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.119&r2=1.120
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/WriteSource.cpp?cvsroot=traverso&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/ExportWidget.cpp?cvsroot=traverso&r1=1.53&r2=1.54

Patches:
Index: audiofileio/encode/AbstractAudioWriter.cpp
===================================================================
RCS file: 
/sources/traverso/traverso/src/audiofileio/encode/AbstractAudioWriter.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- audiofileio/encode/AbstractAudioWriter.cpp  14 Aug 2007 04:12:57 -0000      
1.5
+++ audiofileio/encode/AbstractAudioWriter.cpp  15 Aug 2007 00:18:49 -0000      
1.6
@@ -124,10 +124,10 @@
 // Static method used by other classes to get an AudioWriter for the correct 
file type
 AbstractAudioWriter* AbstractAudioWriter::create_audio_writer(const QString& 
type)
 {
-       if (type == "sf") {
+       if (type == "sndfile") {
                return new SFAudioWriter();
        }
-       else if (libwavpack_is_present && type == "wp") {
+       else if (libwavpack_is_present && type == "wavpack") {
                return new WPAudioWriter();
        }
        /*else if (type == "mad") {

Index: audiofileio/encode/WPAudioWriter.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/audiofileio/encode/WPAudioWriter.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- audiofileio/encode/WPAudioWriter.cpp        14 Aug 2007 19:41:42 -0000      
1.8
+++ audiofileio/encode/WPAudioWriter.cpp        15 Aug 2007 00:18:50 -0000      
1.9
@@ -34,6 +34,9 @@
        m_wp = 0;
        m_firstBlock = 0;
        m_firstBlockSize = 0;
+       m_tmp_buffer = 0;
+       m_tmpBufferSize = 0;
+       m_qualityFlags = 0;
 }
 
 
@@ -53,6 +56,47 @@
 }
 
 
+bool WPAudioWriter::set_format_attribute(const QString& key, const QString& 
value)
+{
+       if (key == "quality") {
+               // Clear quality before or-ing in the new quality value
+               m_qualityFlags &= ~(CONFIG_FAST_FLAG | CONFIG_HIGH_FLAG | 
CONFIG_VERY_HIGH_FLAG);
+               
+               if (value == "fast") {
+                       m_qualityFlags |= CONFIG_FAST_FLAG;
+                       return true;
+               }
+               else if (value == "high") {
+                       // CONFIG_HIGH_FLAG (default) ~ 1.5 times slower then 
FAST, ~ 20% extra compression then FAST
+                       m_qualityFlags |= CONFIG_HIGH_FLAG;
+                       return true;
+               }
+               else if (value == "very_high") {
+                       // CONFIG_VERY_HIGH_FLAG ~ 2 times slower then FAST, ~ 
25 % extra compression then FAST
+                       m_qualityFlags |= CONFIG_VERY_HIGH_FLAG;
+                       return true;
+               }
+       }
+       
+       if (key == "skip_wvx") {
+               if (value == "true") {
+                       // This option reduces the storage of some 
floating-point data files by up to about 10% by eliminating some 
+                       // information that has virtually no effect on the 
audio data. While this does technically make the compression 
+                       // lossy, it retains all the advantages of floating 
point data (>600 dB of dynamic range, no clipping, and 25 bits 
+                       // of resolution). This also affects large integer 
compression by limiting the resolution to 24 bits.
+                       m_qualityFlags |= CONFIG_SKIP_WVX;
+                       return true;
+               }
+               else if (value == "false") {
+                       m_qualityFlags &= ~CONFIG_SKIP_WVX;
+                       return true;
+               }
+       }
+       
+       return false;
+}
+
+
 bool WPAudioWriter::open_private()
 {
        m_file = fopen(m_fileName.toUtf8().data(), "wb");
@@ -74,17 +118,7 @@
        m_config.channel_mask = (m_channels == 2) ? 3 : 4; // Microsoft 
standard (mono = 4, stereo = 3)
        m_config.num_channels = m_channels;
        m_config.sample_rate = m_rate;
-       
-       // Make optional ?
-       
-       // CONFIG_HIGH_FLAG (default) ~ 1.5 times slower then FAST, ~ 20% extra 
compression then FAST
-       // CONFIG_VERY_HIGH_FLAG ~ 2 times slower then FAST, ~ 25 % extra 
compression then FAST
-       m_config.flags |= CONFIG_FAST_FLAG;
-       // This option reduces the storage of some floating-point data files by 
up to about 10% by eliminating some 
-       // information that has virtually no effect on the audio data. While 
this does technically make the compression 
-       // lossy, it retains all the advantages of floating point data (>600 dB 
of dynamic range, no clipping, and 25 bits 
-       // of resolution). This also affects large integer compression by 
limiting the resolution to 24 bits.
-//     m_config.flags |= CONFIG_SKIP_WVX;
+       m_config.flags = m_qualityFlags;
        
        WavpackSetConfiguration(m_wp, &m_config, -1);
        
@@ -170,22 +204,27 @@
        // 8bit or 16bit sample in a 0-padded, int32_t
        // 
        if (m_sampleWidth > 1 && m_sampleWidth < 24) { // Not float, or 32bit 
int, or 24bit int
-               int32_t *tmp_buffer = new int32_t[frameCount * m_channels];
+               if (frameCount > m_tmpBufferSize) {
+                       if (m_tmp_buffer) {
+                               delete [] m_tmp_buffer;
+                       }
+                       m_tmp_buffer = new int32_t[frameCount * m_channels];
+                       m_tmpBufferSize = frameCount;
+               }
                for (nframes_t s = 0; s < frameCount * m_channels; s++) {
                        switch (m_sampleWidth) {
                                case 8:
-                                       tmp_buffer[s] = ((int8_t*)buffer)[s];
+                                       m_tmp_buffer[s] = ((int8_t*)buffer)[s];
                                        break;
                                case 16:
-                                       tmp_buffer[s] = ((int16_t*)buffer)[s];
+                                       m_tmp_buffer[s] = ((int16_t*)buffer)[s];
+                                       break;
+                               default:
+                                       // Less than 24 bit, but not 8 or 16 ?  
This won't end well...
                                        break;
-                               //case 24:
-                               //      tmp_buffer[s] = ((int32_t*)buffer)[s]; 
//FIXME: does this need to read 3 bytes at a time??
-                               //      break;
                        }
                }
-               WavpackPackSamples(m_wp, tmp_buffer, frameCount);
-               delete [] tmp_buffer;
+               WavpackPackSamples(m_wp, m_tmp_buffer, frameCount);
                return frameCount;
        }
        
@@ -201,6 +240,13 @@
        WavpackCloseFile(m_wp);
        fclose(m_file);
        m_wp = 0;
+
+       if (m_tmp_buffer) {
+               delete [] m_tmp_buffer;
+               m_tmp_buffer = 0;
+       }
+       m_tmpBufferSize = 0;
+
        if (m_firstBlock) {
                delete [] m_firstBlock;
                m_firstBlock = 0;

Index: audiofileio/encode/WPAudioWriter.h
===================================================================
RCS file: /sources/traverso/traverso/src/audiofileio/encode/WPAudioWriter.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- audiofileio/encode/WPAudioWriter.h  14 Aug 2007 19:41:43 -0000      1.5
+++ audiofileio/encode/WPAudioWriter.h  15 Aug 2007 00:18:50 -0000      1.6
@@ -37,6 +37,7 @@
        WPAudioWriter();
        ~WPAudioWriter();
        
+       bool set_format_attribute(const QString& key, const QString& value);
        const char* get_extension();
        
 protected:
@@ -53,6 +54,9 @@
        FILE*           m_file;
        char*           m_firstBlock;
        int32_t         m_firstBlockSize;
+       int             m_qualityFlags;
+       int32_t*        m_tmp_buffer;
+       nframes_t       m_tmpBufferSize;
 };
 
 #endif

Index: commands/AudioClipExternalProcessing.cpp
===================================================================
RCS file: 
/sources/traverso/traverso/src/commands/AudioClipExternalProcessing.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- commands/AudioClipExternalProcessing.cpp    14 Aug 2007 10:49:54 -0000      
1.24
+++ commands/AudioClipExternalProcessing.cpp    15 Aug 2007 00:18:51 -0000      
1.25
@@ -65,10 +65,9 @@
                spec->total_frames = spec->end_frame;
                spec->pos = 0;
                spec->isRecording = false;
-               spec->extraFormat["filetype"] = "wav";
        
                spec->exportdir = pm().get_project()->get_root_dir() + 
"/audiosources/";
-               spec->writerType = "sf";
+               spec->writerType = "sndfile";
                spec->extraFormat["filetype"] = "wav";
                spec->data_width = 16;
                spec->channels = 2;

Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -b -r1.119 -r1.120
--- core/AudioClip.cpp  14 Aug 2007 10:49:54 -0000      1.119
+++ core/AudioClip.cpp  15 Aug 2007 00:18:51 -0000      1.120
@@ -560,7 +560,7 @@
                ExportSpecification* spec = new ExportSpecification;
 
                spec->exportdir = pm().get_project()->get_root_dir() + 
"/audiosources/";
-               spec->writerType = "sf";
+               spec->writerType = "sndfile";
                spec->extraFormat["filetype"] = "wav";
                spec->data_width = 1;   // 1 means float
                spec->channels = 1;

Index: core/WriteSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/WriteSource.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- core/WriteSource.cpp        14 Aug 2007 10:49:55 -0000      1.31
+++ core/WriteSource.cpp        15 Aug 2007 00:18:51 -0000      1.32
@@ -266,12 +266,6 @@
                delete m_writer;
        }
        
-       if (m_writer) {
-               delete m_writer;
-       }
-       
-       // Try out using the wavpack writer for all writing by switching these 
lines
-       // m_writer = AbstractAudioWriter::create_audio_writer("wp");
        m_writer = AbstractAudioWriter::create_audio_writer(m_spec->writerType);
        m_writer->set_rate(m_spec->sample_rate);
        m_writer->set_bits_per_sample(m_spec->data_width);

Index: traverso/ExportWidget.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/ExportWidget.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- traverso/ExportWidget.cpp   14 Aug 2007 04:12:57 -0000      1.53
+++ traverso/ExportWidget.cpp   15 Aug 2007 00:18:52 -0000      1.54
@@ -188,19 +188,21 @@
        
        switch (audioTypeComboBox->currentIndex()) {
         case   0:
-                m_exportSpec->writerType = "sf";
+               m_exportSpec->writerType = "sndfile";
                 m_exportSpec->extraFormat["filetype"] = "wav";
                 break;
         case   1:
-                m_exportSpec->writerType = "sf";
+               m_exportSpec->writerType = "sndfile";
                 m_exportSpec->extraFormat["filetype"] = "aiff";
                 break;
         case   2:
-                m_exportSpec->writerType = "sf";
+               m_exportSpec->writerType = "sndfile";
                 m_exportSpec->extraFormat["filetype"] = "flac";
                 break;
         case   3:
-                m_exportSpec->writerType = "wp";
+               m_exportSpec->writerType = "wavpack";
+               m_exportSpec->extraFormat["quality"] = "high";
+               m_exportSpec->extraFormat["skip_wvx"] = "true";
                 break;
         }
 
@@ -537,7 +539,7 @@
                (m_exportSpec->normalize == cdNormalizeCheckBox->isChecked())) 
) {
                
                m_exportSpec->data_width = 16;
-               m_exportSpec->writerType = "sf";
+               m_exportSpec->writerType = "sndfile";
                m_exportSpec->extraFormat["filetype"] = "wav";
                m_exportSpec->channels = 2;
                m_exportSpec->sample_rate = 44100;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]