traverso-commit
[Top][All Lists]
Advanced

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

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


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src core/DiskIO.cpp core/Peak.cpp core...
Date: Mon, 17 Sep 2007 13:40:35 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/09/17 13:40:35

Modified files:
        src/core       : DiskIO.cpp Peak.cpp Peak.h ReadSource.cpp 
                         ReadSource.h Utils.cpp 
        src/traverso/songcanvas: AudioClipView.cpp 

Log message:
        * remove xscale factor from Peak::calculate_peaks(), we'll do rescaling 
in Peak itself, not via QPainter
        * calculate Peak data in a samplerate independent way, using 44.1 KHz 
as the reference samplerate

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/DiskIO.cpp?cvsroot=traverso&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.cpp?cvsroot=traverso&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.h?cvsroot=traverso&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.cpp?cvsroot=traverso&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.h?cvsroot=traverso&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Utils.cpp?cvsroot=traverso&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/AudioClipView.cpp?cvsroot=traverso&r1=1.86&r2=1.87

Patches:
Index: core/DiskIO.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/DiskIO.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- core/DiskIO.cpp     28 Aug 2007 19:51:52 -0000      1.47
+++ core/DiskIO.cpp     17 Sep 2007 13:40:34 -0000      1.48
@@ -182,7 +182,9 @@
 {
        PENTER;
        
-//     Q_ASSERT_X(m_song->threadId != QThread::currentThreadId (), 
"DiskIO::seek", "Error, running in gui thread!!!!!");
+#if defined (THREAD_CHECK)
+       Q_ASSERT_X(m_song->threadId != QThread::currentThreadId (), 
"DiskIO::seek", "Error, running in gui thread!!!!!");
+#endif
 
        mutex.lock();
        
@@ -193,7 +195,7 @@
 
        foreach(ReadSource* source, m_readSources) {
                if (m_sampleRateChanged) {
-                       source->output_rate_changed();
+                       
source->set_output_rate(audiodevice().get_sample_rate());
                        source->prepare_buffer();
                }
                source->rb_seek_to_file_position(location);

Index: core/Peak.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- core/Peak.cpp       11 Sep 2007 19:52:33 -0000      1.49
+++ core/Peak.cpp       17 Sep 2007 13:40:34 -0000      1.50
@@ -61,6 +61,7 @@
        
        if (rs) {
                m_source = resources_manager()->get_readsource(rs->get_id());
+               m_source->set_output_rate(44100);
        } else {
                m_source = 0;
        }
@@ -70,6 +71,7 @@
        
        peaksAvailable = permanentFailure = interuptPeakBuild = false;
        m_file = m_normFile = 0;
+       m_pd = 0;
 }
 
 Peak::~Peak()
@@ -211,13 +213,10 @@
 }
 
 
