traverso-commit
[Top][All Lists]
Advanced

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

[Traverso-commit] traverso/src/core Peak.cpp


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src/core Peak.cpp
Date: Fri, 08 Jun 2007 10:37:33 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/06/08 10:37:33

Modified files:
        src/core       : Peak.cpp 

Log message:
        reduce stack allocation in get_max_amplitude()  

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.cpp?cvsroot=traverso&r1=1.30&r2=1.31

Patches:
Index: Peak.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- Peak.cpp    8 Jun 2007 10:25:14 -0000       1.30
+++ Peak.cpp    8 Jun 2007 10:37:33 -0000       1.31
@@ -633,6 +633,8 @@
 {
        Q_ASSERT(m_file);
        
+       audio_sample_t* readbuffer =  new 
audio_sample_t[NORMALIZE_CHUNK_SIZE*2];
+       
        audio_sample_t maxamp = 0;
        int startpos = startframe / NORMALIZE_CHUNK_SIZE;
        
@@ -643,7 +645,6 @@
                int toRead = (int) ((startpos * NORMALIZE_CHUNK_SIZE) - 
startframe);
                
                audio_sample_t buf[toRead];
-               audio_sample_t readbuffer[toRead*2];
                int read = m_source->file_read(m_channel, buf, startframe, 
toRead, readbuffer);
                
                maxamp = Mixer::compute_peak(buf, read, maxamp);
@@ -658,11 +659,9 @@
        int endpos = (int) f;
        int toRead = (int) ((f - (endframe / NORMALIZE_CHUNK_SIZE)) * 
NORMALIZE_CHUNK_SIZE);
        audio_sample_t buf[toRead];
-       audio_sample_t readbuffer[toRead*2];
        int read = m_source->file_read(m_channel, buf, endframe - toRead, 
toRead, readbuffer);
        maxamp = Mixer::compute_peak(buf, read, maxamp);
        
-       
        // Now that we have covered both boundary situations,
        // read in the cached normvalues, and calculate the highest value!
        count = endpos - startpos;
@@ -670,13 +669,15 @@
        
        fseek(m_file, m_data.normValuesDataOffset + (startpos * 
sizeof(audio_sample_t)), SEEK_SET);
        
-       read = fread(buffer, sizeof(audio_sample_t), count, m_file);
+       read = fread(readbuffer, sizeof(audio_sample_t), count, m_file);
        
        if (read != count) {
                printf("could only read %d, %d requested\n", read, count);
        }
        
-       maxamp = Mixer::compute_peak(buffer, read, maxamp);
+       maxamp = Mixer::compute_peak(readbuffer, read, maxamp);
+       
+       delete [] readbuffer;
        
        return maxamp;
 }




reply via email to

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