X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.0%2Fcinelerra%2Findexthread.C;h=efe938e3c1fec333d0e015816ef213b9696ac68a;hb=6c0c8bd0e577001d1cc18c6c27d58e62f58a6bff;hp=c990e5fbc7164c37a85b40a3a49839ad2b8a1a3d;hpb=2d99bb8ce591f05a31464b517d85dc2bc35b2abe;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.0/cinelerra/indexthread.C b/cinelerra-5.0/cinelerra/indexthread.C index c990e5fb..efe938e3 100644 --- a/cinelerra-5.0/cinelerra/indexthread.C +++ b/cinelerra-5.0/cinelerra/indexthread.C @@ -54,24 +54,6 @@ IndexThread::IndexThread(MWindow *mwindow, this->mwindow = mwindow; this->index_filename = index_filename; this->index_file = index_file; - IndexState *index_state = index_file->get_state(); - -// initialize output data -// size of output file in floats - int64_t index_size = mwindow->preferences->index_size / - sizeof(float) + 1; - - delete [] index_state->index_buffer; - delete [] index_state->index_offsets; - delete [] index_state->index_sizes; - - index_state->channels = index_file->source_channels; -// buffer used for drawing during the build. This is not deleted in the index_state - index_state->index_buffer = new float[index_size]; -// This is deleted in the index_state's destructor - index_state->index_offsets = new int64_t[index_state->channels]; - index_state->index_sizes = new int64_t[index_state->channels]; - bzero(index_state->index_buffer, index_size * sizeof(float)); // initialization is completed in run for(int i = 0; i < TOTAL_INDEX_BUFFERS; i++) @@ -84,7 +66,6 @@ IndexThread::IndexThread(MWindow *mwindow, output_lock[i] = new Condition(0, "IndexThread::output_lock"); input_lock[i] = new Condition(1, "IndexThread::input_lock"); - for(int j = 0; j < index_file->source_channels; j++) { buffer_in[i][j] = new Samples(buffer_size); @@ -99,8 +80,6 @@ IndexThread::IndexThread(MWindow *mwindow, IndexThread::~IndexThread() { - IndexState *index_state = index_file->get_state(); - for(int i = 0; i < TOTAL_INDEX_BUFFERS; i++) { for(int j = 0; j < index_file->source_channels; j++) @@ -111,9 +90,6 @@ IndexThread::~IndexThread() delete output_lock[i]; delete input_lock[i]; } - - delete [] index_state->index_buffer; - index_state->index_buffer = 0; } int IndexThread::start_build() @@ -134,113 +110,26 @@ int IndexThread::stop_build() void IndexThread::run() { int done = 0; - -// current high samples in index - int64_t *highpoint; -// current low samples in the index - int64_t *lowpoint; -// position in current indexframe - int64_t *frame_position; - int first_point = 1; IndexState *index_state = index_file->get_state(); - - highpoint = new int64_t[index_file->source_channels]; - lowpoint = new int64_t[index_file->source_channels]; - frame_position = new int64_t[index_file->source_channels]; - -// predict first highpoint for each channel plus padding and initialize it - for(int64_t channel = 0; channel < index_file->source_channels; channel++) - { - highpoint[channel] = - index_state->index_offsets[channel] = - (length_source / index_state->index_zoom * 2 + 1) * channel; - lowpoint[channel] = highpoint[channel] + 1; - - index_state->index_sizes[channel] = 0; - frame_position[channel] = 0; - } - - //int64_t index_start = 0; // end of index during last edit update - index_state->index_end = 0; // samples in source completed - index_state->old_index_end = 0; + int index_channels = index_file->source_channels; + index_state->add_audio_stream(index_channels, index_file->source_length); + index_state->init_scan(mwindow->preferences->index_size); index_state->index_status = INDEX_BUILDING; - int64_t zoomx = index_state->index_zoom; - float *index_buffer = index_state->index_buffer; // output of index build - int64_t *index_sizes = index_state->index_sizes; - int64_t *index_offsets = index_state->index_offsets; -//printf("IndexThread::run %d\n", __LINE__); -//index_state->dump(); -//printf("IndexThread::run %d\n", __LINE__); - while(!interrupt_flag && !done) - { + while(!interrupt_flag && !done) { output_lock[current_buffer]->lock("IndexThread::run"); if(last_buffer[current_buffer]) done = 1; - if(!interrupt_flag && !done) - { + if(!interrupt_flag && !done) { // process buffer - int64_t fragment_size = input_len[current_buffer]; - -// printf("IndexThread::run %d index_state->channels=%d index_file->source_channels=%d index_state->index_buffer=%p buffer_in=%p\n", -// __LINE__, -// index_state->channels, -// index_file->source_channels, -// index_state->index_buffer, -// buffer_in); - for(int channel = 0; channel < index_file->source_channels; channel++) - { -SET_TRACE - int64_t *highpoint_channel = &highpoint[channel]; - int64_t *lowpoint_channel = &lowpoint[channel]; - int64_t *frame_position_channel = &frame_position[channel]; - double *buffer_source = buffer_in[current_buffer][channel]->get_data(); - -SET_TRACE - for(int64_t i = 0; i < fragment_size; i++) - { - if(*frame_position_channel == zoomx) - { - *highpoint_channel += 2; - *lowpoint_channel += 2; - *frame_position_channel = 0; -// store and reset output values - index_buffer[*highpoint_channel] = - index_buffer[*lowpoint_channel] = - buffer_source[i]; - index_sizes[channel] = - *lowpoint_channel - - index_offsets[channel] + - 1; - } - else - { -// get high and low points - if(first_point) - { - index_buffer[*highpoint_channel] = - index_buffer[*lowpoint_channel] = buffer_source[i]; - first_point = 0; - } - else - { - if(buffer_source[i] > index_buffer[*highpoint_channel]) - index_buffer[*highpoint_channel] = buffer_source[i]; - else - if(buffer_source[i] < index_buffer[*lowpoint_channel]) - index_buffer[*lowpoint_channel] = buffer_source[i]; - } - } - (*frame_position_channel)++; - } // end index one buffer -SET_TRACE + int64_t len = input_len[current_buffer]; + for( int ch=0; chget_data(); + index_state->put_data(ch,samples,len); } - index_state->index_end += fragment_size; - // draw simultaneously with build index_file->redraw_edits(0); - //index_start = index_state->index_end; } input_lock[current_buffer]->unlock(); @@ -251,15 +140,8 @@ SET_TRACE index_file->redraw_edits(1); // write the index file to disk - index_state->write_index(index_filename, - (lowpoint[index_file->source_channels - 1] + 1) * sizeof(float), - index_file->indexable->is_asset ? (Asset*)index_file->indexable : 0, - index_file->source_length); - - - delete [] highpoint; - delete [] lowpoint; - delete [] frame_position; + Asset *asset = index_file->indexable->is_asset ? (Asset*)index_file->indexable : 0; + index_state->create_index(index_filename, asset); }