| 197 | // Return true if a full window of samples is prepared; manage the queue. |
| 198 | template <class InputSample> |
| 199 | bool Spectrogram::GetNextWindowOfSamples(const std::vector<InputSample>& input, |
| 200 | int* input_start) { |
| 201 | auto input_it = input.begin() + *input_start; |
| 202 | int input_remaining = input.end() - input_it; |
| 203 | if (samples_to_next_step_ > input_remaining) { |
| 204 | // Copy in as many samples are left and return false, no full window. |
| 205 | input_queue_.insert(input_queue_.end(), input_it, input.end()); |
| 206 | *input_start += input_remaining; // Increases it to input.size(). |
| 207 | samples_to_next_step_ -= input_remaining; |
| 208 | return false; // Not enough for a full window. |
| 209 | } else { |
| 210 | // Copy just enough into queue to make a new window, then trim the |
| 211 | // front off the queue to make it window-sized. |
| 212 | input_queue_.insert(input_queue_.end(), input_it, |
| 213 | input_it + samples_to_next_step_); |
| 214 | *input_start += samples_to_next_step_; |
| 215 | input_queue_.erase( |
| 216 | input_queue_.begin(), |
| 217 | input_queue_.begin() + input_queue_.size() - window_length_); |
| 218 | // DCHECK_EQ(window_length_, input_queue_.size()); |
| 219 | samples_to_next_step_ = step_length_; // Be ready for next time. |
| 220 | return true; // Yes, input_queue_ now contains exactly a window-full. |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void Spectrogram::ProcessCoreFFT() { |
| 225 | for (int j = 0; j < window_length_; ++j) { |