[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src common/defines.h core/AudioClip.cp...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src common/defines.h core/AudioClip.cp... |
Date: |
Wed, 30 Jan 2008 12:24:36 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 08/01/30 12:24:36
Modified files:
src/common : defines.h
src/core : AudioClip.cpp Peak.cpp Peak.h
src/sheetcanvas: AudioClipView.cpp
Log message:
* More zooming work, let's hope one day it'll work fine again hehe
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/common/defines.h?cvsroot=traverso&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.161&r2=1.162
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.cpp?cvsroot=traverso&r1=1.82&r2=1.83
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.h?cvsroot=traverso&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/traverso/src/sheetcanvas/AudioClipView.cpp?cvsroot=traverso&r1=1.4&r2=1.5
Patches:
Index: common/defines.h
===================================================================
RCS file: /sources/traverso/traverso/src/common/defines.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- common/defines.h 23 Jan 2008 17:32:22 -0000 1.6
+++ common/defines.h 30 Jan 2008 12:24:35 -0000 1.7
@@ -66,6 +66,10 @@
m_position = (UNIVERSAL_SAMPLE_RATE / rate) * frame;
}
+ TimeRef(qreal frame, int rate) {
+ m_position = qint64((qreal(UNIVERSAL_SAMPLE_RATE) / rate) *
frame);
+ }
+
void add_frames(nframes_t frames, int rate) {
m_position += ((UNIVERSAL_SAMPLE_RATE / rate) * frames);
}
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -b -r1.161 -r1.162
--- core/AudioClip.cpp 21 Jan 2008 16:22:12 -0000 1.161
+++ core/AudioClip.cpp 30 Jan 2008 12:24:35 -0000 1.162
@@ -280,8 +280,8 @@
TimeRef movingToRight = newLeftLocation - m_trackStartLocation;
- if (movingToRight > (availableTimeRight - TimeRef(4,
get_rate())) ) {
- movingToRight = (availableTimeRight - TimeRef(4,
get_rate()));
+ if (movingToRight > (availableTimeRight - TimeRef(nframes_t(4),
get_rate())) ) {
+ movingToRight = (availableTimeRight -
TimeRef(nframes_t(4), get_rate()));
}
m_trackStartLocation += movingToRight;
@@ -319,8 +319,8 @@
TimeRef movingToLeft = m_trackEndLocation - newRightLocation;
- if (movingToLeft > availableTimeLeft - TimeRef(4, get_rate())) {
- movingToLeft = availableTimeLeft - TimeRef(4,
get_rate());
+ if (movingToLeft > availableTimeLeft - TimeRef(nframes_t(4),
get_rate())) {
+ movingToLeft = availableTimeLeft -
TimeRef(nframes_t(4), get_rate());
}
set_track_end_location( m_trackEndLocation - movingToLeft );
Index: core/Peak.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.cpp,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -b -r1.82 -r1.83
--- core/Peak.cpp 29 Jan 2008 18:21:53 -0000 1.82
+++ core/Peak.cpp 30 Jan 2008 12:24:35 -0000 1.83
@@ -79,7 +79,6 @@
if (rs) {
// This Peak object was created by AudioClip, meant for reading
peak data
m_source = resources_manager()->get_readsource(rs->get_id());
- m_source->set_output_rate(44100, true);
} else {
// No ReadSource object? Then it's created by WriteSource for
on the fly
// peak data creation, no m_source needed!
@@ -238,7 +237,14 @@
}
-int Peak::calculate_peaks(int chan, float** buffer, qreal zoomLevel, TimeRef
startlocation, int pixelcount)
+int Peak::calculate_peaks(
+ int chan,
+ float ** buffer,
+ TimeRef startlocation,
+ int peakDataCount,
+ qreal framesPerPeak,
+ qreal & scaleFactor
+ )
{
PENTER3;
@@ -252,7 +258,7 @@
}
}
- if (pixelcount <= 0) {
+ if (peakDataCount <= 0) {
return NO_PEAKDATA_FOUND;
}
@@ -262,13 +268,16 @@
// PROFILE_START;
// Macro view mode
- if (zoomLevel >= 64) {
+ if (framesPerPeak >= 64) {
int highbit;
- unsigned long nearestpow2 =
nearest_power_of_two(qRound(zoomLevel), highbit);
+ unsigned long nearestpow2 =
nearest_power_of_two(qRound(framesPerPeak), highbit);
if (nearestpow2 == 0) {
return NO_PEAKDATA_FOUND;
}
+ scaleFactor = qreal(nearestpow2) / framesPerPeak;
+
+
nframes_t startPos = startlocation.to_frame(44100);
int index = cache_index_lut()->value(nearestpow2, -1);
@@ -280,16 +289,16 @@
int truncate = 0;
// Check if this zoom level has as many data as requested.
- if ( (pixelcount + offset) >
data->headerdata.peakDataSizeForLevel[index]) {
- truncate = pixelcount -
(data->headerdata.peakDataSizeForLevel[index] - offset);
+ if ( (peakDataCount + offset) >
data->headerdata.peakDataSizeForLevel[index]) {
+ truncate = peakDataCount -
(data->headerdata.peakDataSizeForLevel[index] - offset);
// pixelcount =
data->headerdata.peakDataSizeForLevel[index] - offset;
}
nframes_t readposition = data->headerdata.headerSize +
(data->headerdata.peakDataOffsets[index] + offset) * sizeof(peak_data_t);
- produced =
data->peakreader->read_from(data->peakdataDecodeBuffer, readposition,
pixelcount);
+ produced =
data->peakreader->read_from(data->peakdataDecodeBuffer, readposition,
peakDataCount);
- if (produced != pixelcount) {
- PERROR("Could not read in all peak data, pixelcount is
%d, read count is %d", pixelcount, produced);
+ if (produced != peakDataCount) {
+ PERROR("Could not read in all peak data, peakDataCount
is %d, read count is %d", peakDataCount, produced);
}
// PROFILE_END("Peak calculate_peaks");
@@ -304,20 +313,19 @@
//
*buffer = data->peakdataDecodeBuffer->destination[0];
- return pixelcount;
+ return produced;
// Micro view mode
} else {
-
- int highbit;
- unsigned long nearestpow2 = nearest_power_of_two(zoomLevel,
highbit);
-
- if (nearestpow2 == 0) {
- nearestpow2 = 1;
+ if (framesPerPeak < 1.0) {
+ scaleFactor = 1.0 / framesPerPeak;
+ framesPerPeak = 1.0;
+ } else {
+ scaleFactor = 1.0;
}
// Calculate the amount of frames to be read
- nframes_t toRead = pixelcount * nearestpow2;
+ nframes_t toRead = qRound(peakDataCount * framesPerPeak);
nframes_t readFrames =
m_source->file_read(data->peakdataDecodeBuffer, startlocation, toRead);
@@ -327,41 +335,53 @@
if ( readFrames != toRead) {
PWARN("Unable to read nframes %d (only %d available)",
toRead, readFrames);
- pixelcount = qRound(readFrames / nearestpow2);
}
int count = 0;
- nframes_t pos = 0;
- audio_sample_t valueMax, valueMin, sample;
+ audio_sample_t sample;
// MicroView needs a buffer to store the calculated peakdata
// our decodebuffer's readbuffer is large enough for this
purpose
// and it's no problem to use it at this point in the process
chain.
float* peakdata = data->peakdataDecodeBuffer->readBuffer;
- do {
- valueMax = valueMin = 0;
+ ProcessData pd;
+ pd.stepSize = TimeRef(nframes_t(1), m_source->get_file_rate());
+ pd.processRange = TimeRef(framesPerPeak,
m_source->get_file_rate());
+
+ for (uint i=0; i < readFrames; i++) {
+
+ pd.processLocation += pd.stepSize;
+
+ sample =
data->peakdataDecodeBuffer->destination[chan][i];
+
+ pd.normValue = f_max(pd.normValue, fabsf(sample));
- for(int i=0; i < nearestpow2; i++) {
- Q_ASSERT(pos <= readFrames);
- sample =
data->peakdataDecodeBuffer->destination[chan][pos];
- if (sample > valueMax)
- valueMax = sample;
- if (sample < valueMin)
- valueMin = sample;
- pos++;
+ if (sample > pd.peakUpperValue) {
+ pd.peakUpperValue = sample;
}
- if (valueMax > fabs(valueMin)) {
- peakdata[count] = valueMax;
+ if (sample < pd.peakLowerValue) {
+ pd.peakLowerValue = sample;
+ }
+
+ if (pd.processLocation >= pd.nextDataPointLocation) {
+
+ if (pd.peakUpperValue >
fabs(pd.peakLowerValue)) {
+ peakdata[count] = pd.peakUpperValue;
} else {
- peakdata[count] = valueMin;
+ peakdata[count] = pd.peakLowerValue;
}
- count++;
+ pd.peakUpperValue = -10.0;
+ pd.peakLowerValue = 10.0;
- } while(count < pixelcount);
+ pd.nextDataPointLocation += pd.processRange;
+ count++;
+ }
+ }
+// printf("framesPerPeak, peakDataCount, generated, readFrames %f,
%d, %d, %d\n", framesPerPeak, peakDataCount, count, readFrames);
// PROFILE_END("Peak calculate_peaks");
@@ -415,7 +435,8 @@
data->file.seek(data->headerdata.headerSize);
data->pd = new Peak::ProcessData;
- data->pd->stepSize = TimeRef(1, rate);
+ data->pd->stepSize = TimeRef(nframes_t(1), rate);
+ data->pd->processRange = TimeRef(nframes_t(64), 44100);
}
@@ -666,8 +687,6 @@
// PROFILE_END("Peak create from scratch");
- m_source->set_output_rate(44100, true);
-
return ret;
}
@@ -737,8 +756,6 @@
delete [] readbuffer;
- m_source->set_output_rate(44100, true);
-
return maxamp;
}
@@ -973,3 +990,9 @@
return 1048576;
}
+Peak::ChannelData::~ ChannelData()
+{
+ if (peakdataDecodeBuffer) {
+ delete peakdataDecodeBuffer;
+ }
+}
Index: core/Peak.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- core/Peak.h 29 Jan 2008 18:21:54 -0000 1.32
+++ core/Peak.h 30 Jan 2008 12:24:35 -0000 1.33
@@ -114,7 +114,7 @@
void process(uint channel, audio_sample_t* buffer, nframes_t frames);
int prepare_processing(int rate);
int finish_processing();
- int calculate_peaks(int chan, float** buffer, qreal zoomLevel, TimeRef
startlocation, int count);
+ int calculate_peaks(int chan, float** buffer, TimeRef startlocation,
int peakDataCount, qreal framesPerPeak, qreal& scaleFactor);
void close();
@@ -136,7 +136,6 @@
ProcessData() {
normValue = peakUpperValue = peakLowerValue = 0;
processBufferSize = progress = normProcessedFrames =
normDataCount = 0;
- processRange = TimeRef(64, 44100);
nextDataPointLocation = processRange;
}
@@ -170,11 +169,7 @@
memory = 0;
peakdataDecodeBuffer = 0;
}
- ~ChannelData() {
- if (peakdataDecodeBuffer) {
- delete peakdataDecodeBuffer;
- }
- }
+ ~ChannelData();
QString fileName;
QString normFileName;
QFile file;
Index: sheetcanvas/AudioClipView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/sheetcanvas/AudioClipView.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- sheetcanvas/AudioClipView.cpp 28 Jan 2008 21:11:51 -0000 1.4
+++ sheetcanvas/AudioClipView.cpp 30 Jan 2008 12:24:36 -0000 1.5
@@ -266,49 +266,8 @@
curveDefaultValue = curveView->get_default_value();
}
- int highbit;
- unsigned long nearestpow2 =
nearest_power_of_two(long(m_sheet->get_hzoom()), highbit);
- if (nearestpow2 == 0) {
- nearestpow2 = 1;
- }
-
- qreal xscale = qreal(nearestpow2) / m_sheet->get_hzoom();
- // xscale becomes smaller then 1.0 at times, which is not supported!
- // only if it is > 1.0 we are allowed to adjust the pixelcount. (needs
proper fix)
- if (xscale > 1) {
- pixelcount = qRound(pixelcount / xscale);
- }
-// printf("xscale %f, nearestpow2 %d, zoomlevel %f\n", qreal(nearestpow2)
/ m_sheet->get_hzoom(), nearestpow2, m_sheet->get_hzoom());
-
- // 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) {
-
- int availpeaks = peak->calculate_peaks( chan,
- &pixeldata[chan],
- m_sheet->get_hzoom(),
- TimeRef(xstart * m_sv->timeref_scalefactor) +
clipstartoffset,
- peakdatacount);
-
- if (peakdatacount != availpeaks) {
-// PWARN("peakdatacount != availpeaks (%d, %d)",
peakdatacount, availpeaks);
- }
-
- if (availpeaks == Peak::NO_PEAK_FILE) {
- connect(peak, SIGNAL(progress(int)), this,
SLOT(update_progress_info(int)));
- connect(peak, SIGNAL(finished()), this, SLOT
(peak_creation_finished()));
- m_waitingForPeaks = true;
- peak->start_peak_loading();
- return;
- }
-
- if (availpeaks == Peak::PERMANENT_FAILURE || availpeaks ==
Peak::NO_PEAKDATA_FOUND) {
- return;
- }
-
-// pixelcount = std::min(pixelcount, availpeaks);
- }
-
+ qreal xscale;
+// printf("xscale %f, zoomlevel %f\n", xscale, m_sheet->get_hzoom());
float curvemixdown[peakdatacount];
if (mixcurvedata) {
@@ -335,34 +294,60 @@
mixcurvedata |= fademix;
}
- // Load the Peak data into the pixeldata float buffers
+ // Load peak data, mix curvedata and start painting it
+ // if no peakdata is returned for a certain Peak object, schedule it
for loading.
+ for (int chan=0; chan < channels; ++chan) {
+
+ int availpeaks = peak->calculate_peaks(
+ chan,
+ &pixeldata[chan],
+ TimeRef(xstart * m_sv->timeref_scalefactor) +
clipstartoffset,
+ peakdatacount,
+ m_sheet->get_hzoom(),
+ xscale);
+
+ if (peakdatacount != availpeaks) {
+// PWARN("peakdatacount != availpeaks (%d, %d)",
peakdatacount, availpeaks);
+ }
+
+ if (availpeaks == Peak::NO_PEAK_FILE) {
+ connect(peak, SIGNAL(progress(int)), this,
SLOT(update_progress_info(int)));
+ connect(peak, SIGNAL(finished()), this, SLOT
(peak_creation_finished()));
+ m_waitingForPeaks = true;
+ peak->start_peak_loading();
+ return;
+ }
+
+ if (availpeaks == Peak::PERMANENT_FAILURE || availpeaks ==
Peak::NO_PEAKDATA_FOUND) {
+ return;
+ }
+
+ if (m_mergedView && channels == 2 && chan == 0) continue;
+
+
+// pixelcount = std::min(pixelcount, availpeaks);
+
// ClassicView uses both positive and negative values,
// rectified view: pick the highest value of both
// Merged view: calculate highest value for all channels,
// and store it in the first channels pixeldata.
if (!microView) {
+ // if Rectified View, calculate max of the minimum and
maximum value.
if (!m_classicView) {
- for (int chan=0; chan < channels; chan++) {
for (int i=0, j=0; i < (pixelcount*2); i+=2,
++j) {
pixeldata[chan][j] = -
fabs(f_max(pixeldata[chan][i], - pixeldata[chan][i+1]));
}
}
- }
- if (m_mergedView) {
- for (int chan=1; chan < channels; chan++) {
+ if (m_mergedView && channels == 2) {
for (int i = 0; i < (pixelcount*2); ++i) {
pixeldata[0][i] = f_max(pixeldata[chan
- 1][i], pixeldata[chan][i]);
}
}
}
- }
-
if (mixcurvedata) {
- int curvemixdownpos;
- for (int chan=0; chan < channels; chan++) {
- curvemixdownpos = 0;
+ int curvemixdownpos = 0;
if (m_classicView) {
for (int i = 0; i < (pixelcount*2); ++i) {
pixeldata[chan][i++] *=
curvemixdown[curvemixdownpos];
@@ -376,10 +361,7 @@
}
}
}
- }
-
- for (int chan=0; chan < channels; chan++) {
p->save();
// calculate the height of the area available for peak drawing
@@ -415,6 +397,7 @@
p->restore();
}
+
// Microview, paint waveform as polyline
if (microView) {
@@ -543,14 +526,9 @@
p->drawPath(path);
}
-
}
p->restore();
-
- if (m_mergedView) {
- break;
- }
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src common/defines.h core/AudioClip.cp...,
Remon Sijrier <=