| 113 | << " actual=" << actual[max_index]; |
| 114 | throw std::runtime_error(oss.str()); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | std::vector<float> make_speech_like_waveform( |
| 119 | int64_t sample_rate, |
| 120 | double seconds, |
| 121 | WaveformMode mode = WaveformMode::Fixed, |
| 122 | int variant = 0) { |
| 123 | const int64_t samples = static_cast<int64_t>(sample_rate * seconds); |
| 124 | std::vector<float> waveform(static_cast<size_t>(samples), 0.0f); |
| 125 | const WaveformProfile & profile = |
| 126 | mode == WaveformMode::PerRun |
| 127 | ? get_per_run_waveform_profile() |
| 128 | : WaveformProfile{}; |
| 129 | const double variant_scale = 1.0 + 0.035 * static_cast<double>(variant); |
| 130 | const double envelope_phase = profile.envelope_phase + 0.47 * static_cast<double>(variant); |
| 131 | const double voiced_scale = profile.voiced_rate_scale * variant_scale; |
| 132 | const double fricative_scale = profile.fricative_rate_scale * (1.0 + 0.02 * static_cast<double>(variant)); |
| 133 | const double pause_period = std::max(1.5, profile.pause_period + 0.06 * static_cast<double>(variant)); |
| 134 | const double pause_start = std::min(pause_period - 0.12, profile.pause_start + 0.03 * static_cast<double>(variant)); |
| 135 | const double pause_end = std::min(pause_period - 0.04, profile.pause_end + 0.03 * static_cast<double>(variant)); |
| 136 | for (int64_t i = 0; i < samples; ++i) { |
| 137 | const double t = static_cast<double>(i) / static_cast<double>(sample_rate); |
| 138 | const double envelope = |
| 139 | 0.55 + profile.envelope_bias + |
| 140 | 0.30 * std::sin(2.0 * kPi * 0.7 * profile.envelope_rate_scale * t + envelope_phase) + |
| 141 | 0.10 * std::sin(2.0 * kPi * 0.11 * profile.envelope_rate_scale * t + 0.3 + envelope_phase * 0.5); |
| 142 | const double voiced = |
| 143 | 0.55 * std::sin(2.0 * kPi * 180.0 * voiced_scale * t) + |
| 144 | 0.25 * std::sin(2.0 * kPi * 360.0 * voiced_scale * t + 0.2 + envelope_phase * 0.25) + |
| 145 | 0.12 * std::sin(2.0 * kPi * 520.0 * voiced_scale * t + 0.5 + envelope_phase * 0.4); |
| 146 | const double fricative = |
| 147 | 0.03 * std::sin(2.0 * kPi * 1900.0 * fricative_scale * t) + |
| 148 | 0.02 * std::sin(2.0 * kPi * 2600.0 * fricative_scale * t + 0.1 + envelope_phase * 0.15); |
| 149 | const double pause_phase = std::fmod(t, pause_period); |
| 150 | const double pause_gate = (pause_phase > pause_start && pause_phase < pause_end) ? 0.15 : 1.0; |
| 151 | waveform[static_cast<size_t>(i)] = static_cast<float>(pause_gate * envelope * (voiced + fricative)); |
| 152 | } |
| 153 | return waveform; |
| 154 | } |
no test coverage detected