5 #include "edlsession.h"
8 #include "indexthread.h"
11 #include "mwindowgui.h"
12 #include "preferences.h"
13 #include "mainsession.h"
15 #include "trackcanvas.h"
18 // Read data from buffers and calculate peaks
20 IndexThread::IndexThread(MWindow *mwindow,
21 IndexFile *index_file,
25 int64_t length_source)
28 this->buffer_size = buffer_size;
29 this->length_source = length_source;
30 this->mwindow = mwindow;
31 this->index_filename = index_filename;
32 this->index_file = index_file;
34 // initialize output data
35 int64_t index_size = mwindow->preferences->index_size /
36 sizeof(float) + 1; // size of output file in floats
38 delete [] asset->index_buffer;
39 delete [] asset->index_offsets;
40 delete [] asset->index_sizes;
42 // buffer used for drawing during the build. This is not deleted in the asset
43 asset->index_buffer = new float[index_size];
44 // This is deleted in the asset's destructor
45 asset->index_offsets = new int64_t[asset->channels];
46 asset->index_sizes = new int64_t[asset->channels];
47 bzero(asset->index_buffer, index_size * sizeof(float));
49 // initialization is completed in run
50 for(int i = 0; i < TOTAL_BUFFERS; i++)
52 buffer_in[i] = new double*[asset->channels];
53 output_lock[i] = new Condition(0, "IndexThread::output_lock");
54 input_lock[i] = new Condition(1, "IndexThread::input_lock");
55 for(int j = 0; j < asset->channels; j++)
57 buffer_in[i][j] = new double[buffer_size];
64 IndexThread::~IndexThread()
66 for(int i = 0; i < TOTAL_BUFFERS; i++)
68 for(int j = 0; j < asset->channels; j++)
70 delete [] buffer_in[i][j];
72 delete [] buffer_in[i];
73 delete output_lock[i];
77 delete [] asset->index_buffer;
78 asset->index_buffer = 0;
81 int IndexThread::start_build()
86 for(int i = 0; i < TOTAL_BUFFERS; i++) last_buffer[i] = 0;
90 int IndexThread::stop_build()
95 void IndexThread::run()
99 // current high samples in index
101 // current low samples in the index
103 // position in current indexframe
104 int64_t *frame_position;
107 highpoint = new int64_t[asset->channels];
108 lowpoint = new int64_t[asset->channels];
109 frame_position = new int64_t[asset->channels];
111 // predict first highpoint for each channel plus padding and initialize it
112 for(int64_t channel = 0; channel < asset->channels; channel++)
115 asset->index_offsets[channel] =
116 (length_source / asset->index_zoom * 2 + 1) * channel;
117 lowpoint[channel] = highpoint[channel] + 1;
119 frame_position[channel] = 0;
122 int64_t index_start = 0; // end of index during last edit update
123 asset->index_end = 0; // samples in source completed
124 asset->old_index_end = 0;
125 asset->index_status = INDEX_BUILDING;
126 int64_t zoomx = asset->index_zoom;
127 float *index_buffer = asset->index_buffer; // output of index build
129 while(!interrupt_flag && !done)
131 output_lock[current_buffer]->lock("IndexThread::run");
133 if(last_buffer[current_buffer]) done = 1;
134 if(!interrupt_flag && !done)
137 int64_t fragment_size = input_len[current_buffer];
139 for(int channel = 0; channel < asset->channels; channel++)
141 int64_t *highpoint_channel = &highpoint[channel];
142 int64_t *lowpoint_channel = &lowpoint[channel];
143 int64_t *frame_position_channel = &frame_position[channel];
144 double *buffer_source = buffer_in[current_buffer][channel];
146 for(int64_t i = 0; i < fragment_size; i++)
148 if(*frame_position_channel == zoomx)
150 *highpoint_channel += 2;
151 *lowpoint_channel += 2;
152 *frame_position_channel = 0;
153 // store and reset output values
154 index_buffer[*highpoint_channel] =
155 index_buffer[*lowpoint_channel] =
157 asset->index_sizes[channel] = *lowpoint_channel -
158 asset->index_offsets[channel] +
163 // get high and low points
166 index_buffer[*highpoint_channel] =
167 index_buffer[*lowpoint_channel] = buffer_source[i];
172 if(buffer_source[i] > index_buffer[*highpoint_channel])
173 index_buffer[*highpoint_channel] = buffer_source[i];
175 if(buffer_source[i] < index_buffer[*lowpoint_channel])
176 index_buffer[*lowpoint_channel] = buffer_source[i];
179 (*frame_position_channel)++;
180 } // end index one buffer
183 asset->index_end += fragment_size;
185 // draw simultaneously with build
186 index_file->redraw_edits(0);
187 index_start = asset->index_end;
190 input_lock[current_buffer]->unlock();
192 if(current_buffer >= TOTAL_BUFFERS) current_buffer = 0;
195 index_file->redraw_edits(1);
198 // write the index file to disk
199 asset->write_index(index_filename,
200 (lowpoint[asset->channels - 1] + 1) * sizeof(float));
205 delete [] frame_position;
213 // c-file-style: "linux"