[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src audiofileio/decode/AbstractAudioRe...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src audiofileio/decode/AbstractAudioRe... |
Date: |
Tue, 28 Aug 2007 19:51:52 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/08/28 19:51:52
Modified files:
src/audiofileio/decode: AbstractAudioReader.cpp
AbstractAudioReader.h
ResampleAudioReader.cpp
SFAudioReader.cpp WPAudioReader.cpp
src/commands : AudioClipExternalProcessing.cpp
src/core : AudioClip.cpp AudioClip.h DiskIO.cpp DiskIO.h
Peak.cpp Peak.h ReadSource.cpp ReadSource.h
Song.cpp Song.h
src/engine : defines.h
src/traverso/songcanvas: AudioClipView.cpp
Added files:
src/audiofileio/decode: PeakDataReader.cpp PeakDataReader.h
Log message:
* An absolute mess, but Ben want something too look at :-P
* Added PeakDataReader class used to read peak data
* Added peak_data_t typedef used by Peak and related classes
* buffer management is moved completely into DecodeBuffer itself +
related cleanups, needs more work
* ReadSource and AudioClip further converted to TimeRef
* Tons of bugs added
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/AbstractAudioReader.cpp?cvsroot=traverso&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/AbstractAudioReader.h?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/ResampleAudioReader.cpp?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/SFAudioReader.cpp?cvsroot=traverso&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/WPAudioReader.cpp?cvsroot=traverso&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/PeakDataReader.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/audiofileio/decode/PeakDataReader.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/AudioClipExternalProcessing.cpp?cvsroot=traverso&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.127&r2=1.128
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.h?cvsroot=traverso&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/DiskIO.cpp?cvsroot=traverso&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/DiskIO.h?cvsroot=traverso&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.cpp?cvsroot=traverso&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.h?cvsroot=traverso&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.cpp?cvsroot=traverso&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.h?cvsroot=traverso&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Song.cpp?cvsroot=traverso&r1=1.131&r2=1.132
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Song.h?cvsroot=traverso&r1=1.65&r2=1.66
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/defines.h?cvsroot=traverso&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/AudioClipView.cpp?cvsroot=traverso&r1=1.82&r2=1.83
Patches:
Index: audiofileio/decode/AbstractAudioReader.cpp
===================================================================
RCS file:
/sources/traverso/traverso/src/audiofileio/decode/AbstractAudioReader.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- audiofileio/decode/AbstractAudioReader.cpp 17 Aug 2007 00:13:26 -0000
1.4
+++ audiofileio/decode/AbstractAudioReader.cpp 28 Aug 2007 19:51:51 -0000
1.5
@@ -26,6 +26,7 @@
#include "WPAudioReader.h"
#include "VorbisAudioReader.h"
#include "ResampleAudioReader.h"
+#include "PeakDataReader.h"
#include <QString>
@@ -106,6 +107,10 @@
nframes_t AbstractAudioReader::read(DecodeBuffer* buffer, nframes_t count)
{
if (count && m_readPos < m_length) {
+
+ // Make sure the read buffer is big enough for this read
+ buffer->check_buffers_capacity(count, m_channels);
+
// printf("read_from:: after_seek from %d, framepos is %d\n",
start, m_readPos);
nframes_t framesRead = read_private(buffer, count);
@@ -128,6 +133,8 @@
newReader = new SFAudioReader(filename);
} else if (decoder == "wavpack") {
newReader = new WPAudioReader(filename);
+ } else if (decoder == "peak") {
+ newReader = new PeakDataReader(filename);
} else if (decoder == "flac") {
newReader = new FlacAudioReader(filename);
} else if (decoder == "vorbis") {
@@ -159,6 +166,9 @@
else if (MadAudioReader::can_decode(filename)) {
newReader = new MadAudioReader(filename);
}
+ else if (PeakDataReader::can_decode(filename)) {
+ newReader = new PeakDataReader(filename);
+ }
}
if (newReader && !newReader->is_valid()) {
Index: audiofileio/decode/AbstractAudioReader.h
===================================================================
RCS file:
/sources/traverso/traverso/src/audiofileio/decode/AbstractAudioReader.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- audiofileio/decode/AbstractAudioReader.h 21 Aug 2007 01:54:59 -0000
1.7
+++ audiofileio/decode/AbstractAudioReader.h 28 Aug 2007 19:51:51 -0000
1.8
@@ -26,38 +26,52 @@
#include <QString>
-struct DecodeBuffer {
+class DecodeBuffer {
+
+public:
DecodeBuffer() {
+ destination = resampleBuffer = 0;
readBuffer = 0;
- resampleBuffer = 0;
- destinationChannelCount = destinationBufferSize =
resampleBufferSize = readBufferSize = 0;
+ m_channels = destinationBufferSize = resampleBufferSize =
readBufferSize = 0;
+ }
+
+ void check_buffers_capacity(uint size, uint channels) {
+
+ if (m_channels < channels || destinationBufferSize < size) {
+ if (destination) {
+ for (uint chan = 0; chan < m_channels; chan++) {
+ delete [] destination[chan];
+ }
+ delete [] destination;
+ }
+
+ m_channels = channels;
+ destination = new audio_sample_t*[m_channels];
+
+ for (uint chan = 0; chan < m_channels; chan++) {
+ destination[chan] = new audio_sample_t[size];
}
- DecodeBuffer(audio_sample_t** dest, audio_sample_t* readbuf, uint
destbufsize, uint readbufsize, uint channels) {
- destination = dest;
- readBuffer = readbuf;
- destinationBufferSize = destbufsize;
- readBufferSize = readbufsize;
- destinationChannelCount = channels;
+ destinationBufferSize = size;
}
- void check_readbuffer_capacity(uint size) {
- if (readBufferSize < size) {
+ if (readBufferSize < (size*m_channels)) {
if (readBuffer) {
delete [] readBuffer;
}
- readBuffer = new audio_sample_t[size];
- readBufferSize = size;
+ readBuffer = new audio_sample_t[size*m_channels];
+ readBufferSize = (size*m_channels);
}
}
void check_resamplebuffer_capacity(uint frames) {
+
if (resampleBufferSize < frames) {
if (!resampleBuffer) {
- resampleBuffer = new
audio_sample_t*[destinationChannelCount];
+ resampleBuffer = new
audio_sample_t*[m_channels];
}
- for (uint chan = 0; chan < destinationChannelCount;
chan++) {
+ for (uint chan = 0; chan < m_channels; chan++) {
if (resampleBufferSize) {
delete [] resampleBuffer[chan];
}
@@ -74,7 +88,7 @@
// Let the child reader write into the buffer starting
offset samples past the beginning.
// This lets the resampler prefill the buffers with the
pre-existing overflow.
- for (uint chan = 0; chan < destinationChannelCount;
chan++) {
+ for (uint chan = 0; chan < m_channels; chan++) {
resampleBuffer[chan] += offset;
}
}
@@ -84,20 +98,23 @@
if (origDestination) {
destination = origDestination;
- for (uint chan = 0; chan < destinationChannelCount;
chan++) {
+ for (uint chan = 0; chan < m_channels; chan++) {
resampleBuffer[chan] -= offset;
}
}
}
audio_sample_t** destination;
- audio_sample_t** origDestination; // Used to store destination during a
child read in the resampler
audio_sample_t* readBuffer;
audio_sample_t** resampleBuffer;
- uint destinationChannelCount;
uint destinationBufferSize;
uint readBufferSize;
uint resampleBufferSize; // ????
+
+private:
+ uint m_channels;
+ audio_sample_t** origDestination; // Used to store destination during a
child read in the resampler
+
};
class AbstractAudioReader
@@ -113,6 +130,11 @@
bool eof();
nframes_t pos();
+ nframes_t read_from(DecodeBuffer* buffer, TimeRef& start, nframes_t
count) {
+ return read_from(buffer, start.to_frame(m_rate), count);
+ }
+ bool seek(const TimeRef& start);
+
nframes_t read_from(DecodeBuffer* buffer, nframes_t start, nframes_t
count);
bool seek(nframes_t start);
nframes_t read(DecodeBuffer* buffer, nframes_t frameCount);
Index: audiofileio/decode/ResampleAudioReader.cpp
===================================================================
RCS file:
/sources/traverso/traverso/src/audiofileio/decode/ResampleAudioReader.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- audiofileio/decode/ResampleAudioReader.cpp 17 Aug 2007 00:13:27 -0000
1.7
+++ audiofileio/decode/ResampleAudioReader.cpp 28 Aug 2007 19:51:51 -0000
1.8
@@ -21,6 +21,7 @@
#include "ResampleAudioReader.h"
#include <QString>
+#include "PeakDataReader.h"
#define OVERFLOW_SIZE 512
@@ -272,6 +273,12 @@
{
Q_ASSERT(m_reader);
+ PeakDataReader* reader = dynamic_cast<PeakDataReader*>(m_reader);
+ if (reader) {
+// int diff = frame - (nframes_t)(frame * ((double) m_rate /
m_outputRate));
+ return frame;
+ }
+
return (nframes_t)(frame * ((double) m_rate / m_outputRate));
}
Index: audiofileio/decode/SFAudioReader.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/audiofileio/decode/SFAudioReader.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- audiofileio/decode/SFAudioReader.cpp 16 Aug 2007 14:26:50 -0000
1.4
+++ audiofileio/decode/SFAudioReader.cpp 28 Aug 2007 19:51:51 -0000
1.5
@@ -106,9 +106,6 @@
{
Q_ASSERT(m_sf);
- // Make sure the read buffer is big enough for this read
- buffer->check_readbuffer_capacity(frameCount * m_channels);
-
int framesRead = sf_readf_float(m_sf, buffer->readBuffer, frameCount);
// De-interlace
Index: audiofileio/decode/WPAudioReader.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/audiofileio/decode/WPAudioReader.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- audiofileio/decode/WPAudioReader.cpp 24 Aug 2007 20:40:34 -0000
1.8
+++ audiofileio/decode/WPAudioReader.cpp 28 Aug 2007 19:51:51 -0000
1.9
@@ -100,9 +100,6 @@
{
Q_ASSERT(m_wp);
- // Make sure the read buffer is big enough for this read
- buffer->check_readbuffer_capacity(frameCount * m_channels);
-
// WavPack only reads into a int32_t buffer...
int32_t* readbuffer = (int32_t*)buffer->readBuffer;
Index: commands/AudioClipExternalProcessing.cpp
===================================================================
RCS file:
/sources/traverso/traverso/src/commands/AudioClipExternalProcessing.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- commands/AudioClipExternalProcessing.cpp 21 Aug 2007 19:05:24 -0000
1.26
+++ commands/AudioClipExternalProcessing.cpp 28 Aug 2007 19:51:51 -0000
1.27
@@ -54,10 +54,7 @@
void run() {
uint buffersize = 16384;
- audio_sample_t readbuffer[buffersize];
- audio_sample_t* mixdown[2];
- for (int i=0; i<2; ++i) mixdown[i] = new audio_sample_t[2 *
buffersize];
- DecodeBuffer decodebuffer(mixdown, readbuffer, buffersize,
buffersize*2, 2);
+ DecodeBuffer decodebuffer;
ExportSpecification* spec = new ExportSpecification();
spec->start_frame = 0;
@@ -88,7 +85,7 @@
for (int chan=0; chan < 2; ++chan) {
for (uint x = 0; x < nframes; ++x) {
- spec->dataF[chan+(x*spec->channels)] =
mixdown[chan][x];
+ spec->dataF[chan+(x*spec->channels)] =
decodebuffer.destination[chan][x];
}
}
@@ -102,8 +99,6 @@
delete writesource;
delete [] spec->dataF;
delete spec;
- for (int i=0; i<2; ++i)
- delete [] mixdown[i];
}
private:
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -b -r1.127 -r1.128
--- core/AudioClip.cpp 21 Aug 2007 19:09:18 -0000 1.127
+++ core/AudioClip.cpp 28 Aug 2007 19:51:51 -0000 1.128
@@ -90,8 +90,9 @@
m_name = e.attribute( "clipname", "" ) ;
m_isMuted = e.attribute( "mute", "" ).toInt();
// FIXME!!!!!!!
- m_length = TimeRef(e.attribute( "length", "0" ).toUInt(), 44100);
- m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toUInt(), 44100);
+ bool ok;
+ m_length = TimeRef(e.attribute( "length", "0" ).toLongLong(&ok));
+ m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toLongLong(&ok));
m_sourceEndLocation = m_sourceStartLocation + m_length;
set_track_start_frame( e.attribute( "trackstart", "" ).toUInt());
@@ -148,11 +149,12 @@
m_isMuted = e.attribute( "mute", "" ).toInt();
// FIXME!!!!!!!!
- m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toUInt(), 44100);
- m_length = TimeRef(e.attribute( "length", "0" ).toUInt(), 44100);
+ bool ok;
+ m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toLongLong(&ok));
+ m_length = TimeRef(e.attribute( "length", "0" ).toLongLong(&ok));
m_sourceEndLocation = m_sourceStartLocation + m_length;
- set_track_start_frame(e.attribute( "trackstart", "" ).toUInt());
+ set_track_start_frame(e.attribute( "trackstart", "" ).toLongLong(&ok));
emit stateChanged();
@@ -187,9 +189,9 @@
QDomNode AudioClip::get_state( QDomDocument doc )
{
QDomElement node = doc.createElement("Clip");
- node.setAttribute("trackstart",
m_trackStartLocation.to_frame(get_rate()));
- node.setAttribute("sourcestart",
m_sourceStartLocation.to_frame(get_rate()));
- node.setAttribute("length", m_length.to_frame(get_rate()));
+ node.setAttribute("trackstart",
m_trackStartLocation.to_universal_frame());
+ node.setAttribute("sourcestart",
m_sourceStartLocation.to_universal_frame());
+ node.setAttribute("length", m_length.to_universal_frame());
node.setAttribute("mute", m_isMuted);
node.setAttribute("take", m_isTake);
node.setAttribute("clipname", m_name );
@@ -418,7 +420,7 @@
Q_ASSERT(m_readSource);
AudioBus* bus = m_song->get_render_bus();
- nframes_t mix_pos;
+ TimeRef mix_pos;
audio_sample_t* mixdown[get_channels()];
@@ -428,14 +430,14 @@
if ( (m_trackStartLocation < upperRange) && (m_trackEndLocation >
transportLocation) ) {
if (transportLocation < m_trackStartLocation) {
uint offset = (m_trackStartLocation -
transportLocation).to_frame(get_rate());
- mix_pos = m_sourceStartLocation.to_frame(get_rate());
+ mix_pos = m_sourceStartLocation;
for (int chan=0; chan<bus->get_channel_count(); ++chan)
{
mixdown[chan] = bus->get_buffer(chan, nframes)
+ offset;
}
nframes = nframes - offset;
} else {
- mix_pos = (transportLocation - m_trackStartLocation +
m_sourceStartLocation).to_frame(audiodevice().get_sample_rate());
+ mix_pos = (transportLocation - m_trackStartLocation +
m_sourceStartLocation);
for (int chan=0; chan<bus->get_channel_count(); ++chan)
{
mixdown[chan] = bus->get_buffer(chan, nframes);
@@ -455,8 +457,7 @@
if (m_song->realtime_path()) {
read_frames = m_readSource->rb_read(mixdown, mix_pos, nframes);
} else {
- DecodeBuffer buffer(mixdown, m_song->readbuffer, nframes,
nframes*get_channels(), get_channels());
- buffer.destinationChannelCount = get_channels();
+ DecodeBuffer buffer;
read_frames = m_readSource->file_read(&buffer, mix_pos,
nframes);
}
Index: core/AudioClip.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- core/AudioClip.h 17 Aug 2007 00:18:29 -0000 1.59
+++ core/AudioClip.h 28 Aug 2007 19:51:51 -0000 1.60
@@ -97,6 +97,11 @@
nframes_t get_source_end_frame() const;
nframes_t get_source_length() const;
+ TimeRef& get_track_start_location() const {return m_trackStartLocation;}
+ TimeRef& get_track_end_location() const {return m_trackEndLocation;}
+ TimeRef& get_source_start_location() const {return
m_sourceStartLocation;}
+ TimeRef& get_source_end_location() const {return m_sourceEndLocation;}
+
int get_channels() const;
int get_rate() const;
int get_bitdepth() const;
Index: core/DiskIO.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/DiskIO.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- core/DiskIO.cpp 17 Aug 2007 00:18:30 -0000 1.46
+++ core/DiskIO.cpp 28 Aug 2007 19:51:52 -0000 1.47
@@ -151,12 +151,8 @@
// TODO This is a LARGE buffer, any ideas how to make it smaller ??
framebuffer[0] = new audio_sample_t[audiodevice().get_sample_rate() *
writebuffertime];
- framebuffer[1] = new audio_sample_t[audiodevice().get_sample_rate() *
writebuffertime];
m_decodebuffer = new DecodeBuffer;
- m_decodebuffer->destinationChannelCount = 2; // FIXME?: Hardcoding to
2 channels
- m_decodebuffer->destination = framebuffer;
- m_decodebuffer->readBufferSize = 0;
// Move this instance to the workthread
moveToThread(m_diskThread);
@@ -173,7 +169,6 @@
stop();
delete cpuTimeBuffer;
delete [] framebuffer[0];
- delete [] framebuffer[1];
delete m_decodebuffer;
}
Index: core/DiskIO.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/DiskIO.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- core/DiskIO.h 17 Aug 2007 00:18:30 -0000 1.22
+++ core/DiskIO.h 28 Aug 2007 19:51:52 -0000 1.23
@@ -34,7 +34,7 @@
class RingBuffer;
class DiskIOThread;
class Song;
-struct DecodeBuffer;
+class DecodeBuffer;
struct BufferStatus {
int fillStatus;
Index: core/Peak.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- core/Peak.cpp 21 Aug 2007 01:54:59 -0000 1.43
+++ core/Peak.cpp 28 Aug 2007 19:51:52 -0000 1.44
@@ -24,6 +24,7 @@
#include "Peak.h"
#include "AbstractAudioReader.h"
+#include "ResampleAudioReader.h"
#include "ReadSource.h"
#include "ResourcesManager.h"
#include "defines.h"
@@ -35,7 +36,7 @@
#include "Debugger.h"
/* Store for each zoomStep the upper and lower sample to hard disk as a
-* unsigned char. The top-top resolution is then 512 pixels, which should do
+* peak_data_t. The top-top resolution is then 512 pixels, which should do
* Painting the waveform will be as simple as painting a line starting from the
* lower value to the upper value.
*/
@@ -64,8 +65,8 @@
m_source = 0;
}
- m_fileName = source->get_filename() + "-ch" +
QByteArray::number(m_channel) + ".peak";
- m_fileName = m_fileName.replace(QRegExp("audiosources"), "peakfiles");
+ m_fileName = source->get_name() + "-ch" + QByteArray::number(m_channel)
+ ".peak";
+ m_fileName.prepend(pm().get_project()->get_root_dir() + "/peakfiles/");
peaksAvailable = permanentFailure = interuptPeakBuild = false;
m_file = m_normFile = 0;
@@ -145,6 +146,10 @@
fread(&m_data.normValuesDataOffset,
sizeof(m_data.normValuesDataOffset), 1, m_file);
fread(&m_data.peakDataOffset, sizeof(m_data.peakDataOffset), 1, m_file);
+ m_peakreader = new ResampleAudioReader(m_fileName, 4, "peak");
+ ((ResampleAudioReader*)m_peakreader)->set_output_rate(32000);
+ m_peakdataDecodeBuffer = new DecodeBuffer;
+
peaksAvailable = true;
return 1;
@@ -207,7 +212,7 @@
}
-int Peak::calculate_peaks(void* buffer, int zoomLevel, nframes_t startPos, int
pixelcount )
+int Peak::calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos,
int pixelcount )
{
PENTER3;
if (permanentFailure) {
@@ -231,45 +236,7 @@
#endif
// Macro view mode
- if (false) {
- unsigned long val = nearest_power_of_two(256);
- printf("Using VAL %ld measurements\n", val);
-
- int zoomlevel = zoomStep[zoomLevel];
-
- int offset = (startPos / zoomStep[zoomLevel-1]) * 2;
- int nearestlevel = zoomlevel / 2;
- int toread = pixelcount * 2;
-
- unsigned char readbuffer[toread];
-
- // Seek to the correct position in the buffer on hard
disk
- fseek(m_file, m_data.peakDataLevelOffsets[zoomLevel - 1 -
SAVING_ZOOM_FACTOR] + offset, SEEK_SET);
-
- // Read in the pixelcount of peakdata
- int read = fread(readbuffer, sizeof(unsigned char), toread,
m_file);
-
-
- float max = 0;
- int bufpos = 0;
- int totalnearestlevel = 0;
- int totalinterpolatedlevel = 0;
- uchar* bufpointer = (uchar*)buffer;
-
- for (int i=0; i<read; ++i) {
- max = f_max(max, readbuffer[i]);
- totalnearestlevel += nearestlevel;
-
- if ( (totalnearestlevel + zoomlevel/2) >
(totalinterpolatedlevel + zoomlevel)) {
- bufpointer[bufpos++] = (uchar)max;
- max = 0;
- totalinterpolatedlevel += zoomlevel;
- }
- }
-
- return pixelcount;
-
- } else if ( zoomLevel > MAX_ZOOM_USING_SOURCEFILE) {
+ if ( zoomLevel > MAX_ZOOM_USING_SOURCEFILE) {
int offset = (startPos / zoomStep[zoomLevel]) * 2;
@@ -280,11 +247,13 @@
pixelcount = m_data.peakDataSizeForLevel[zoomLevel -
SAVING_ZOOM_FACTOR] - offset;
}
- // Seek to the correct position in the buffer on hard disk
+/* // Seek to the correct position in the buffer on hard disk
fseek(m_file, m_data.peakDataLevelOffsets[zoomLevel -
SAVING_ZOOM_FACTOR] + offset, SEEK_SET);
// Read in the pixelcount of peakdata
- int read = fread(buffer, sizeof(unsigned char), pixelcount,
m_file);
+ int read = fread(buffer, sizeof(peak_data_t), pixelcount,
m_file);*/
+
+ int read = m_peakreader->read_from(m_peakdataDecodeBuffer,
(nframes_t)(m_data.peakDataLevelOffsets[zoomLevel - SAVING_ZOOM_FACTOR] +
offset)*sizeof(peak_data_t), (nframes_t)pixelcount);
if (read != pixelcount) {
PERROR("Could not read in all peak data, pixelcount is
%d, read count is %d", pixelcount, read);
@@ -299,6 +268,8 @@
return NO_PEAKDATA_FOUND;
}
+ *buffer = m_peakdataDecodeBuffer->destination[0];
+
return read;
// Micro view mode
@@ -306,15 +277,7 @@
nframes_t toRead = pixelcount * zoomStep[zoomLevel];
// Maybe they can be created on the stack for better
performance ?
- audio_sample_t* audiobuf[m_source->get_channel_count()];
- for (uint chan=0; chan < m_source->get_channel_count(); ++chan)
{
- audiobuf[chan] = new audio_sample_t[toRead];
- }
- audio_sample_t readbuffer[toRead*2];
-
- DecodeBuffer decodebuffer(audiobuf, readbuffer, toRead,
toRead*2, 2);
-
- nframes_t readFrames = m_source->file_read(&decodebuffer,
startPos, toRead);
+ nframes_t readFrames =
m_source->file_read(m_peakdataDecodeBuffer, startPos, toRead);
if (readFrames == 0) {
return NO_PEAKDATA_FOUND;
@@ -336,7 +299,7 @@
for(int i=0; i < zoomStep[zoomLevel]; i++) {
if (pos > readFrames)
break;
- sample = audiobuf[m_channel][pos];
+ sample =
m_peakdataDecodeBuffer->destination[m_channel][pos];
if (sample > valueMax)
valueMax = sample;
if (sample < valueMin)
@@ -360,10 +323,6 @@
printf("Process time: %d useconds\n\n", processtime);
#endif
- for (uint chan=0; chan < m_source->get_channel_count(); ++chan)
{
- delete [] audiobuf[chan];
- }
-
return count;
}
@@ -420,29 +379,21 @@
PENTER;
if (processedFrames != 64) {
- fwrite(&peakUpperValue, 1, 1, m_file);
- fwrite(&peakLowerValue, 1, 1, m_file);
+ peak_data_t data = (peak_data_t)(peakUpperValue * MAX_DB_VALUE);
+ fwrite(&data, sizeof(peak_data_t), 1, m_file);
+ data = (peak_data_t)(-1 * peakLowerValue * MAX_DB_VALUE);
+ fwrite(&data, sizeof(peak_data_t), 1, m_file);
processBufferSize += 2;
}
int totalBufferSize = 0;
- int dividingFactor = 2;
m_data.peakDataSizeForLevel[0] = processBufferSize;
totalBufferSize += processBufferSize;
for( int i = SAVING_ZOOM_FACTOR + 1; i < ZOOM_LEVELS+1; ++i) {
- int size = processBufferSize / dividingFactor;
- // If the size is an odd number, it means we have no data
available for
- // the lower level data point, so we skip that data point.
- // This does mean that the calculate_peaks() function can start
to spit
- // out errors about a missing last datapoint...
- if (size % 2) {
- size -= 1;
- }
- m_data.peakDataSizeForLevel[i - SAVING_ZOOM_FACTOR] = size;
- totalBufferSize += size;
- dividingFactor *= 2;
+ m_data.peakDataSizeForLevel[i - SAVING_ZOOM_FACTOR] =
m_data.peakDataSizeForLevel[i - SAVING_ZOOM_FACTOR - 1] / 2;
+ totalBufferSize += m_data.peakDataSizeForLevel[i -
SAVING_ZOOM_FACTOR];
}
@@ -451,9 +402,9 @@
// The routine below uses a different total buffer size calculation
// which might end up with a size >= totalbufferSize !!!
// Need to look into that, for now + 2 seems to work...
- unsigned char* saveBuffer = new unsigned char[totalBufferSize + 2];
+ peak_data_t* saveBuffer = new peak_data_t[totalBufferSize +
1*sizeof(peak_data_t)];
- int read = fread(saveBuffer, 1, processBufferSize, m_file);
+ int read = fread(saveBuffer, sizeof(peak_data_t), processBufferSize,
m_file);
if (read != processBufferSize) {
PERROR("couldn't read in all saved data?? (%d read)", read);
@@ -476,9 +427,9 @@
int count = 0;
do {
- Q_ASSERT((nextLevelBufferPos + 1) < (totalBufferSize +
2));
- saveBuffer[nextLevelBufferPos] = (unsigned char)
f_max(saveBuffer[prevLevelBufferPos], saveBuffer[prevLevelBufferPos + 2]);
- saveBuffer[nextLevelBufferPos + 1] = (unsigned char)
f_max(saveBuffer[prevLevelBufferPos + 1], saveBuffer[prevLevelBufferPos + 3]);
+ Q_ASSERT(nextLevelBufferPos <= totalBufferSize);
+ saveBuffer[nextLevelBufferPos] = (peak_data_t)
f_max(saveBuffer[prevLevelBufferPos], saveBuffer[prevLevelBufferPos + 2]);
+ saveBuffer[nextLevelBufferPos + 1] = (peak_data_t)
f_max(saveBuffer[prevLevelBufferPos + 1], saveBuffer[prevLevelBufferPos + 3]);
nextLevelBufferPos += 2;
prevLevelBufferPos += 4;
count+=4;
@@ -488,7 +439,7 @@
fseek(m_file, m_data.peakDataOffset, SEEK_SET);
- int written = fwrite(saveBuffer, 1, totalBufferSize, m_file);
+ int written = fwrite(saveBuffer, sizeof(peak_data_t), totalBufferSize,
m_file);
if (written != totalBufferSize) {
PERROR("could not write complete buffer! (only %d)", written);
@@ -546,12 +497,12 @@
if (processedFrames == 64) {
- unsigned char peakbuffer[2];
+ peak_data_t peakbuffer[2];
- peakbuffer[0] = (unsigned char) (peakUpperValue *
MAX_DB_VALUE );
- peakbuffer[1] = (unsigned char) ((-1) * (peakLowerValue
* MAX_DB_VALUE ));
+ peakbuffer[0] = (peak_data_t) (peakUpperValue *
MAX_DB_VALUE );
+ peakbuffer[1] = (peak_data_t) ((-1) * (peakLowerValue *
MAX_DB_VALUE ));
- int written = fwrite(peakbuffer, sizeof(unsigned char),
2, m_file);
+ int written = fwrite(peakbuffer, sizeof(peak_data_t),
2, m_file);
if (written != 2) {
PWARN("couldnt write data, only (%d)", written);
@@ -586,6 +537,11 @@
{
PENTER;
+#define profile
+
+#if defined (profile)
+ trav_time_t starttime = get_microseconds();
+#endif
int ret = -1;
if (prepare_processing() < 0) {
@@ -612,13 +568,7 @@
}
}
- audio_sample_t* buffer[m_source->get_channel_count()];
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- buffer[chan] = new audio_sample_t[bufferSize];
- }
- audio_sample_t* readbuffer = new audio_sample_t[bufferSize * 2];
-
- DecodeBuffer decodebuffer(buffer, readbuffer, bufferSize, bufferSize*2,
m_source->get_channel_count());
+ DecodeBuffer decodebuffer;
do {
if (interuptPeakBuild) {
@@ -632,7 +582,7 @@
PERROR("readFrames < 0 during peak building");
break;
}
- process(buffer[m_channel], readFrames);
+ process(decodebuffer.destination[m_channel], readFrames);
totalReadFrames += readFrames;
p = (int) ((float)totalReadFrames /
((float)m_source->get_nframes() / 100.0));
@@ -652,11 +602,11 @@
ret = 1;
out:
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- delete [] buffer[chan];
- }
- delete [] readbuffer;
+#if defined (profile)
+ long processtime = (long) (get_microseconds() - starttime);
+ printf("Process time: %d seconds\n\n", (int)(processtime/1000));
+#endif
return ret;
}
@@ -682,21 +632,9 @@
startpos += 1;
int toRead = (int) ((startpos * NORMALIZE_CHUNK_SIZE) -
startframe);
- audio_sample_t* buffer[m_source->get_channel_count()];
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- buffer[chan] = new audio_sample_t[toRead];
- }
- audio_sample_t readbuffer[toRead * 2];
-
- DecodeBuffer decodebuffer(buffer, readbuffer, toRead, toRead*2,
m_source->get_channel_count());
-
- int read = m_source->file_read(&decodebuffer, startframe,
toRead);
-
- maxamp = Mixer::compute_peak(buffer[m_channel], read, maxamp);
+ int read = m_source->file_read(m_peakdataDecodeBuffer,
startframe, toRead);
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- delete [] buffer[chan];
- }
+ maxamp =
Mixer::compute_peak(m_peakdataDecodeBuffer->destination[m_channel], read,
maxamp);
}
@@ -706,19 +644,9 @@
int endpos = (int) f;
int toRead = (int) ((f - (endframe / NORMALIZE_CHUNK_SIZE)) *
NORMALIZE_CHUNK_SIZE);
- audio_sample_t* buffer[m_source->get_channel_count()];
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- buffer[chan] = new audio_sample_t[toRead];
- }
- DecodeBuffer decodebuffer(buffer, readbuffer, toRead, toRead*2,
m_source->get_channel_count());
-
- int read = m_source->file_read(&decodebuffer, endframe - toRead,
toRead);
+ int read = m_source->file_read(m_peakdataDecodeBuffer, endframe -
toRead, toRead);
- maxamp = Mixer::compute_peak(buffer[m_channel], read, maxamp);
-
- for (uint chan=0; chan<m_source->get_channel_count(); ++chan) {
- delete [] buffer[chan];
- }
+ maxamp =
Mixer::compute_peak(m_peakdataDecodeBuffer->destination[m_channel], read,
maxamp);
// Now that we have covered both boundary situations,
// read in the cached normvalues, and calculate the highest value!
Index: core/Peak.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- core/Peak.h 18 May 2007 10:40:58 -0000 1.14
+++ core/Peak.h 28 Aug 2007 19:51:52 -0000 1.15
@@ -34,6 +34,8 @@
class AudioSource;
class Peak;
class PPThread;
+class AbstractAudioReader;
+class DecodeBuffer;
class PeakProcessor : public QObject
{
@@ -116,7 +118,7 @@
void process(audio_sample_t* buffer, nframes_t frames);
int prepare_processing();
int finish_processing();
- int calculate_peaks(void* buffer, int zoomLevel, nframes_t startPos,
int count);
+ int calculate_peaks(float** buffer, int zoomLevel, nframes_t startPos,
int count);
void close();
@@ -144,6 +146,8 @@
FILE* m_normFile;
QString m_fileName;
QString m_normFileName;
+ AbstractAudioReader* m_peakreader;
+ DecodeBuffer* m_peakdataDecodeBuffer;
int create_from_scratch();
Index: core/ReadSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- core/ReadSource.cpp 21 Aug 2007 19:47:24 -0000 1.51
+++ core/ReadSource.cpp 28 Aug 2007 19:51:52 -0000 1.52
@@ -273,32 +273,21 @@
}
-int ReadSource::file_read(DecodeBuffer* buffer, nframes_t start, nframes_t
cnt) const
+int ReadSource::file_read(DecodeBuffer* buffer, TimeRef& start, nframes_t cnt)
const
{
#if defined (profile)
trav_time_t starttime = get_microseconds();
#endif
- if (m_audioReader->get_num_channels() == 1) {
nframes_t result = m_audioReader->read_from(buffer, start, cnt);
-#if defined (profile)
- int processtime = (int) (get_microseconds() - starttime);
- if (processtime > 40000)
- printf("Process time for %s: %d useconds\n\n",
QS_C(m_fileName), processtime);
-#endif
- return (int)result;
- }
-
- // The readbuffer 'assumes' that there is max 2 channels...
- Q_ASSERT(m_audioReader->get_num_channels() <= 2);
- nframes_t nread = m_audioReader->read_from(buffer, start, cnt);
#if defined (profile)
int processtime = (int) (get_microseconds() - starttime);
- if (processtime > 40000)
+ if (processtime > 40000) {
printf("Process time for %s: %d useconds\n\n",
QS_C(m_fileName), processtime);
+ }
#endif
- return nread;
+ return result;
}
@@ -355,7 +344,7 @@
-int ReadSource::rb_read(audio_sample_t** dst, nframes_t start, nframes_t count)
+int ReadSource::rb_read(audio_sample_t** dst, TimeRef& start, nframes_t count)
{
if ( ! m_rbReady ) {
@@ -363,22 +352,27 @@
return 0;
}
- nframes_t relativepos = m_rbRelativeFileReadPos.to_frame(m_rate);
+ int devicerate = audiodevice().get_sample_rate();
+
+ if (start != m_rbRelativeFileReadPos) {
- if (start != relativepos) {
- uint available = m_buffers.at(0)->read_space();
-// printf("start %d, m_rbFileReadPos %d\n", start,
m_rbRelativeFileReadPos);
- if ( (start > relativepos) && (relativepos + available) >
(start + count)) {
- uint advance = start - relativepos;
- if (available < advance) {
+ TimeRef availabletime(m_buffers.at(0)->read_space(),
devicerate);
+
+ if ( (start > m_rbRelativeFileReadPos) &&
(m_rbRelativeFileReadPos + availabletime) > (start + TimeRef(count,
devicerate))) {
+
+ TimeRef advance = start - m_rbRelativeFileReadPos;
+ if (availabletime < advance) {
printf("available < advance !!!!!!!\n");
}
for (int i=m_buffers.size()-1; i>=0; --i) {
- m_buffers.at(i)->increment_read_ptr(advance);
+
m_buffers.at(i)->increment_read_ptr(advance.to_frame(devicerate));
}
- m_rbRelativeFileReadPos.add_frames(advance, m_rate);
+
+ m_rbRelativeFileReadPos += advance;
} else {
- start_resync(start + (m_clip->get_track_start_frame() +
m_clip->get_source_start_frame()));
+ printf("calling start_resync\n");
+ TimeRef synclocation = start +
m_clip->get_track_start_location() + m_clip->get_source_start_location();
+ start_resync(synclocation);
return 0;
}
}
@@ -395,7 +389,7 @@
}
- m_rbRelativeFileReadPos.add_frames(readcount, m_rate);
+ m_rbRelativeFileReadPos.add_frames(readcount, devicerate);
return readcount;
}
@@ -403,7 +397,7 @@
int ReadSource::rb_file_read(DecodeBuffer* buffer, nframes_t cnt)
{
- int readFrames = file_read(buffer, m_rbFileReadPos.to_frame(m_rate),
cnt);
+ int readFrames = file_read(buffer, m_rbFileReadPos, cnt);
m_rbFileReadPos.add_frames(readFrames, m_rate);
return readFrames;
@@ -417,7 +411,7 @@
// printf("rb_seek_to_file_position:: seeking to %d\n", position);
// calculate position relative to the file!
- TimeRef fileposition = position -
TimeRef(m_clip->get_track_start_frame() + m_clip->get_source_start_frame(),
m_rate);
+ TimeRef fileposition = position - m_clip->get_track_start_location() -
m_clip->get_source_start_location();
if (m_rbFileReadPos == fileposition) {
// printf("ringbuffer allready at position %d\n", position);
@@ -497,14 +491,7 @@
}
-void ReadSource::recover_from_buffer_underrun(nframes_t position)
-{
-// printf("buffer underrun detected!\n");
- m_bufferUnderRunDetected = 1;
- start_resync(position);
-}
-
-void ReadSource::start_resync( nframes_t position )
+void ReadSource::start_resync(TimeRef& position)
{
printf("starting resync!\n");
m_syncPos = position;
@@ -529,8 +516,7 @@
}
if (!m_syncInProgress) {
- TimeRef position(m_syncPos, m_rate);
- rb_seek_to_file_position(position);
+ rb_seek_to_file_position(m_syncPos);
m_syncInProgress = 1;
}
@@ -570,7 +556,8 @@
m_buffers.append(new RingBufferNPT<float>(m_bufferSize));
}
- start_resync(m_clip->get_song()->get_working_frame());
+ TimeRef synclocation = m_clip->get_song()->get_working_location();
+ start_resync(synclocation);
}
BufferStatus* ReadSource::get_buffer_status()
@@ -610,3 +597,8 @@
//eof
+int ReadSource::file_read(DecodeBuffer * buffer, nframes_t start, nframes_t
cnt)
+{
+ TimeRef startlocation(start, get_rate() );
+ return file_read(buffer, startlocation, cnt);
+}
Index: core/ReadSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- core/ReadSource.h 17 Aug 2007 00:18:30 -0000 1.34
+++ core/ReadSource.h 28 Aug 2007 19:51:52 -0000 1.35
@@ -30,7 +30,7 @@
class AbstractAudioReader;
class AudioClip;
struct BufferStatus;
-struct DecodeBuffer;
+class DecodeBuffer;
class ReadSource : public AudioSource
{
@@ -54,10 +54,11 @@
int set_state( const QDomNode& node );
QDomNode get_state(QDomDocument doc);
- int rb_read(audio_sample_t** dest, nframes_t start, nframes_t cnt);
+ int rb_read(audio_sample_t** dest, TimeRef& start, nframes_t cnt);
void rb_seek_to_file_position(TimeRef& position);
- int file_read(DecodeBuffer* buffer, nframes_t start, nframes_t cnt)
const;
+ int file_read(DecodeBuffer* buffer, TimeRef& start, nframes_t cnt)
const;
+ int file_read(DecodeBuffer* buffer, nframes_t start, nframes_t cnt);
int init();
int get_error() const {return m_error;}
@@ -85,7 +86,7 @@
bool m_silent;
TimeRef m_rbFileReadPos;
TimeRef m_rbRelativeFileReadPos;
- volatile size_t m_syncPos;
+ TimeRef m_syncPos;
volatile size_t m_rbReady;
volatile size_t m_needSync;
volatile size_t m_active;
@@ -101,9 +102,8 @@
int ref() { return m_refcount++;}
void private_init();
- void start_resync(nframes_t position);
+ void start_resync(TimeRef& position);
void finish_resync();
- void recover_from_buffer_underrun(nframes_t position);
int rb_file_read(DecodeBuffer* buffer, nframes_t cnt);
friend class ResourcesManager;
Index: core/Song.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Song.cpp,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -b -r1.131 -r1.132
--- core/Song.cpp 17 Aug 2007 00:18:30 -0000 1.131
+++ core/Song.cpp 28 Aug 2007 19:51:52 -0000 1.132
@@ -197,8 +197,10 @@
m_sby = e.attribute("sby", "0").toInt();
set_first_visible_frame(e.attribute( "firstVisibleFrame", "0"
).toUInt());
set_work_at(e.attribute( "workingFrame", "0").toUInt());
-// m_transportFrame = e.attribute( "transportFrame", "0").toUInt();
- m_transportLocation.set_position(e.attribute( "transportFrame",
"0").toUInt(), audiodevice().get_sample_rate());
+
+ bool ok;
+ m_transportLocation = TimeRef(e.attribute( "transportlocation",
"0").toLongLong(&ok));
+
// Start seeking to the 'old' transport pos
set_transport_pos(m_transportLocation);
set_snapping(e.attribute("snapping", "0").toInt());
@@ -236,7 +238,7 @@
properties.setAttribute("artists", artists);
properties.setAttribute("firstVisibleFrame", firstVisibleFrame);
properties.setAttribute("workingFrame", (uint)workingFrame);
- properties.setAttribute("transportFrame",
(uint)m_transportLocation.to_frame(audiodevice().get_sample_rate()));
+ properties.setAttribute("transportlocation",
m_transportLocation.to_universal_frame());
properties.setAttribute("hzoom", m_hzoom);
properties.setAttribute("sbx", m_sbx);
properties.setAttribute("sby", m_sby);
@@ -1332,3 +1334,9 @@
// eof
+TimeRef Song::get_working_location() const
+{
+ TimeRef location(workingFrame, audiodevice().get_sample_rate());
+ return location;
+}
+
Index: core/Song.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Song.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- core/Song.h 17 Aug 2007 00:18:30 -0000 1.65
+++ core/Song.h 28 Aug 2007 19:51:52 -0000 1.66
@@ -88,6 +88,7 @@
nframes_t get_first_visible_frame() const;
nframes_t get_last_frame() const;
const TimeRef& get_transport_location() const {return
m_transportLocation;}
+ TimeRef get_working_location() const;
const TimeRef& get_new_transport_location() const {return
m_newTransportLocation;}
Index: engine/defines.h
===================================================================
RCS file: /sources/traverso/traverso/src/engine/defines.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- engine/defines.h 17 Aug 2007 00:18:31 -0000 1.15
+++ engine/defines.h 28 Aug 2007 19:51:52 -0000 1.16
@@ -75,6 +75,8 @@
return nframes_t(m_position / (UNIVERSAL_SAMPLE_RATE / rate));
}
+ qint64 to_universal_frame() const {return m_position;}
+
friend int operator!=(const TimeRef& left, const TimeRef& right) {
return left.m_position != right.m_position;
}
@@ -138,6 +140,8 @@
typedef unsigned long channel_t;
typedef float audio_sample_t;
+//typedef unsigned char peak_data_t;
+typedef short peak_data_t;
typedef FastDelegate1<nframes_t, int> ProcessCallback;
Index: traverso/songcanvas/AudioClipView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/AudioClipView.cpp,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -b -r1.82 -r1.83
--- traverso/songcanvas/AudioClipView.cpp 15 Aug 2007 20:22:43 -0000
1.82
+++ traverso/songcanvas/AudioClipView.cpp 28 Aug 2007 19:51:52 -0000
1.83
@@ -254,8 +254,8 @@
int channels = m_clip->get_channels();
int peakdatacount = microView ? pixelcount : pixelcount * 2;
- int buffersize = microView ? sizeof(short) * peakdatacount :
sizeof(unsigned char) * peakdatacount;
- unsigned char buffers[channels][buffersize];
+ int buffersize = microView ? sizeof(short) * peakdatacount :
sizeof(peak_data_t) * peakdatacount;
+ float* buffers[channels];
float pixeldata[channels][buffersize];
float curvemixdown[buffersize];
@@ -263,7 +263,7 @@
// 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++) {
- memset(buffers[chan], 0, buffersize * sizeof(unsigned char));
+// memset(buffers[chan], 0, buffersize * sizeof(peak_data_t));
nframes_t clipstartoffset = m_clip->get_source_start_frame();
@@ -272,7 +272,7 @@
PERROR("No Peak object available for clip %s channel
%d", QS_C(m_clip->get_name()), chan);
return;
}
- int availpeaks = peak->calculate_peaks( buffers[chan],
+ int availpeaks = peak->calculate_peaks( &buffers[chan],
microView ?
m_song->get_hzoom() : m_song->get_hzoom() + 1,
(xstart *
m_sv->scalefactor) + clipstartoffset,
microView ?
peakdatacount : peakdatacount / 2);
Index: audiofileio/decode/PeakDataReader.cpp
===================================================================
RCS file: audiofileio/decode/PeakDataReader.cpp
diff -N audiofileio/decode/PeakDataReader.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ audiofileio/decode/PeakDataReader.cpp 28 Aug 2007 19:51:51 -0000
1.1
@@ -0,0 +1,116 @@
+/*
+Copyright (C) 2007 Ben Levitt
+
+This file is part of Traverso
+
+Traverso is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "PeakDataReader.h"
+#include <QFile>
+#include <QString>
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+
+PeakDataReader::PeakDataReader(QString filename)
+ : AbstractAudioReader(filename)
+{
+
+ m_file = fopen(m_fileName.toUtf8().data(),"rb");
+
+ if (! m_file) {
+ PERROR("Couldn't open peak file for reading! (%s)",
m_fileName.toUtf8().data());
+ m_length = m_channels = 0;
+ return;
+ }
+
+ fseek (m_file, 0, SEEK_END);
+ m_channels = 1;
+ m_length = ftell (m_file);
+ m_rate = 32000;
+
+}
+
+
+PeakDataReader::~PeakDataReader()
+{
+ if (m_file) {
+ fclose(m_file);
+ }
+}
+
+
+bool PeakDataReader::can_decode(QString filename)
+{
+ if (!filename.contains(".peak")) return false;
+ return true;
+}
+
+
+bool PeakDataReader::seek_private(nframes_t start)
+{
+ Q_ASSERT(m_file);
+
+
+ if (start >= m_length) {
+ return false;
+ }
+
+ if (fseek (m_file, start, SEEK_SET) < 0) {
+ PERROR("PeakDataReader: could not seek to data point %d within
%s", start, m_fileName.toUtf8().data());
+ return false;
+ }
+
+ return true;
+}
+
+
+nframes_t PeakDataReader::read_private(DecodeBuffer* buffer, nframes_t
frameCount)
+{
+ Q_ASSERT(m_file);
+
+ int framesRead = fread(buffer->readBuffer, sizeof(peak_data_t),
frameCount, m_file);
+
+ peak_data_t* readbuffer = (peak_data_t*)buffer->readBuffer;
+
+ // De-interlace
+ switch (m_channels) {
+ case 1:
+ for (int f = 0; f < framesRead; f++) {
+ buffer->destination[0][f] =
(float)readbuffer[f];
+ }
+ break;
+ case 2:
+ for (int f = 0; f < framesRead; f++) {
+ int pos = f*2;
+ buffer->destination[0][f] =
(float)readbuffer[pos];
+ buffer->destination[1][f] =
(float)readbuffer[pos + 1];
+ }
+ break;
+ default:
+ for (int f = 0; f < framesRead; f++) {
+ for (int c = 0; c < m_channels; c++) {
+ buffer->destination[c][f] =
(float)readbuffer[f * m_channels + c];
+ }
+ }
+ }
+
+ return framesRead;
+}
+
Index: audiofileio/decode/PeakDataReader.h
===================================================================
RCS file: audiofileio/decode/PeakDataReader.h
diff -N audiofileio/decode/PeakDataReader.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ audiofileio/decode/PeakDataReader.h 28 Aug 2007 19:51:51 -0000 1.1
@@ -0,0 +1,48 @@
+/*
+Copyright (C) 2007 Remon Sijrier
+
+This file is part of Traverso
+
+Traverso is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef PEAK_DATA_READER_H
+#define PEAK_DATA_READER_H
+
+#include <AbstractAudioReader.h>
+
+
+class PeakDataReader : public AbstractAudioReader
+{
+ public:
+ PeakDataReader(QString filename);
+ ~PeakDataReader();
+
+ QString decoder_type() const {return "sndfile";}
+
+ static bool can_decode(QString filename);
+
+ protected:
+ bool seek_private(nframes_t start);
+ nframes_t read_private(DecodeBuffer* buffer, nframes_t
frameCount);
+
+
+ private:
+ FILE* m_file;
+
+};
+
+#endif