| 211 | } |
| 212 | |
| 213 | void fadeInStereoFloatFront(QByteArray& buffer, int sampleRate) |
| 214 | { |
| 215 | constexpr qsizetype kFrameBytes = 2 * static_cast<qsizetype>(sizeof(float)); |
| 216 | constexpr int kTrimFadeMs = 2; |
| 217 | const qsizetype frames = alignedStereoFloatBytes(buffer.size()) / kFrameBytes; |
| 218 | if (frames <= 0 || sampleRate <= 0) { |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | const qsizetype fadeFrames = |
| 223 | std::min<qsizetype>( |
| 224 | frames, |
| 225 | std::max<qsizetype>(1, sampleRate * kTrimFadeMs / 1000)); |
| 226 | auto* samples = reinterpret_cast<float*>(buffer.data()); |
| 227 | for (qsizetype frame = 0; frame < fadeFrames; ++frame) { |
| 228 | const float gain = |
| 229 | static_cast<float>(frame + 1) / static_cast<float>(fadeFrames); |
| 230 | samples[frame * 2] *= gain; |
| 231 | samples[frame * 2 + 1] *= gain; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void dropAudioBufferFront(QByteArray& buffer, qsizetype bytes, int sampleRate) |
| 236 | { |
no test coverage detected