-int Peak::calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos, 
int pixelcount, qreal& xscale)
+int Peak::calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos, 
int pixelcount)
 {
        PENTER3;
        
-       // TODO determine the real xscale value
-       xscale = 1.0;
-       
        if (permanentFailure) {
                return PERMANENT_FAILURE;
        }
@@ -275,7 +274,8 @@
                // Calculate the amount of frames to be read
                nframes_t toRead = pixelcount * zoomStep[zoomLevel];
                
-               nframes_t readFrames = 
m_source->file_read(m_peakdataDecodeBuffer, startPos, toRead);
+               TimeRef startlocation(startPos, 44100);
+               nframes_t readFrames = 
m_source->file_read(m_peakdataDecodeBuffer, startlocation, toRead);
 
                if (readFrames == 0) {
                        return NO_PEAKDATA_FOUND;
@@ -371,8 +371,8 @@
        // Now seek to the start position, so we can write the peakdata to it 
in the process function
        fseek(m_file, m_data.peakDataOffset, SEEK_SET);
        
-       normValue = peakUpperValue = peakLowerValue = 0;
-       processBufferSize = processedFrames = m_progress = normProcessedFrames 
= normDataCount = 0;
+       m_pd = new Peak::ProcessData;
+       m_pd->stepSize = TimeRef(1, m_source->get_file_rate());
        
        return 1;
 }
@@ -382,18 +382,18 @@
 {
        PENTER;
        
-       if (processedFrames != 64) {
-               peak_data_t data = (peak_data_t)(peakUpperValue * MAX_DB_VALUE);
+       if (m_pd->processLocation < m_pd->nextDataPointLocation) {
+               peak_data_t data = (peak_data_t)(m_pd->peakUpperValue * 
MAX_DB_VALUE);
                fwrite(&data, sizeof(peak_data_t), 1, m_file);
-               data = (peak_data_t)(-1 * peakLowerValue * MAX_DB_VALUE);
+               data = (peak_data_t)(-1 * m_pd->peakLowerValue * MAX_DB_VALUE);
                fwrite(&data, sizeof(peak_data_t), 1, m_file);
-               processBufferSize += 2;
+               m_pd->processBufferSize += 2;
        }
        
        int totalBufferSize = 0;
        
-       m_data.peakDataSizeForLevel[0] = processBufferSize;
-       totalBufferSize += processBufferSize;
+       m_data.peakDataSizeForLevel[0] = m_pd->processBufferSize;
+       totalBufferSize += m_pd->processBufferSize;
        
        for( int i = SAVING_ZOOM_FACTOR + 1; i < ZOOM_LEVELS+1; ++i) {
                m_data.peakDataSizeForLevel[i - SAVING_ZOOM_FACTOR] = 
m_data.peakDataSizeForLevel[i - SAVING_ZOOM_FACTOR - 1] / 2;
@@ -408,16 +408,16 @@
        // Need to look into that, for now + 2 seems to work...
        peak_data_t* saveBuffer = new peak_data_t[totalBufferSize + 
1*sizeof(peak_data_t)];
        
-       int read = fread(saveBuffer, sizeof(peak_data_t), processBufferSize, 
m_file);
+       int read = fread(saveBuffer, sizeof(peak_data_t), 
m_pd->processBufferSize, m_file);
        
-       if (read != processBufferSize) {
+       if (read != m_pd->processBufferSize) {
                PERROR("couldn't read in all saved data?? (%d read)", read);
        }
        
        
        int prevLevelBufferPos = 0;
        int nextLevelBufferPos;
-       m_data.peakDataSizeForLevel[0] = processBufferSize;
+       m_data.peakDataSizeForLevel[0] = m_pd->processBufferSize;
        m_data.peakDataLevelOffsets[0] = m_data.peakDataOffset;
        
        for (int i = SAVING_ZOOM_FACTOR+1; i < ZOOM_LEVELS+1; ++i) {
@@ -452,10 +452,10 @@
        
        fseek(m_normFile, 0, SEEK_SET);
        
-       read = fread(saveBuffer, sizeof(audio_sample_t), normDataCount, 
m_normFile);
+       read = fread(saveBuffer, sizeof(audio_sample_t), m_pd->normDataCount, 
m_normFile);
        
-       if (read != normDataCount) {
-               PERROR("Could not read in all (%d) norm. data, only %d", 
normDataCount, read);
+       if (read != m_pd->normDataCount) {
+               PERROR("Could not read in all (%d) norm. data, only %d", 
m_pd->normDataCount, read);
        }
        
        m_data.normValuesDataOffset = m_data.peakDataOffset + totalBufferSize;
@@ -475,6 +475,8 @@
        m_file = 0;
        
        delete [] saveBuffer;
+       delete m_pd;
+       m_pd = 0;
        
        emit finished(this);
        
@@ -487,24 +489,26 @@
 {
        for (uint i=0; i < nframes; i++) {
                
+               m_pd->processLocation += m_pd->stepSize;
+               
                audio_sample_t sample = buffer[i];
                
-               if (sample > peakUpperValue) {
-                       peakUpperValue = sample;
-               }
+               m_pd->normValue = f_max(m_pd->normValue, fabsf(sample));
                
-               if (sample < peakLowerValue) {
-                       peakLowerValue = sample;
+               if (sample > m_pd->peakUpperValue) {
+                       m_pd->peakUpperValue = sample;
                }
                
-               normValue = f_max(normValue, fabsf(sample));
+               if (sample < m_pd->peakLowerValue) {
+                       m_pd->peakLowerValue = sample;
+               }
                
-               if (processedFrames == 64) {
+               if (m_pd->processLocation >= m_pd->nextDataPointLocation) {
                
                        peak_data_t peakbuffer[2];
 
-                       peakbuffer[0] = (peak_data_t) (peakUpperValue * 
MAX_DB_VALUE );
-                       peakbuffer[1] = (peak_data_t) ((-1) * (peakLowerValue * 
MAX_DB_VALUE ));
+                       peakbuffer[0] = (peak_data_t) (m_pd->peakUpperValue * 
MAX_DB_VALUE );
+                       peakbuffer[1] = (peak_data_t) ((-1) * 
(m_pd->peakLowerValue * MAX_DB_VALUE ));
                        
                        int written = fwrite(peakbuffer, sizeof(peak_data_t), 
2, m_file);
                        
@@ -512,27 +516,26 @@
                                PWARN("couldnt write data, only (%d)", written);
                        }
 
-                       peakUpperValue = 0.0;
-                       peakLowerValue = 0.0;
-                       processedFrames = 0;
+                       m_pd->peakUpperValue = 0.0;
+                       m_pd->peakLowerValue = 0.0;
                        
-                       processBufferSize+=2;
+                       m_pd->processBufferSize+=2;
+                       m_pd->nextDataPointLocation += m_pd->processRange;
                }
                
-               if (normProcessedFrames == NORMALIZE_CHUNK_SIZE) {
-                       int written = fwrite(&normValue, 
sizeof(audio_sample_t), 1, m_normFile);
+               if (m_pd->normProcessedFrames == NORMALIZE_CHUNK_SIZE) {
+                       int written = fwrite(&m_pd->normValue, 
sizeof(audio_sample_t), 1, m_normFile);
                        
                        if (written != 1) {
                                PWARN("couldnt write data, only (%d)", written);
                        }
  
-                       normValue = 0.0;
-                       normProcessedFrames = 0;
-                       normDataCount++;
+                       m_pd->normValue = 0.0;
+                       m_pd->normProcessedFrames = 0;
+                       m_pd->normDataCount++;
                }
                
-               processedFrames++;
-               normProcessedFrames++;
+               m_pd->normProcessedFrames++;
        }
 }
 
@@ -552,6 +555,8 @@
                return ret;
        }
        
+       m_source->set_output_rate(m_source->get_file_rate());
+       
        nframes_t readFrames = 0;
        nframes_t totalReadFrames = 0;
 
@@ -590,9 +595,9 @@
                totalReadFrames += readFrames;
                p = (int) ((float)totalReadFrames / 
((float)m_source->get_nframes() / 100.0));
                
-               if ( p > m_progress) {
-                       emit progress(p - m_progress);
-                       m_progress = p;
+               if ( p > m_pd->progress) {
+                       emit progress(p - m_pd->progress);
+                       m_pd->progress = p;
                }
                
        } while (totalReadFrames < m_source->get_nframes());
@@ -612,6 +617,8 @@
        printf("Process time: %d seconds\n\n", (int)(processtime/1000));
 #endif
        
+       m_source->set_output_rate(44100);
+
        return ret;
 }
 

Index: core/Peak.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- core/Peak.h 11 Sep 2007 19:52:33 -0000      1.16
+++ core/Peak.h 17 Sep 2007 13:40:34 -0000      1.17
@@ -118,7 +118,7 @@
        void process(audio_sample_t* buffer, nframes_t frames);
        int prepare_processing();
        int finish_processing();
-       int calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos, 
int count, qreal& xscale);
+       int calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos, 
int count);
 
        void close();
        
@@ -131,16 +131,33 @@
        bool                    peaksAvailable;
        bool                    permanentFailure;
        bool                    interuptPeakBuild;
-       nframes_t               processedFrames;
-       nframes_t               normProcessedFrames;
-       int                     processBufferSize;
-       int                     normDataCount;
-       int                     m_progress;
        int                     m_channel;
+       
+       struct ProcessData {
+               ProcessData() {
+                       normValue = peakUpperValue = peakLowerValue = 0;
+                       processBufferSize = progress = normProcessedFrames = 
normDataCount = 0;
+                       processRange = TimeRef(64, 44100);
+                       nextDataPointLocation = processRange;
+               }
        audio_sample_t          peakUpperValue;
        audio_sample_t          peakLowerValue;
        audio_sample_t          normValue;
 
+               TimeRef                 stepSize;
+               TimeRef                 processRange;
+               TimeRef                 processLocation;
+               TimeRef                 nextDataPointLocation;
+               
+               nframes_t               normProcessedFrames;
+               
+               int                     progress;
+               int                     processBufferSize;
+               int                     normDataCount;
+       };
+       
+       ProcessData*            m_pd;
+
        PeakData                m_data;
        FILE*                   m_file;
        FILE*                   m_normFile;

Index: core/ReadSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.cpp,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- core/ReadSource.cpp 11 Sep 2007 14:16:02 -0000      1.57
+++ core/ReadSource.cpp 17 Sep 2007 13:40:34 -0000      1.58
@@ -224,7 +224,7 @@
                //converter_type = config().get_property("Conversion", 
"ExportResamplingConverterType", 0).toInt();
                m_audioReader = new ResampleAudioReader(m_fileName, 
converter_type, m_decodertype);
                if (m_audioReader->is_valid()) {
-                       output_rate_changed();
+                       set_output_rate(audiodevice().get_sample_rate());
                }
                else {
                        delete m_audioReader;
@@ -265,11 +265,12 @@
 }
 
 
-void ReadSource::output_rate_changed()
+void ReadSource::set_output_rate(int rate)
 {
+       Q_ASSERT(rate > 0);
        ResampleAudioReader* reader = 
dynamic_cast<ResampleAudioReader*>(m_audioReader);
        if (reader) {
-               reader->set_output_rate(audiodevice().get_sample_rate());
+               reader->set_output_rate(rate);
        }
 }
 
@@ -279,7 +280,14 @@
 #if defined (profile)
        trav_time_t starttime = get_microseconds();
 #endif
-       nframes_t result = m_audioReader->read_from(buffer, 
start.to_frame(audiodevice().get_sample_rate()), cnt);
+       
+       int rate = audiodevice().get_sample_rate();
+       ResampleAudioReader* reader = 
dynamic_cast<ResampleAudioReader*>(m_audioReader);
+       if (reader) {
+               rate = reader->get_output_rate();
+       }
+       
+       nframes_t result = m_audioReader->read_from(buffer, 
start.to_frame(rate), cnt);
 
 #if defined (profile)
        int processtime = (int) (get_microseconds() - starttime);
@@ -597,10 +605,16 @@
 }
 
 
-//eof
-
 int ReadSource::file_read(DecodeBuffer * buffer, nframes_t start, nframes_t 
cnt)
 {
        TimeRef startlocation(start, get_rate());
        return file_read(buffer, startlocation, cnt);
 }
+
+
+int ReadSource::get_file_rate() const
+{
+       Q_ASSERT(m_audioReader);
+       return m_audioReader->get_file_rate();
+}
+

Index: core/ReadSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- core/ReadSource.h   28 Aug 2007 19:51:52 -0000      1.35
+++ core/ReadSource.h   17 Sep 2007 13:40:34 -0000      1.36
@@ -67,6 +67,7 @@
        
        void set_audio_clip(AudioClip* clip);
        const nframes_t get_nframes() const;
+       int get_file_rate() const;
        const TimeRef& get_length() const {return m_length;}
        
        void sync(DecodeBuffer* buffer);
@@ -75,8 +76,7 @@
        size_t is_active() const;
        BufferStatus* get_buffer_status();
        
-public slots:
-       void output_rate_changed();
+       void set_output_rate(int rate);
        
 private:
        AbstractAudioReader*    m_audioReader;

Index: core/Utils.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Utils.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- core/Utils.cpp      11 Sep 2007 14:16:02 -0000      1.15
+++ core/Utils.cpp      17 Sep 2007 13:40:35 -0000      1.16
@@ -99,6 +99,10 @@
        long unsigned int remainder;
        int mins, secs, frames;
 
+       if (rate != 44100) {
+               nframes = nframes * (44100/rate);
+       }
+
        mins = nframes / ( 60 * rate );
        remainder = nframes - ( mins * 60 * rate );
        secs = remainder / rate;

Index: traverso/songcanvas/AudioClipView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/AudioClipView.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -b -r1.86 -r1.87
--- traverso/songcanvas/AudioClipView.cpp       11 Sep 2007 19:52:33 -0000      
1.86
+++ traverso/songcanvas/AudioClipView.cpp       17 Sep 2007 13:40:35 -0000      
1.87
@@ -231,8 +231,8 @@
        // when using a different color for the brush then the outline.
        // Painting 2 more pixels makes it getting clipped away.....
        pixelcount += 2;
-       // When painting skips one pixel at a time, we always have to start
-       // at an even position with an even amount of pixels to paint
+/*     When painting skips one pixel at a time, we always have to start
+       at an even position with an even amount of pixels to paint*/
        if (xstart % 2) {
                xstart -= 1;
                pixelcount++;
@@ -258,7 +258,6 @@
        float pixeldata[channels][buffersize];
        float curvemixdown[buffersize];
        
-       qreal xscale;
        // Load peak data for all channels, if no peakdata is returned
        // for a certain Peak object, schedule it for loading.
        for (int chan=0; chan < channels; chan++) {
@@ -274,8 +273,7 @@
                int availpeaks = peak->calculate_peaks( &buffers[chan],
                                                        microView ? 
m_song->get_hzoom() : m_song->get_hzoom() + 1,
                                                        (xstart * 
m_sv->scalefactor) + clipstartoffset.to_frame(audiodevice().get_sample_rate()),
-                                                       microView ? 
peakdatacount : peakdatacount / 2, 
-                                                       xscale);
+                                                       microView ? 
peakdatacount : peakdatacount / 2);
                
                if (peakdatacount != availpeaks) {
 //                     PWARN("peakdatacount != availpeaks (%d, %d)", 
peakdatacount, availpeaks);
@@ -476,8 +474,8 @@
                        if (m_classicView) {
                                QPolygonF polygonbottom(pixelcount);
                                
-                               int range = pixelcount+xstart;
-                               for (int x = xstart; x < range; x+=2) {
+                               int range = pixelcount;
+                               for (int x = 0; x < range; x+=2) {
                                        polygontop.append( QPointF(x, 
scaleFactor * pixeldata[chan][bufferpos++]) );
                                        polygonbottom.append( QPointF(x, 
-scaleFactor * pixeldata[chan][bufferpos++]) );
                                }
@@ -512,12 +510,14 @@
                                
                        }
                                        
-                       p->setMatrix(matrix().scale(xscale, 1).translate(0, 
ytrans), true);
+                       p->setMatrix(matrix().translate(xstart, ytrans), true);
                        p->drawPath(path);
+                       
                }
                
                p->restore();
                
+               
                if (m_mergedView) {
                        break;
                }




reply via email to

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