- j = 0;
- /*
- * we have several flavors of the same basic loop, optimized for
- * different conditions:
- */
- if(encoder->protected_->max_lpc_order > 0) {
- if(encoder->protected_->do_mid_side_stereo && channels == 2) {
- /*
- * stereo coding: unroll channel loop
- * with LPC: calculate floating point version of signal
- */
- do {
- if(encoder->protected_->verify)
- append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
-
- /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- x = mid = side = buffer[0][j];
- encoder->private_->integer_signal[0][i] = x;
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal[0][i] = (FLAC__real)x;
-#endif
- x = buffer[1][j];
- encoder->private_->integer_signal[1][i] = x;
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal[1][i] = (FLAC__real)x;
-#endif
- mid += x;
- side -= x;
- mid >>= 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
- encoder->private_->integer_signal_mid_side[1][i] = side;
- encoder->private_->integer_signal_mid_side[0][i] = mid;
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal_mid_side[1][i] = (FLAC__real)side;
- encoder->private_->real_signal_mid_side[0][i] = (FLAC__real)mid;
-#endif
- encoder->private_->current_sample_number++;
- }
- /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
- if(i > blocksize) {
- if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
- return false;
- /* move unprocessed overread samples to beginnings of arrays */
- FLAC__ASSERT(i == blocksize+OVERREAD_);
- FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
- i--;
- encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
- encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
- encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
- encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal[0][0] = encoder->private_->real_signal[0][i];
- encoder->private_->real_signal[1][0] = encoder->private_->real_signal[1][i];
- encoder->private_->real_signal_mid_side[0][0] = encoder->private_->real_signal_mid_side[0][i];
- encoder->private_->real_signal_mid_side[1][0] = encoder->private_->real_signal_mid_side[1][i];
-#endif
- encoder->private_->current_sample_number = 1;
- }
- } while(j < samples);
- }
- else {
- /*
- * independent channel coding: buffer each channel in inner loop
- * with LPC: calculate floating point version of signal
- */
- do {
- if(encoder->protected_->verify)
- append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
-
- /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- for(channel = 0; channel < channels; channel++) {
- x = buffer[channel][j];
- encoder->private_->integer_signal[channel][i] = x;
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal[channel][i] = (FLAC__real)x;
-#endif
- }
- encoder->private_->current_sample_number++;
- }
- /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
- if(i > blocksize) {
- if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
- return false;
- /* move unprocessed overread samples to beginnings of arrays */
- FLAC__ASSERT(i == blocksize+OVERREAD_);
- FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
- i--;
- for(channel = 0; channel < channels; channel++) {
- encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][i];
-#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->real_signal[channel][0] = encoder->private_->real_signal[channel][i];
-#endif
- }
- encoder->private_->current_sample_number = 1;
- }
- } while(j < samples);
- }
- }
- else {
- if(encoder->protected_->do_mid_side_stereo && channels == 2) {
- /*
- * stereo coding: unroll channel loop
- * without LPC: no need to calculate floating point version of signal
- */
- do {
- if(encoder->protected_->verify)
- append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
-
- /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- encoder->private_->integer_signal[0][i] = mid = side = buffer[0][j];
- x = buffer[1][j];
- encoder->private_->integer_signal[1][i] = x;
- mid += x;
- side -= x;
- mid >>= 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
- encoder->private_->integer_signal_mid_side[1][i] = side;
- encoder->private_->integer_signal_mid_side[0][i] = mid;
- encoder->private_->current_sample_number++;
- }
- /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
- if(i > blocksize) {
- if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
- return false;
- /* move unprocessed overread samples to beginnings of arrays */
- FLAC__ASSERT(i == blocksize+OVERREAD_);
- FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
- i--;
- encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
- encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
- encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
- encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
- encoder->private_->current_sample_number = 1;
- }
- } while(j < samples);