| 183 | } |
| 184 | |
| 185 | bool PaulstretchBase::ProcessOne( |
| 186 | const WaveChannel& track, WaveChannel& outputTrack, double t0, double t1, |
| 187 | int count) |
| 188 | { |
| 189 | const auto badAllocMessage = XO("Requested value exceeds memory capacity."); |
| 190 | |
| 191 | const auto rate = track.GetTrack().GetRate(); |
| 192 | const auto stretch_buf_size = GetBufferSize(rate); |
| 193 | if (stretch_buf_size == 0) |
| 194 | { |
| 195 | BasicUI::ShowMessageBox(badAllocMessage); |
| 196 | return {}; |
| 197 | } |
| 198 | |
| 199 | double amount = this->mAmount; |
| 200 | |
| 201 | auto start = track.TimeToLongSamples(t0); |
| 202 | auto end = track.TimeToLongSamples(t1); |
| 203 | auto len = end - start; |
| 204 | |
| 205 | const auto minDuration = stretch_buf_size * 2 + 1; |
| 206 | if (minDuration < stretch_buf_size) |
| 207 | { |
| 208 | // overflow! |
| 209 | BasicUI::ShowMessageBox(badAllocMessage); |
| 210 | return {}; |
| 211 | } |
| 212 | |
| 213 | if (len < minDuration) |
| 214 | { // error because the selection is too short |
| 215 | |
| 216 | float maxTimeRes = log(len.as_double()) / log(2.0); |
| 217 | maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5); |
| 218 | maxTimeRes = maxTimeRes / rate; |
| 219 | |
| 220 | using namespace BasicUI; |
| 221 | if (this->IsPreviewing()) |
| 222 | { |
| 223 | double defaultPreviewLen; |
| 224 | gPrefs->Read( |
| 225 | wxT("/AudioIO/EffectsPreviewLen"), &defaultPreviewLen, 6.0); |
| 226 | |
| 227 | if ((minDuration / mProjectRate) < defaultPreviewLen) |
| 228 | { |
| 229 | ShowMessageBox( |
| 230 | /* i18n-hint: 'Time Resolution' is the name of a control in the |
| 231 | Paulstretch effect.*/ |
| 232 | XO("Audio selection too short to preview.\n\n" |
| 233 | "Try increasing the audio selection to at least %.1f seconds,\n" |
| 234 | "or reducing the 'Time Resolution' to less than %.1f seconds.") |
| 235 | .Format( |
| 236 | (minDuration / rate) + 0.05, // round up to 1/10 s. |
| 237 | floor(maxTimeRes * 10.0) / 10.0), |
| 238 | MessageBoxOptions {}.IconStyle(Icon::Warning)); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | ShowMessageBox( |
nothing calls this directly
no test coverage detected