| 1 | /* |
| 2 | * Copyright (C) 2005 to 2013 by Jonathan Duddington |
| 3 | * email: [email protected] |
| 4 | * Copyright (C) 2015-2016 Reece H. Dunn |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, see: <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | // this version keeps wavemult window as a constant fraction |
| 21 | // of the cycle length - but that spreads out the HF peaks too much |
| 22 | |
| 23 | #include "espeak__config.h"cxx . . $ `<file>/external/espeak/espeak__config.h`/ |
| 24 | |
| 25 | #include <math.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <stdint.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | |
| 32 | #include "espeak_ng.h"cxx . . $ `<file>/external/espeak/espeak_ng.h`/ |
| 33 | #include "speak_lib.h"cxx . . $ `<file>/external/espeak/speak_lib.h`/ |
| 34 | |
| 35 | #include "wavegen.h"cxx . . $ `<file>/external/espeak/wavegen.h`/ |
| 36 | #include "common.h"cxx . . $ `<file>/external/espeak/common.h`/ // for espeak_rand |
| 37 | #include "synthesize.h"cxx . . $ `<file>/external/espeak/synthesize.h`/ // for WGEN_DATA, RESONATOR, frame_t |
| 38 | #include "mbrola.h"cxx . . $ `<file>/external/espeak/mbrola.h`/ // for MbrolaFill, MbrolaReset, mbrola... |
| 39 | |
| 40 | #include "melder.h"cxx . . $ `<file>/melder/melder.h`/ // for tracing |
| 41 | |
| 42 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 43 | #include "klatt.h"cxx . . $ `<file>/external/espeak/klatt.h`/ |
| 44 | #endif |
| 45 | |
| 46 | #if USE_LIBSONIC |
| 47 | #include "sonic.h" |
| 48 | #endif |
| 49 | |
| 50 | #include "sintab.h"cxx . . $ `<file>/external/espeak/sintab.h`/ |
| 51 | #include "speech.h"cxx . . $ `<file>/external/espeak/speech.h`/ |
| 52 | |
| 53 | static void SetSynthcxx . . $ SetSynth(cdd8e8d4e631e94e).(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v); |
| 54 | |
| 55 | static voice_t *wvoicecxx . . $ wvoice. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 56 | |
| 57 | static int option_harmonic1cxx . . $ option_harmonic1. = 10; |
| 58 | static int flutter_ampcxx . . $ flutter_amp. = 64; |
| 59 | |
| 60 | static int general_amplitudecxx . . $ general_amplitude. = 60; |
| 61 | static int consonant_ampcxx . . $ consonant_amp. = 26; |
| 62 | |
| 63 | int embedded_valuecxx . . $ embedded_value.[N_EMBEDDED_VALUEScxx . . $ `external/espeak/synthesize.h:77:9`!]; |
| 64 | |
| 65 | static int PHASE_INC_FACTORcxx . . $ PHASE_INC_FACTOR.; |
| 66 | int sampleratecxx . . $ samplerate. = 0; // this is set by Wavegeninit() |
| 67 | |
| 68 | static wavegen_peaks_t peakscxx . . $ peaks.[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!]; |
| 69 | static int peak_harmoniccxx . . $ peak_harmonic.[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!]; |
| 70 | static int peak_heightcxx . . $ peak_height.[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!]; |
| 71 | |
| 72 | int echo_headcxx . . $ echo_head.; |
| 73 | int echo_tailcxx . . $ echo_tail.; |
| 74 | int echo_ampcxx . . $ echo_amp. = 0; |
| 75 | short echo_bufcxx . . $ echo_buf.[N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!]; |
| 76 | static int echo_lengthcxx . . $ echo_length. = 0; // period (in sample\) to ensure completion of echo at the end of speech, set in WavegenSetEcho() |
| 77 | |
| 78 | static int voicingcxx . . $ voicing.; |
| 79 | static RESONATOR rbreathcxx . . $ rbreath.[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!]; |
| 80 | |
| 81 | #define N_LOWHARMcxx . . $ `external/espeak/wavegen.cpp:81:9`! 30 |
| 82 | #define MAX_HARMONICcxx . . $ `external/espeak/wavegen.cpp:82:9`! 400 // 400 * 50Hz = 20 kHz, more than enough |
| 83 | static int harm_inccxx . . $ harm_inc.[N_LOWHARMcxx . . $ `external/espeak/wavegen.cpp:81:9`!]; // only for these harmonics do we interpolate amplitude between steps |
| 84 | static int *harmspectcxx . . $ harmspect.; |
| 85 | static int hswitchcxx . . $ hswitch. = 0; |
| 86 | static int hspectcxx . . $ hspect.[2][MAX_HARMONICcxx . . $ `external/espeak/wavegen.cpp:82:9`!]; // 2 copies, we interpolate between then |
| 87 | |
| 88 | static int nsamplescxx . . $ nsamples. = 0; // number to do |
| 89 | static int modulation_typecxx . . $ modulation_type. = 0; |
| 90 | static int glottal_flagcxx . . $ glottal_flag. = 0; |
| 91 | static int glottal_reducecxx . . $ glottal_reduce. = 0; |
| 92 | |
| 93 | static WGEN_DATA wdatacxx . . $ wdata.; |
| 94 | |
| 95 | static int amp_ixcxx . . $ amp_ix.; |
| 96 | static int amp_inccxx . . $ amp_inc.; |
| 97 | static unsigned char *amplitude_envcxx . . $ amplitude_env. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 98 | |
| 99 | static int samplecountcxx . . $ samplecount. = 0; // number done |
| 100 | static int samplecount_startcxx . . $ samplecount_start. = 0; // count at start of this segment |
| 101 | static int end_wavecxx . . $ end_wave. = 0; // continue to end of wave cycle |
| 102 | static int wavephasecxx . . $ wavephase.; |
| 103 | static int phaseinccxx . . $ phaseinc.; |
| 104 | static int cycle_samplescxx . . $ cycle_samples.; // number of samples in a cycle at current pitch |
| 105 | static int cbytescxx . . $ cbytes.; |
| 106 | static int hf_factorcxx . . $ hf_factor.; |
| 107 | |
| 108 | static double minus_pi_tcxx . . $ minus_pi_t.; |
| 109 | static double two_pi_tcxx . . $ two_pi_t.; |
| 110 | |
| 111 | unsigned char *out_ptrcxx . . $ out_ptr.; |
| 112 | unsigned char *out_endcxx . . $ out_end.; |
| 113 | |
| 114 | espeak_ng_OUTPUT_HOOKS* output_hookscxx . . $ output_hooks. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 115 | static int const_f0cxx . . $ const_f0. = 0; |
| 116 | |
| 117 | // the queue of operations passed to wavegen from sythesize |
| 118 | intptr_tcxx . . $ intptr_t# wcmdqcxx . . $ wcmdq.[N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`!][4]; |
| 119 | int wcmdq_headcxx . . $ wcmdq_head. = 0; |
| 120 | int wcmdq_tailcxx . . $ wcmdq_tail. = 0; |
| 121 | |
| 122 | // pitch,speed, |
| 123 | const int embedded_defaultcxx . . $ embedded_default.[N_EMBEDDED_VALUEScxx . . $ `external/espeak/synthesize.h:77:9`!] = { 0, 50, espeakRATE_NORMALcxx . . $ `external/espeak/speak_lib.h:85:9`!, 100, 50, 0, 0, 0, espeakRATE_NORMALcxx . . $ `external/espeak/speak_lib.h:85:9`!, 0, 0, 0, 0, 0, 0 }; |
| 124 | static const int embedded_maxcxx . . $ embedded_max.[N_EMBEDDED_VALUEScxx . . $ `external/espeak/synthesize.h:77:9`!] = { 0, 0x7fff, 2000, 300, 99, 99, 99, 0, 2000, 0, 0, 0, 0, 4, 0 }; |
| 125 | |
| 126 | #if USE_LIBSONIC |
| 127 | static sonicStream sonicSpeedupStream = NULL; |
| 128 | static double sonicSpeed = 1.0; |
| 129 | #endif |
| 130 | |
| 131 | // 1st index=roughness |
| 132 | // 2nd index=modulation_type |
| 133 | // value: bits 0-3 amplitude (16ths), bits 4-7 every n cycles |
| 134 | #define N_ROUGHNESScxx . . $ `external/espeak/wavegen.cpp:134:9`! 8 |
| 135 | static const unsigned char modulation_tabcxx . . $ modulation_tab.[N_ROUGHNESScxx . . $ `external/espeak/wavegen.cpp:134:9`!][8] = { |
| 136 | { 0, 0x00, 0x00, 0x00, 0, 0x46, 0xf2, 0x29 }, |
| 137 | { 0, 0x2f, 0x00, 0x2f, 0, 0x45, 0xf2, 0x29 }, |
| 138 | { 0, 0x2f, 0x00, 0x2e, 0, 0x45, 0xf2, 0x28 }, |
| 139 | { 0, 0x2e, 0x00, 0x2d, 0, 0x34, 0xf2, 0x28 }, |
| 140 | { 0, 0x2d, 0x2d, 0x2c, 0, 0x34, 0xf2, 0x28 }, |
| 141 | { 0, 0x2b, 0x2b, 0x2b, 0, 0x34, 0xf2, 0x28 }, |
| 142 | { 0, 0x2a, 0x2a, 0x2a, 0, 0x34, 0xf2, 0x28 }, |
| 143 | { 0, 0x29, 0x29, 0x29, 0, 0x34, 0xf2, 0x28 }, |
| 144 | }; |
| 145 | |
| 146 | // Flutter table, to add natural variations to the pitch |
| 147 | #define N_FLUTTERcxx . . $ `external/espeak/wavegen.cpp:147:9`! 0x170 |
| 148 | static int Flutter_inccxx . . $ Flutter_inc.; |
| 149 | static const unsigned char Flutter_tabcxx . . $ Flutter_tab.[N_FLUTTERcxx . . $ `external/espeak/wavegen.cpp:147:9`!] = { |
| 150 | 0x80, 0x9b, 0xb5, 0xcb, 0xdc, 0xe8, 0xed, 0xec, |
| 151 | 0xe6, 0xdc, 0xce, 0xbf, 0xb0, 0xa3, 0x98, 0x90, |
| 152 | 0x8c, 0x8b, 0x8c, 0x8f, 0x92, 0x94, 0x95, 0x92, |
| 153 | 0x8c, 0x83, 0x78, 0x69, 0x59, 0x49, 0x3c, 0x31, |
| 154 | 0x2a, 0x29, 0x2d, 0x36, 0x44, 0x56, 0x69, 0x7d, |
| 155 | 0x8f, 0x9f, 0xaa, 0xb1, 0xb2, 0xad, 0xa4, 0x96, |
| 156 | 0x87, 0x78, 0x69, 0x5c, 0x53, 0x4f, 0x4f, 0x55, |
| 157 | 0x5e, 0x6b, 0x7a, 0x88, 0x96, 0xa2, 0xab, 0xb0, |
| 158 | |
| 159 | 0xb1, 0xae, 0xa8, 0xa0, 0x98, 0x91, 0x8b, 0x88, |
| 160 | 0x89, 0x8d, 0x94, 0x9d, 0xa8, 0xb2, 0xbb, 0xc0, |
| 161 | 0xc1, 0xbd, 0xb4, 0xa5, 0x92, 0x7c, 0x63, 0x4a, |
| 162 | 0x32, 0x1e, 0x0e, 0x05, 0x02, 0x05, 0x0f, 0x1e, |
| 163 | 0x30, 0x44, 0x59, 0x6d, 0x7f, 0x8c, 0x96, 0x9c, |
| 164 | 0x9f, 0x9f, 0x9d, 0x9b, 0x99, 0x99, 0x9c, 0xa1, |
| 165 | 0xa9, 0xb3, 0xbf, 0xca, 0xd5, 0xdc, 0xe0, 0xde, |
| 166 | 0xd8, 0xcc, 0xbb, 0xa6, 0x8f, 0x77, 0x60, 0x4b, |
| 167 | |
| 168 | 0x3a, 0x2e, 0x28, 0x29, 0x2f, 0x3a, 0x48, 0x59, |
| 169 | 0x6a, 0x7a, 0x86, 0x90, 0x94, 0x95, 0x91, 0x89, |
| 170 | 0x80, 0x75, 0x6b, 0x62, 0x5c, 0x5a, 0x5c, 0x61, |
| 171 | 0x69, 0x74, 0x80, 0x8a, 0x94, 0x9a, 0x9e, 0x9d, |
| 172 | 0x98, 0x90, 0x86, 0x7c, 0x71, 0x68, 0x62, 0x60, |
| 173 | 0x63, 0x6b, 0x78, 0x88, 0x9b, 0xaf, 0xc2, 0xd2, |
| 174 | 0xdf, 0xe6, 0xe7, 0xe2, 0xd7, 0xc6, 0xb2, 0x9c, |
| 175 | 0x84, 0x6f, 0x5b, 0x4b, 0x40, 0x39, 0x37, 0x38, |
| 176 | |
| 177 | 0x3d, 0x43, 0x4a, 0x50, 0x54, 0x56, 0x55, 0x52, |
| 178 | 0x4d, 0x48, 0x42, 0x3f, 0x3e, 0x41, 0x49, 0x56, |
| 179 | 0x67, 0x7c, 0x93, 0xab, 0xc3, 0xd9, 0xea, 0xf6, |
| 180 | 0xfc, 0xfb, 0xf4, 0xe7, 0xd5, 0xc0, 0xaa, 0x94, |
| 181 | 0x80, 0x71, 0x64, 0x5d, 0x5a, 0x5c, 0x61, 0x68, |
| 182 | 0x70, 0x77, 0x7d, 0x7f, 0x7f, 0x7b, 0x74, 0x6b, |
| 183 | 0x61, 0x57, 0x4e, 0x48, 0x46, 0x48, 0x4e, 0x59, |
| 184 | 0x66, 0x75, 0x84, 0x93, 0x9f, 0xa7, 0xab, 0xaa, |
| 185 | |
| 186 | 0xa4, 0x99, 0x8b, 0x7b, 0x6a, 0x5b, 0x4e, 0x46, |
| 187 | 0x43, 0x45, 0x4d, 0x5a, 0x6b, 0x7f, 0x92, 0xa6, |
| 188 | 0xb8, 0xc5, 0xcf, 0xd3, 0xd2, 0xcd, 0xc4, 0xb9, |
| 189 | 0xad, 0xa1, 0x96, 0x8e, 0x89, 0x87, 0x87, 0x8a, |
| 190 | 0x8d, 0x91, 0x92, 0x91, 0x8c, 0x84, 0x78, 0x68, |
| 191 | 0x55, 0x41, 0x2e, 0x1c, 0x0e, 0x05, 0x01, 0x05, |
| 192 | 0x0f, 0x1f, 0x34, 0x4d, 0x68, 0x81, 0x9a, 0xb0, |
| 193 | 0xc1, 0xcd, 0xd3, 0xd3, 0xd0, 0xc8, 0xbf, 0xb5, |
| 194 | |
| 195 | 0xab, 0xa4, 0x9f, 0x9c, 0x9d, 0xa0, 0xa5, 0xaa, |
| 196 | 0xae, 0xb1, 0xb0, 0xab, 0xa3, 0x96, 0x87, 0x76, |
| 197 | 0x63, 0x51, 0x42, 0x36, 0x2f, 0x2d, 0x31, 0x3a, |
| 198 | 0x48, 0x59, 0x6b, 0x7e, 0x8e, 0x9c, 0xa6, 0xaa, |
| 199 | 0xa9, 0xa3, 0x98, 0x8a, 0x7b, 0x6c, 0x5d, 0x52, |
| 200 | 0x4a, 0x48, 0x4a, 0x50, 0x5a, 0x67, 0x75, 0x82 |
| 201 | }; |
| 202 | |
| 203 | // waveform shape table for HF peaks, formants 6,7,8 |
| 204 | #define N_WAVEMULTcxx . . $ `external/espeak/wavegen.cpp:204:9`! 128 |
| 205 | static int wavemult_offsetcxx . . $ wavemult_offset. = 0; |
| 206 | static int wavemult_maxcxx . . $ wavemult_max. = 0; |
| 207 | |
| 208 | // the presets are for 22050 Hz sample rate. |
| 209 | // A different rate will need to recalculate the presets in WavegenInit() |
| 210 | static unsigned char wavemultcxx . . $ wavemult.[N_WAVEMULTcxx . . $ `external/espeak/wavegen.cpp:204:9`!] = { |
| 211 | 0, 0, 0, 2, 3, 5, 8, 11, 14, 18, 22, 27, 32, 37, 43, 49, |
| 212 | 55, 62, 69, 76, 83, 90, 98, 105, 113, 121, 128, 136, 144, 152, 159, 166, |
| 213 | 174, 181, 188, 194, 201, 207, 213, 218, 224, 228, 233, 237, 240, 244, 246, 249, |
| 214 | 251, 252, 253, 253, 253, 253, 252, 251, 249, 246, 244, 240, 237, 233, 228, 224, |
| 215 | 218, 213, 207, 201, 194, 188, 181, 174, 166, 159, 152, 144, 136, 128, 121, 113, |
| 216 | 105, 98, 90, 83, 76, 69, 62, 55, 49, 43, 37, 32, 27, 22, 18, 14, |
| 217 | 11, 8, 5, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 218 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 219 | }; |
| 220 | |
| 221 | // set from y = pow(2,x) * 128, x=-1 to 1 |
| 222 | #define MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`! 101 |
| 223 | static const unsigned char pitch_adjust_tabcxx . . $ pitch_adjust_tab.[MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`!+1] = { |
| 224 | 64, 65, 66, 67, 68, 69, 70, 71, |
| 225 | 72, 73, 74, 75, 76, 77, 78, 79, |
| 226 | 80, 81, 82, 83, 84, 86, 87, 88, |
| 227 | 89, 91, 92, 93, 94, 96, 97, 98, |
| 228 | 100, 101, 103, 104, 105, 107, 108, 110, |
| 229 | 111, 113, 115, 116, 118, 119, 121, 123, |
| 230 | 124, 126, 128, 130, 132, 133, 135, 137, |
| 231 | 139, 141, 143, 145, 147, 149, 151, 153, |
| 232 | 155, 158, 160, 162, 164, 167, 169, 171, |
| 233 | 174, 176, 179, 181, 184, 186, 189, 191, |
| 234 | 194, 197, 199, 202, 205, 208, 211, 214, |
| 235 | 217, 220, 223, 226, 229, 232, 236, 239, |
| 236 | 242, 246, 249, 252, 254, 255 |
| 237 | }; |
| 238 | |
| 239 | void WcmdqStopcxx . . $ WcmdqStop(49f6e7a06ebc5aa8).(void) |
| 240 | { |
| 241 | wcmdq_headcxx . . $ wcmdq_head. = 0; |
| 242 | wcmdq_tailcxx . . $ wcmdq_tail. = 0; |
| 243 | |
| 244 | #if USE_LIBSONIC |
| 245 | if (sonicSpeedupStream != NULL) { |
| 246 | sonicDestroyStream(sonicSpeedupStream); |
| 247 | sonicSpeedupStream = NULL; |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | #if USE_MBROLAcxx . . $ `external/espeak/espeak__config.h:18:9`! |
| 252 | if (mbrola_name[0] != 0) |
| 253 | MbrolaReset(); |
| 254 | #endif |
| 255 | } |
| 256 | |
| 257 | int WcmdqFreecxx . . $ WcmdqFree(b126dc7c1de90089).(void) |
| 258 | { |
| 259 | int i; |
| 260 | i = wcmdq_headcxx . . $ wcmdq_head. - wcmdq_tailcxx . . $ wcmdq_tail.; |
| 261 | if (i <= 0) i += N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`!; |
| 262 | return i; |
| 263 | } |
| 264 | |
| 265 | int WcmdqUsedcxx . . $ WcmdqUsed(b126dc7c1de90089).(void) |
| 266 | { |
| 267 | return N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`! - WcmdqFreecxx . . $ WcmdqFree(b126dc7c1de90089).(); |
| 268 | } |
| 269 | |
| 270 | void WcmdqInccxx . . $ WcmdqInc(49f6e7a06ebc5aa8).(void) |
| 271 | { |
| 272 | wcmdq_tailcxx . . $ wcmdq_tail.++; |
| 273 | if (wcmdq_tailcxx . . $ wcmdq_tail. >= N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`!) wcmdq_tailcxx . . $ wcmdq_tail. = 0; |
| 274 | //TRACE |
| 275 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Tail now ", wcmdq_tail); |
| 276 | } |
| 277 | |
| 278 | static void WcmdqIncHeadcxx . . $ WcmdqIncHead(49f6e7a06ebc5aa8).(void) |
| 279 | { |
| 280 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&wcmdq[wcmdq_head], sizeof(wcmdq[wcmdq_head])); |
| 281 | wcmdq_headcxx . . $ wcmdq_head.++; |
| 282 | if (wcmdq_headcxx . . $ wcmdq_head. >= N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`!) wcmdq_headcxx . . $ wcmdq_head. = 0; |
| 283 | //TRACE |
| 284 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Head now ", wcmdq_head); |
| 285 | } |
| 286 | |
| 287 | #define PEAKSHAPEWcxx . . $ `external/espeak/wavegen.cpp:287:9`! 256 |
| 288 | |
| 289 | static const unsigned char pk_shape1cxx . . $ pk_shape1.[PEAKSHAPEWcxx . . $ `external/espeak/wavegen.cpp:287:9`!+1] = { |
| 290 | 255, 254, 254, 254, 254, 254, 253, 253, 252, 251, 251, 250, 249, 248, 247, 246, |
| 291 | 245, 244, 242, 241, 239, 238, 236, 234, 233, 231, 229, 227, 225, 223, 220, 218, |
| 292 | 216, 213, 211, 209, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189, 187, 185, |
| 293 | 183, 180, 178, 176, 173, 171, 169, 166, 164, 161, 159, 156, 154, 151, 148, 146, |
| 294 | 143, 140, 138, 135, 132, 129, 126, 123, 120, 118, 115, 112, 108, 105, 102, 99, |
| 295 | 96, 95, 93, 91, 90, 88, 86, 85, 83, 82, 80, 79, 77, 76, 74, 73, |
| 296 | 72, 70, 69, 68, 67, 66, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, |
| 297 | 55, 54, 53, 52, 52, 51, 50, 50, 49, 48, 48, 47, 47, 46, 46, 46, |
| 298 | 45, 45, 45, 44, 44, 44, 44, 44, 44, 44, 43, 43, 43, 43, 44, 43, |
| 299 | 42, 42, 41, 40, 40, 39, 38, 38, 37, 36, 36, 35, 35, 34, 33, 33, |
| 300 | 32, 32, 31, 30, 30, 29, 29, 28, 28, 27, 26, 26, 25, 25, 24, 24, |
| 301 | 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, 18, 17, 17, 16, |
| 302 | 16, 15, 15, 15, 14, 14, 13, 13, 13, 12, 12, 11, 11, 11, 10, 10, |
| 303 | 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 5, 5, |
| 304 | 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, |
| 305 | 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 306 | 0 |
| 307 | }; |
| 308 | |
| 309 | static const unsigned char pk_shape2cxx . . $ pk_shape2.[PEAKSHAPEWcxx . . $ `external/espeak/wavegen.cpp:287:9`!+1] = { |
| 310 | 255, 254, 254, 254, 254, 254, 254, 254, 254, 254, 253, 253, 253, 253, 252, 252, |
| 311 | 252, 251, 251, 251, 250, 250, 249, 249, 248, 248, 247, 247, 246, 245, 245, 244, |
| 312 | 243, 243, 242, 241, 239, 237, 235, 233, 231, 229, 227, 225, 223, 221, 218, 216, |
| 313 | 213, 211, 208, 205, 203, 200, 197, 194, 191, 187, 184, 181, 178, 174, 171, 167, |
| 314 | 163, 160, 156, 152, 148, 144, 140, 136, 132, 127, 123, 119, 114, 110, 105, 100, |
| 315 | 96, 94, 91, 88, 86, 83, 81, 78, 76, 74, 71, 69, 66, 64, 62, 60, |
| 316 | 57, 55, 53, 51, 49, 47, 44, 42, 40, 38, 36, 34, 32, 30, 29, 27, |
| 317 | 25, 23, 21, 19, 18, 16, 14, 12, 11, 9, 7, 6, 4, 3, 1, 0, |
| 318 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 319 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 320 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 321 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 322 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 323 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 324 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 325 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 326 | 0 |
| 327 | }; |
| 328 | |
| 329 | static const unsigned char *pk_shapecxx . . $ pk_shape.; |
| 330 | |
| 331 | void WavegenInitcxx . . $ WavegenInit(3e454b8ccf442868).(int rate, int wavemult_fact) |
| 332 | { |
| 333 | int ix; |
| 334 | double x; |
| 335 | |
| 336 | if (wavemult_fact == 0) |
| 337 | wavemult_fact = 60; // default |
| 338 | |
| 339 | wvoicecxx . . $ wvoice. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 340 | sampleratecxx . . $ samplerate. = rate; |
| 341 | PHASE_INC_FACTORcxx . . $ PHASE_INC_FACTOR. = 0x8000000 / sampleratecxx . . $ samplerate.; // assumes pitch is Hz*32 |
| 342 | Flutter_inccxx . . $ Flutter_inc. = (64 * sampleratecxx . . $ samplerate.)/rate; |
| 343 | samplecountcxx . . $ samplecount. = 0; |
| 344 | nsamplescxx . . $ nsamples. = 0; |
| 345 | wavephasecxx . . $ wavephase. = 0x7fffffff; |
| 346 | |
| 347 | wdatacxx . . $ wdata..amplitude = 32; |
| 348 | wdatacxx . . $ wdata..amplitude_fmt = 100; |
| 349 | |
| 350 | for (ix = 0; ix < N_EMBEDDED_VALUEScxx . . $ `external/espeak/synthesize.h:77:9`!; ix++) |
| 351 | embedded_valuecxx . . $ embedded_value.[ix] = embedded_defaultcxx . . $ embedded_default.[ix]; |
| 352 | |
| 353 | // set up window to generate a spread of harmonics from a |
| 354 | // single peak for HF peaks |
| 355 | wavemult_maxcxx . . $ wavemult_max. = (sampleratecxx . . $ samplerate. * wavemult_fact)/(256 * 50); |
| 356 | if (wavemult_maxcxx . . $ wavemult_max. > N_WAVEMULTcxx . . $ `external/espeak/wavegen.cpp:204:9`!) wavemult_maxcxx . . $ wavemult_max. = N_WAVEMULTcxx . . $ `external/espeak/wavegen.cpp:204:9`!; |
| 357 | |
| 358 | wavemult_offsetcxx . . $ wavemult_offset. = wavemult_maxcxx . . $ wavemult_max./2; |
| 359 | |
| 360 | if (sampleratecxx . . $ samplerate. != 22050) { |
| 361 | // wavemult table has preset values for 22050 Hz, we only need to |
| 362 | // recalculate them if we have a different sample rate |
| 363 | for (ix = 0; ix < wavemult_maxcxx . . $ wavemult_max.; ix++) { |
| 364 | x = 127*(1.0 - coscxx . . $ cos(fee4f1d22bc8e617).((M_PIcxx . . $ `melder/NUMmath.h:48:9`!*2)*ix/wavemult_maxcxx . . $ wavemult_max.)); |
| 365 | wavemultcxx . . $ wavemult.[ix] = (int)x; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | pk_shapecxx . . $ pk_shape. = pk_shape2cxx . . $ pk_shape2.; |
| 370 | |
| 371 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 372 | KlattInit(); |
| 373 | #endif |
| 374 | } |
| 375 | |
| 376 | void WavegenFinicxx . . $ WavegenFini(49f6e7a06ebc5aa8).(void) |
| 377 | { |
| 378 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 379 | KlattFini(); |
| 380 | #endif |
| 381 | } |
| 382 | |
| 383 | int GetAmplitudecxx . . $ GetAmplitude(b126dc7c1de90089).(void) |
| 384 | { |
| 385 | int amp; |
| 386 | |
| 387 | // normal, none, reduced, moderate, strong |
| 388 | static const unsigned char amp_emphasis[5] = { 16, 16, 10, 16, 22 }; |
| 389 | |
| 390 | amp = (embedded_valuecxx . . $ embedded_value.[EMBED_Acxx . . $ `external/espeak/synthesize.h:65:9`!])*55/100; |
| 391 | general_amplitudecxx . . $ general_amplitude. = amp * amp_emphasis[embedded_valuecxx . . $ embedded_value.[EMBED_Fcxx . . $ `external/espeak/synthesize.h:75:9`!]] / 16; |
| 392 | return general_amplitudecxx . . $ general_amplitude.; |
| 393 | } |
| 394 | |
| 395 | static void WavegenSetEchocxx . . $ WavegenSetEcho(49f6e7a06ebc5aa8).(void) |
| 396 | { |
| 397 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 398 | return; |
| 399 | |
| 400 | int delay; |
| 401 | int amp; |
| 402 | |
| 403 | voicingcxx . . $ voicing. = wvoicecxx . . $ wvoice.->voicing; |
| 404 | delay = wvoicecxx . . $ wvoice.->echo_delay; |
| 405 | amp = wvoicecxx . . $ wvoice.->echo_amp; |
| 406 | |
| 407 | if (delay >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 408 | delay = N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!-1; |
| 409 | if (amp > 100) |
| 410 | amp = 100; |
| 411 | |
| 412 | memset(echo_bufcxx . . $ echo_buf., 0, sizeof(echo_bufcxx . . $ echo_buf.)); |
| 413 | echo_tailcxx . . $ echo_tail. = 0; |
| 414 | |
| 415 | if (embedded_valuecxx . . $ embedded_value.[EMBED_Hcxx . . $ `external/espeak/synthesize.h:67:9`!] > 0) { |
| 416 | // set echo from an embedded command in the text |
| 417 | amp = embedded_valuecxx . . $ embedded_value.[EMBED_Hcxx . . $ `external/espeak/synthesize.h:67:9`!]; |
| 418 | delay = 130; |
| 419 | } |
| 420 | |
| 421 | if (delay == 0) |
| 422 | amp = 0; |
| 423 | |
| 424 | echo_headcxx . . $ echo_head. = (delay * sampleratecxx . . $ samplerate.)/1000; |
| 425 | echo_lengthcxx . . $ echo_length. = echo_headcxx . . $ echo_head.; // ensure completion of echo at the end of speech. Use 1 delay period? |
| 426 | if (amp == 0) |
| 427 | echo_lengthcxx . . $ echo_length. = 0; |
| 428 | if (amp > 20) |
| 429 | echo_lengthcxx . . $ echo_length. = echo_headcxx . . $ echo_head. * 2; // perhaps allow 2 echo periods if the echo is loud. |
| 430 | |
| 431 | // echo_amp units are 1/256ths of the amplitude of the original sound. |
| 432 | echo_ampcxx . . $ echo_amp. = amp; |
| 433 | // compensate (partially) for increase in amplitude due to echo |
| 434 | general_amplitudecxx . . $ general_amplitude. = GetAmplitudecxx . . $ GetAmplitude(b126dc7c1de90089).(); |
| 435 | general_amplitudecxx . . $ general_amplitude. = ((general_amplitudecxx . . $ general_amplitude. * (500-amp))/500); |
| 436 | } |
| 437 | |
| 438 | int PeaksToHarmspectcxx . . $ PeaksToHarmspect(28c13c71e9410f67).(wavegen_peaks_t *wavegenPeaks, int pitch, int *htab, int control) |
| 439 | { |
| 440 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 441 | return 1; |
| 442 | |
| 443 | // Calculate the amplitude of each harmonics from the formants |
| 444 | // Only for formants 0 to 5 |
| 445 | |
| 446 | // control 0=initial call, 1=every 64 cycles |
| 447 | |
| 448 | // pitch and freqs are Hz<<16 |
| 449 | |
| 450 | int f; |
| 451 | wavegen_peaks_t *p; |
| 452 | int fp; // centre freq of peak |
| 453 | int fhi; // high freq of peak |
| 454 | int h; // harmonic number |
| 455 | int pk; |
| 456 | int hmax; |
| 457 | int hmax_samplerate; // highest harmonic allowed for the samplerate |
| 458 | int x; |
| 459 | int h1; |
| 460 | |
| 461 | // initialise as much of *out as we will need |
| 462 | hmax = (wavegenPeaks[wvoicecxx . . $ wvoice.->n_harmonic_peaks].freq + wavegenPeaks[wvoicecxx . . $ wvoice.->n_harmonic_peaks].right)/pitch; |
| 463 | if (hmax >= MAX_HARMONICcxx . . $ `external/espeak/wavegen.cpp:82:9`!) |
| 464 | hmax = MAX_HARMONICcxx . . $ `external/espeak/wavegen.cpp:82:9`!-1; |
| 465 | |
| 466 | // restrict highest harmonic to half the samplerate |
| 467 | hmax_samplerate = (((sampleratecxx . . $ samplerate. * 19)/40) << 16)/pitch; // only 95% of Nyquist freq |
| 468 | |
| 469 | if (hmax > hmax_samplerate) |
| 470 | hmax = hmax_samplerate; |
| 471 | |
| 472 | for (h = 0; h <= hmax; h++) |
| 473 | htab[h] = 0; |
| 474 | |
| 475 | for (pk = 0; pk <= wvoicecxx . . $ wvoice.->n_harmonic_peaks; pk++) { |
| 476 | p = &wavegenPeaks[pk]; |
| 477 | if ((p->height == 0) || (fp = p->freq) == 0) |
| 478 | continue; |
| 479 | |
| 480 | fhi = p->freq + p->right; |
| 481 | h = ((p->freq - p->left) / pitch) + 1; |
| 482 | if (h <= 0) h = 1; |
| 483 | |
| 484 | for (f = pitch*h; f < fp; f += pitch) |
| 485 | htab[h++] += pk_shapecxx . . $ pk_shape.[(fp-f)/(p->left>>8)] * p->height; |
| 486 | for (; f < fhi; f += pitch) |
| 487 | htab[h++] += pk_shapecxx . . $ pk_shape.[(f-fp)/(p->right>>8)] * p->height; |
| 488 | } |
| 489 | |
| 490 | int y; |
| 491 | int h2; |
| 492 | // increase bass |
| 493 | y = wavegenPeaks[1].height * 10; // addition as a multiple of 1/256s |
| 494 | h2 = (1000<<16)/pitch; // decrease until 1000Hz |
| 495 | if (h2 > 0) { |
| 496 | x = y/h2; |
| 497 | h = 1; |
| 498 | while (y > 0) { |
| 499 | htab[h++] += y; |
| 500 | y -= x; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | // find the nearest harmonic for HF peaks where we don't use shape |
| 505 | for (; pk < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; pk++) { |
| 506 | x = wavegenPeaks[pk].height >> 14; |
| 507 | peak_heightcxx . . $ peak_height.[pk] = (x * x * 5)/2; |
| 508 | |
| 509 | // find the nearest harmonic for HF peaks where we don't use shape |
| 510 | if (control == 0) { |
| 511 | // set this initially, but make changes only at the quiet point |
| 512 | peak_harmoniccxx . . $ peak_harmonic.[pk] = wavegenPeaks[pk].freq / pitch; |
| 513 | } |
| 514 | // only use harmonics up to half the samplerate |
| 515 | if (peak_harmoniccxx . . $ peak_harmonic.[pk] >= hmax_samplerate) |
| 516 | peak_heightcxx . . $ peak_height.[pk] = 0; |
| 517 | } |
| 518 | |
| 519 | // convert from the square-rooted values |
| 520 | f = 0; |
| 521 | for (h = 0; h <= hmax; h++, f += pitch) { |
| 522 | x = htab[h] >> 15; |
| 523 | htab[h] = (x * x) >> 8; |
| 524 | |
| 525 | int ix; |
| 526 | if ((ix = (f >> 19)) < N_TONE_ADJUSTcxx . . $ `external/espeak/voice.h:79:10`!) |
| 527 | htab[h] = (htab[h] * wvoicecxx . . $ wvoice.->tone_adjust[ix]) >> 13; // index tone_adjust with Hz/8 |
| 528 | } |
| 529 | |
| 530 | // adjust the amplitude of the first harmonic, affects tonal quality |
| 531 | h1 = htab[1] * option_harmonic1cxx . . $ option_harmonic1.; |
| 532 | htab[1] = h1/8; |
| 533 | |
| 534 | // calc intermediate increments of LF harmonics |
| 535 | if (control & 1) { |
| 536 | for (h = 1; h < N_LOWHARMcxx . . $ `external/espeak/wavegen.cpp:81:9`!; h++) |
| 537 | harm_inccxx . . $ harm_inc.[h] = (htab[h] - harmspectcxx . . $ harmspect.[h]) >> 3; |
| 538 | } |
| 539 | |
| 540 | return hmax; // highest harmonic number |
| 541 | } |
| 542 | |
| 543 | static void AdvanceParameterscxx . . $ AdvanceParameters(49f6e7a06ebc5aa8).(void) |
| 544 | { |
| 545 | // Called every 64 samples to increment the formant freq, height, and widths |
| 546 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 547 | return; |
| 548 | |
| 549 | int x; |
| 550 | int ix; |
| 551 | static int Flutter_ix = 0; |
| 552 | |
| 553 | // advance the pitch |
| 554 | wdatacxx . . $ wdata..pitch_ix += wdatacxx . . $ wdata..pitch_inc; |
| 555 | if ((ix = wdatacxx . . $ wdata..pitch_ix>>8) > 127) ix = 127; |
| 556 | x = wdatacxx . . $ wdata..pitch_env[ix] * wdatacxx . . $ wdata..pitch_range; |
| 557 | if (wdatacxx . . $ wdata..pitch_env) x = wdatacxx . . $ wdata..pitch_env[ix] * wdatacxx . . $ wdata..pitch_range; |
| 558 | wdatacxx . . $ wdata..pitch = (x>>8) + wdatacxx . . $ wdata..pitch_base; |
| 559 | |
| 560 | |
| 561 | |
| 562 | amp_ixcxx . . $ amp_ix. += amp_inccxx . . $ amp_inc.; |
| 563 | |
| 564 | /* add pitch flutter */ |
| 565 | if (Flutter_ix >= (N_FLUTTERcxx . . $ `external/espeak/wavegen.cpp:147:9`!*64)) |
| 566 | Flutter_ix = 0; |
| 567 | x = ((int)(Flutter_tabcxx . . $ Flutter_tab.[Flutter_ix >> 6])-0x80) * flutter_ampcxx . . $ flutter_amp.; |
| 568 | Flutter_ix += Flutter_inccxx . . $ Flutter_inc.; |
| 569 | wdatacxx . . $ wdata..pitch += x; |
| 570 | |
| 571 | if(const_f0cxx . . $ const_f0.) |
| 572 | wdatacxx . . $ wdata..pitch = (const_f0cxx . . $ const_f0.<<12); |
| 573 | |
| 574 | if (wdatacxx . . $ wdata..pitch < 102400) |
| 575 | wdatacxx . . $ wdata..pitch = 102400; // min pitch, 25 Hz (25 << 12) |
| 576 | |
| 577 | if (samplecountcxx . . $ samplecount. == samplecount_startcxx . . $ samplecount_start.) |
| 578 | return; |
| 579 | |
| 580 | for (ix = 0; ix <= wvoicecxx . . $ wvoice.->n_harmonic_peaks; ix++) { |
| 581 | peakscxx . . $ peaks.[ix].freq1 += peakscxx . . $ peaks.[ix].freq_inc; |
| 582 | peakscxx . . $ peaks.[ix].freq = (int)peakscxx . . $ peaks.[ix].freq1; |
| 583 | peakscxx . . $ peaks.[ix].height1 += peakscxx . . $ peaks.[ix].height_inc; |
| 584 | if ((peakscxx . . $ peaks.[ix].height = (int)peakscxx . . $ peaks.[ix].height1) < 0) |
| 585 | peakscxx . . $ peaks.[ix].height = 0; |
| 586 | peakscxx . . $ peaks.[ix].left1 += peakscxx . . $ peaks.[ix].left_inc; |
| 587 | peakscxx . . $ peaks.[ix].left = (int)peakscxx . . $ peaks.[ix].left1; |
| 588 | if (ix < 3) { |
| 589 | peakscxx . . $ peaks.[ix].right1 += peakscxx . . $ peaks.[ix].right_inc; |
| 590 | peakscxx . . $ peaks.[ix].right = (int)peakscxx . . $ peaks.[ix].right1; |
| 591 | } else |
| 592 | peakscxx . . $ peaks.[ix].right = peakscxx . . $ peaks.[ix].left; |
| 593 | } |
| 594 | for (; ix < 8; ix++) { |
| 595 | // formants 6,7,8 don't have a width parameter |
| 596 | if (ix < 7) { |
| 597 | peakscxx . . $ peaks.[ix].freq1 += peakscxx . . $ peaks.[ix].freq_inc; |
| 598 | peakscxx . . $ peaks.[ix].freq = (int)peakscxx . . $ peaks.[ix].freq1; |
| 599 | } |
| 600 | peakscxx . . $ peaks.[ix].height1 += peakscxx . . $ peaks.[ix].height_inc; |
| 601 | if ((peakscxx . . $ peaks.[ix].height = (int)peakscxx . . $ peaks.[ix].height1) < 0) |
| 602 | peakscxx . . $ peaks.[ix].height = 0; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | static double resonatorcxx . . $ resonator(6c9f4eb4666d086d).(RESONATOR *r, double input) |
| 607 | { |
| 608 | double x; |
| 609 | |
| 610 | x = r->a * input + r->b * r->x1 + r->c * r->x2; |
| 611 | r->x2 = r->x1; |
| 612 | r->x1 = x; |
| 613 | |
| 614 | return x; |
| 615 | } |
| 616 | |
| 617 | static void setresonatorcxx . . $ setresonator(5336d0c2aed65cd9).(RESONATOR *rp, int freq, int bwidth, int init) |
| 618 | { |
| 619 | // freq Frequency of resonator in Hz |
| 620 | // bwidth Bandwidth of resonator in Hz |
| 621 | // init Initialize internal data |
| 622 | |
| 623 | double x; |
| 624 | double arg; |
| 625 | |
| 626 | if (init) { |
| 627 | rp->x1 = 0; |
| 628 | rp->x2 = 0; |
| 629 | } |
| 630 | |
| 631 | arg = minus_pi_tcxx . . $ minus_pi_t. * bwidth; |
| 632 | x = expcxx . . $ exp(fee4f1d22bc8e617).(arg); |
| 633 | |
| 634 | rp->c = -(x * x); |
| 635 | |
| 636 | arg = two_pi_tcxx . . $ two_pi_t. * freq; |
| 637 | rp->b = x * coscxx . . $ cos(fee4f1d22bc8e617).(arg) * 2.0; |
| 638 | |
| 639 | rp->a = 1.0 - rp->b - rp->c; |
| 640 | } |
| 641 | |
| 642 | void InitBreathcxx . . $ InitBreath(49f6e7a06ebc5aa8).(void) |
| 643 | { |
| 644 | int ix; |
| 645 | |
| 646 | minus_pi_tcxx . . $ minus_pi_t. = -M_PIcxx . . $ `melder/NUMmath.h:48:9`! / sampleratecxx . . $ samplerate.; |
| 647 | two_pi_tcxx . . $ two_pi_t. = -2.0 * minus_pi_tcxx . . $ minus_pi_t.; |
| 648 | |
| 649 | for (ix = 0; ix < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; ix++) |
| 650 | setresonatorcxx . . $ setresonator(5336d0c2aed65cd9).(&rbreathcxx . . $ rbreath.[ix], 2000, 200, 1); |
| 651 | } |
| 652 | |
| 653 | static void SetBreathcxx . . $ SetBreath(49f6e7a06ebc5aa8).(void) |
| 654 | { |
| 655 | int pk; |
| 656 | |
| 657 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || wvoicecxx . . $ wvoice.->breath[0] == 0) |
| 658 | return; |
| 659 | |
| 660 | for (pk = 1; pk < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; pk++) { |
| 661 | if (wvoicecxx . . $ wvoice.->breath[pk] != 0) { |
| 662 | // breath[0] indicates that some breath formants are needed |
| 663 | // set the freq from the current synthesis formant and the width from the voice data |
| 664 | setresonatorcxx . . $ setresonator(5336d0c2aed65cd9).(&rbreathcxx . . $ rbreath.[pk], peakscxx . . $ peaks.[pk].freq >> 16, wvoicecxx . . $ wvoice.->breathw[pk], 0); |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | static int ApplyBreathcxx . . $ ApplyBreath(b126dc7c1de90089).(void) |
| 670 | { |
| 671 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 672 | return 0; |
| 673 | |
| 674 | int value = 0; |
| 675 | int noise; |
| 676 | int ix; |
| 677 | |
| 678 | // use two random numbers, for alternate formants |
| 679 | noise = espeak_randcxx . . $ espeak_rand(d0a0e4c270da0eca).(-0x2000, 0x1fff); |
| 680 | |
| 681 | for (ix = 1; ix < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; ix++) { |
| 682 | int amp; |
| 683 | if ((amp = wvoicecxx . . $ wvoice.->breath[ix]) != 0) { |
| 684 | amp *= (peakscxx . . $ peaks.[ix].height >> 14); |
| 685 | value += (int)resonatorcxx . . $ resonator(6c9f4eb4666d086d).(&rbreathcxx . . $ rbreath.[ix], noise) * amp; |
| 686 | } |
| 687 | } |
| 688 | return value; |
| 689 | } |
| 690 | |
| 691 | static int Wavegencxx . . $ Wavegen(dc5db46c9e56eacc).(int length, int modulation, bool resume, frame_t *fr1, frame_t *fr2, voice_t *wavegenVoice) |
| 692 | { |
| 693 | if (resume == false) |
| 694 | SetSynthcxx . . $ SetSynth(cdd8e8d4e631e94e).(length, modulation, fr1, fr2, wavegenVoice); |
| 695 | |
| 696 | if (wavegenVoice == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 697 | return 0; |
| 698 | |
| 699 | unsigned short waveph; |
| 700 | unsigned short theta; |
| 701 | int total; |
| 702 | int h; |
| 703 | int ix; |
| 704 | int z, z1, z2; |
| 705 | int echo; |
| 706 | int ov; |
| 707 | static int maxh, maxh2; |
| 708 | int pk; |
| 709 | signed char c; |
| 710 | int sample; |
| 711 | int amp; |
| 712 | int modn_amp = 1, modn_period; |
| 713 | static int agc = 256; |
| 714 | static int h_switch_sign = 0; |
| 715 | static int cycle_count = 0; |
| 716 | static int amplitude2 = 0; // adjusted for pitch |
| 717 | |
| 718 | // continue until the output buffer is full, or |
| 719 | // the required number of samples have been produced |
| 720 | |
| 721 | for (;;) { |
| 722 | if ((end_wavecxx . . $ end_wave. == 0) && (samplecountcxx . . $ samplecount. == nsamplescxx . . $ nsamples.)) |
| 723 | return 0; |
| 724 | |
| 725 | if ((samplecountcxx . . $ samplecount. & 0x3f) == 0) { |
| 726 | // every 64 samples, adjust the parameters |
| 727 | if (samplecountcxx . . $ samplecount. == 0) { |
| 728 | hswitchcxx . . $ hswitch. = 0; |
| 729 | harmspectcxx . . $ harmspect. = hspectcxx . . $ hspect.[0]; |
| 730 | maxh2 = PeaksToHarmspectcxx . . $ PeaksToHarmspect(28c13c71e9410f67).(peakscxx . . $ peaks., wdatacxx . . $ wdata..pitch<<4, hspectcxx . . $ hspect.[0], 0); |
| 731 | |
| 732 | // adjust amplitude to compensate for fewer harmonics at higher pitch |
| 733 | amplitude2 = (wdatacxx . . $ wdata..amplitude * (wdatacxx . . $ wdata..pitch >> 8) * wdatacxx . . $ wdata..amplitude_fmt)/(10000 << 3); |
| 734 | |
| 735 | // switch sign of harmonics above about 900Hz, to reduce max peak amplitude |
| 736 | h_switch_sign = 890 / (wdatacxx . . $ wdata..pitch >> 12); |
| 737 | } else |
| 738 | AdvanceParameterscxx . . $ AdvanceParameters(49f6e7a06ebc5aa8).(); |
| 739 | |
| 740 | // pitch is Hz<<12 |
| 741 | phaseinccxx . . $ phaseinc. = (wdatacxx . . $ wdata..pitch>>7) * PHASE_INC_FACTORcxx . . $ PHASE_INC_FACTOR.; |
| 742 | cycle_samplescxx . . $ cycle_samples. = sampleratecxx . . $ samplerate./(wdatacxx . . $ wdata..pitch >> 12); // sr/(pitch*2) |
| 743 | hf_factorcxx . . $ hf_factor. = wdatacxx . . $ wdata..pitch >> 11; |
| 744 | |
| 745 | maxh = maxh2; |
| 746 | harmspectcxx . . $ harmspect. = hspectcxx . . $ hspect.[hswitchcxx . . $ hswitch.]; |
| 747 | hswitchcxx . . $ hswitch. ^= 1; |
| 748 | maxh2 = PeaksToHarmspectcxx . . $ PeaksToHarmspect(28c13c71e9410f67).(peakscxx . . $ peaks., wdatacxx . . $ wdata..pitch<<4, hspectcxx . . $ hspect.[hswitchcxx . . $ hswitch.], 1); |
| 749 | |
| 750 | SetBreathcxx . . $ SetBreath(49f6e7a06ebc5aa8).(); |
| 751 | } else if ((samplecountcxx . . $ samplecount. & 0x07) == 0) { |
| 752 | for (h = 1; h < N_LOWHARMcxx . . $ `external/espeak/wavegen.cpp:81:9`! && h <= maxh2 && h <= maxh; h++) |
| 753 | harmspectcxx . . $ harmspect.[h] += harm_inccxx . . $ harm_inc.[h]; |
| 754 | |
| 755 | // bring automatic gain control back towards unity |
| 756 | if (agc < 256) agc++; |
| 757 | } |
| 758 | |
| 759 | samplecountcxx . . $ samplecount.++; |
| 760 | |
| 761 | if (wavephasecxx . . $ wavephase. > 0) { |
| 762 | wavephasecxx . . $ wavephase. += phaseinccxx . . $ phaseinc.; |
| 763 | if (wavephasecxx . . $ wavephase. < 0) { |
| 764 | // sign has changed, reached a quiet point in the waveform |
| 765 | cbytescxx . . $ cbytes. = wavemult_offsetcxx . . $ wavemult_offset. - (cycle_samplescxx . . $ cycle_samples.)/2; |
| 766 | if (samplecountcxx . . $ samplecount. > nsamplescxx . . $ nsamples.) |
| 767 | return 0; |
| 768 | |
| 769 | cycle_count++; |
| 770 | |
| 771 | for (pk = wavegenVoice->n_harmonic_peaks+1; pk < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; pk++) { |
| 772 | // find the nearest harmonic for HF peaks where we don't use shape |
| 773 | peak_harmoniccxx . . $ peak_harmonic.[pk] = ((peakscxx . . $ peaks.[pk].freq / (wdatacxx . . $ wdata..pitch*8)) + 1) / 2; |
| 774 | } |
| 775 | |
| 776 | // adjust amplitude to compensate for fewer harmonics at higher pitch |
| 777 | amplitude2 = (wdatacxx . . $ wdata..amplitude * (wdatacxx . . $ wdata..pitch >> 8) * wdatacxx . . $ wdata..amplitude_fmt)/(10000 << 3); |
| 778 | |
| 779 | if (glottal_flagcxx . . $ glottal_flag. > 0) { |
| 780 | if (glottal_flagcxx . . $ glottal_flag. == 3) { |
| 781 | if ((nsamplescxx . . $ nsamples.-samplecountcxx . . $ samplecount.) < (cycle_samplescxx . . $ cycle_samples.*2)) { |
| 782 | // Vowel before glottal-stop. |
| 783 | // This is the start of the penultimate cycle, reduce its amplitude |
| 784 | glottal_flagcxx . . $ glottal_flag. = 2; |
| 785 | amplitude2 = (amplitude2 * glottal_reducecxx . . $ glottal_reduce.)/256; |
| 786 | } |
| 787 | } else if (glottal_flagcxx . . $ glottal_flag. == 4) { |
| 788 | // Vowel following a glottal-stop. |
| 789 | // This is the start of the second cycle, reduce its amplitude |
| 790 | glottal_flagcxx . . $ glottal_flag. = 2; |
| 791 | amplitude2 = (amplitude2 * glottal_reducecxx . . $ glottal_reduce.)/256; |
| 792 | } else |
| 793 | glottal_flagcxx . . $ glottal_flag.--; |
| 794 | } |
| 795 | |
| 796 | if (amplitude_envcxx . . $ amplitude_env. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 797 | // amplitude envelope is only used for creaky voice effect on certain vowels/tones |
| 798 | if ((ix = amp_ixcxx . . $ amp_ix.>>8) > 127) ix = 127; |
| 799 | amp = amplitude_envcxx . . $ amplitude_env.[ix]; |
| 800 | amplitude2 = (amplitude2 * amp)/128; |
| 801 | } |
| 802 | |
| 803 | // introduce roughness into the sound by reducing the amplitude of |
| 804 | modn_period = 0; |
| 805 | if (voice->roughness < N_ROUGHNESScxx . . $ `external/espeak/wavegen.cpp:134:9`!) { |
| 806 | modn_period = modulation_tabcxx . . $ modulation_tab.[voice->roughness][modulation_typecxx . . $ modulation_type.]; |
| 807 | modn_amp = modn_period & 0xf; |
| 808 | modn_period = modn_period >> 4; |
| 809 | } |
| 810 | |
| 811 | if (modn_period != 0) { |
| 812 | if (modn_period == 0xf) { |
| 813 | // just once */ |
| 814 | amplitude2 = (amplitude2 * modn_amp)/16; |
| 815 | modulation_typecxx . . $ modulation_type. = 0; |
| 816 | } else { |
| 817 | // reduce amplitude every [modn_period} cycles |
| 818 | if ((cycle_count % modn_period) == 0) |
| 819 | amplitude2 = (amplitude2 * modn_amp)/16; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } else |
| 824 | wavephasecxx . . $ wavephase. += phaseinccxx . . $ phaseinc.; |
| 825 | waveph = (unsigned short)(wavephasecxx . . $ wavephase. >> 16); |
| 826 | total = 0; |
| 827 | |
| 828 | // apply HF peaks, formants 6,7,8 |
| 829 | // add a single harmonic and then spread this my multiplying by a |
| 830 | // window. This is to reduce the processing power needed to add the |
| 831 | // higher frequence harmonics. |
| 832 | cbytescxx . . $ cbytes.++; |
| 833 | if (cbytescxx . . $ cbytes. >= 0 && cbytescxx . . $ cbytes. < wavemult_maxcxx . . $ wavemult_max.) { |
| 834 | for (pk = wavegenVoice->n_harmonic_peaks+1; pk < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; pk++) { |
| 835 | theta = peak_harmoniccxx . . $ peak_harmonic.[pk] * waveph; |
| 836 | total += (long)sin_tab[theta >> 5] * peak_heightcxx . . $ peak_height.[pk]; |
| 837 | } |
| 838 | |
| 839 | // spread the peaks by multiplying by a window |
| 840 | total = (long)(total / hf_factorcxx . . $ hf_factor.) * wavemultcxx . . $ wavemult.[cbytescxx . . $ cbytes.]; |
| 841 | } |
| 842 | |
| 843 | // apply main peaks, formants 0 to 5 |
| 844 | theta = waveph; |
| 845 | |
| 846 | for (h = 1; h <= h_switch_sign; h++) { |
| 847 | total += ((int)sin_tab[theta >> 5] * harmspectcxx . . $ harmspect.[h]); |
| 848 | theta += waveph; |
| 849 | } |
| 850 | while (h <= maxh) { |
| 851 | total -= ((int)sin_tab[theta >> 5] * harmspectcxx . . $ harmspect.[h]); |
| 852 | theta += waveph; |
| 853 | h++; |
| 854 | } |
| 855 | |
| 856 | if (voicingcxx . . $ voicing. != 64) |
| 857 | total = (total >> 6) * voicingcxx . . $ voicing.; |
| 858 | |
| 859 | if (wavegenVoice->breath[0]) |
| 860 | total += ApplyBreathcxx . . $ ApplyBreath(b126dc7c1de90089).(); |
| 861 | |
| 862 | // mix with sampled wave if required |
| 863 | z2 = 0; |
| 864 | if (wdatacxx . . $ wdata..mix_wavefile_ix < wdatacxx . . $ wdata..n_mix_wavefile) { |
| 865 | if (wdatacxx . . $ wdata..mix_wave_scale == 0) { |
| 866 | // a 16 bit sample |
| 867 | c = wdatacxx . . $ wdata..mix_wavefile[wdatacxx . . $ wdata..mix_wavefile_ix+wdatacxx . . $ wdata..mix_wavefile_offset+1]; |
| 868 | sample = wdatacxx . . $ wdata..mix_wavefile[wdatacxx . . $ wdata..mix_wavefile_ix+wdatacxx . . $ wdata..mix_wavefile_offset] + (c * 256); |
| 869 | wdatacxx . . $ wdata..mix_wavefile_ix += 2; |
| 870 | } else { |
| 871 | // a 8 bit sample, scaled |
| 872 | sample = (signed char)wdatacxx . . $ wdata..mix_wavefile[wdatacxx . . $ wdata..mix_wavefile_offset+wdatacxx . . $ wdata..mix_wavefile_ix++] * wdatacxx . . $ wdata..mix_wave_scale; |
| 873 | } |
| 874 | z2 = (sample * wdatacxx . . $ wdata..amplitude_v) >> 10; |
| 875 | z2 = (z2 * wdatacxx . . $ wdata..mix_wave_amp)/32; |
| 876 | |
| 877 | if ((wdatacxx . . $ wdata..mix_wavefile_ix + wdatacxx . . $ wdata..mix_wavefile_offset) >= wdatacxx . . $ wdata..mix_wavefile_max) // reached the end of available WAV data |
| 878 | wdatacxx . . $ wdata..mix_wavefile_offset -= (wdatacxx . . $ wdata..mix_wavefile_max*3)/4; |
| 879 | } |
| 880 | |
| 881 | z1 = z2 + (((total>>8) * amplitude2) >> 13); |
| 882 | |
| 883 | echo = (echo_bufcxx . . $ echo_buf.[echo_tailcxx . . $ echo_tail.++] * echo_ampcxx . . $ echo_amp.); |
| 884 | z1 += echo >> 8; |
| 885 | if (echo_tailcxx . . $ echo_tail. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 886 | echo_tailcxx . . $ echo_tail. = 0; |
| 887 | |
| 888 | z = (z1 * agc) >> 8; |
| 889 | |
| 890 | // check for overflow, 16bit signed samples |
| 891 | if (z >= 32768) { |
| 892 | ov = 8388608/z1 - 1; // 8388608 is 2^23, i.e. max value * 256 |
| 893 | if (ov < agc) agc = ov; // set agc to number of 1/256ths to multiply the sample by |
| 894 | z = (z1 * agc) >> 8; // reduce sample by agc value to prevent overflow |
| 895 | } else if (z <= -32768) { |
| 896 | ov = -8388608/z1 - 1; |
| 897 | if (ov < agc) agc = ov; |
| 898 | z = (z1 * agc) >> 8; |
| 899 | } |
| 900 | *out_ptrcxx . . $ out_ptr.++ = z; |
| 901 | *out_ptrcxx . . $ out_ptr.++ = z >> 8; |
| 902 | if(output_hookscxx . . $ output_hooks. && output_hookscxx . . $ output_hooks.->outputVoiced) output_hookscxx . . $ output_hooks.->outputVoiced(z); |
| 903 | |
| 904 | echo_bufcxx . . $ echo_buf.[echo_headcxx . . $ echo_head.++] = z; |
| 905 | if (echo_headcxx . . $ echo_head. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 906 | echo_headcxx . . $ echo_head. = 0; |
| 907 | |
| 908 | if (out_ptrcxx . . $ out_ptr. + 2 > out_endcxx . . $ out_end.) |
| 909 | return 1; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | static int PlaySilencecxx . . $ PlaySilence(d455ce14f374a3ab).(int length, bool resume) |
| 914 | { |
| 915 | static int n_samples; |
| 916 | |
| 917 | nsamplescxx . . $ nsamples. = 0; |
| 918 | samplecountcxx . . $ samplecount. = 0; |
| 919 | wavephasecxx . . $ wavephase. = 0x7fffffff; |
| 920 | |
| 921 | if (length == 0) |
| 922 | return 0; |
| 923 | |
| 924 | if (resume == false) |
| 925 | n_samples = length; |
| 926 | |
| 927 | int value = 0; |
| 928 | while (n_samples-- > 0) { |
| 929 | value = (echo_bufcxx . . $ echo_buf.[echo_tailcxx . . $ echo_tail.++] * echo_ampcxx . . $ echo_amp.) >> 8; |
| 930 | |
| 931 | if (echo_tailcxx . . $ echo_tail. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 932 | echo_tailcxx . . $ echo_tail. = 0; |
| 933 | |
| 934 | *out_ptrcxx . . $ out_ptr.++ = value; |
| 935 | *out_ptrcxx . . $ out_ptr.++ = value >> 8; |
| 936 | if(output_hookscxx . . $ output_hooks. && output_hookscxx . . $ output_hooks.->outputSilence) output_hookscxx . . $ output_hooks.->outputSilence(value); |
| 937 | |
| 938 | echo_bufcxx . . $ echo_buf.[echo_headcxx . . $ echo_head.++] = value; |
| 939 | if (echo_headcxx . . $ echo_head. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 940 | echo_headcxx . . $ echo_head. = 0; |
| 941 | |
| 942 | if (out_ptrcxx . . $ out_ptr. + 2 > out_endcxx . . $ out_end.) |
| 943 | return 1; |
| 944 | } |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | static int PlayWavecxx . . $ PlayWave(78401365e8fb678e).(int length, bool resume, unsigned char *data, int scale, int amp) |
| 949 | { |
| 950 | static int n_samples; |
| 951 | static int ix = 0; |
| 952 | int value; |
| 953 | signed char c; |
| 954 | |
| 955 | if (resume == false) { |
| 956 | n_samples = length; |
| 957 | ix = 0; |
| 958 | } |
| 959 | |
| 960 | nsamplescxx . . $ nsamples. = 0; |
| 961 | samplecountcxx . . $ samplecount. = 0; |
| 962 | |
| 963 | while (n_samples-- > 0) { |
| 964 | if (scale == 0) { |
| 965 | // 16 bits data |
| 966 | c = data[ix+1]; |
| 967 | value = data[ix] + (c * 256); |
| 968 | ix += 2; |
| 969 | } else { |
| 970 | // 8 bit data, shift by the specified scale factor |
| 971 | value = (signed char)data[ix++] * scale; |
| 972 | } |
| 973 | value *= (consonant_ampcxx . . $ consonant_amp. * general_amplitudecxx . . $ general_amplitude.); // reduce strength of consonant |
| 974 | value = value >> 10; |
| 975 | value = (value * amp)/32; |
| 976 | |
| 977 | value += ((echo_bufcxx . . $ echo_buf.[echo_tailcxx . . $ echo_tail.++] * echo_ampcxx . . $ echo_amp.) >> 8); |
| 978 | |
| 979 | if (value > 32767) |
| 980 | value = 32767; |
| 981 | else if (value < -32768) |
| 982 | value = -32768; |
| 983 | |
| 984 | if (echo_tailcxx . . $ echo_tail. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 985 | echo_tailcxx . . $ echo_tail. = 0; |
| 986 | |
| 987 | out_ptrcxx . . $ out_ptr.[0] = value; |
| 988 | out_ptrcxx . . $ out_ptr.[1] = value >> 8; |
| 989 | if(output_hookscxx . . $ output_hooks. && output_hookscxx . . $ output_hooks.->outputUnvoiced) output_hookscxx . . $ output_hooks.->outputUnvoiced(value); |
| 990 | out_ptrcxx . . $ out_ptr. += 2; |
| 991 | |
| 992 | echo_bufcxx . . $ echo_buf.[echo_headcxx . . $ echo_head.++] = (value*3)/4; |
| 993 | if (echo_headcxx . . $ echo_head. >= N_ECHO_BUFcxx . . $ `external/espeak/synthesize.h:427:9`!) |
| 994 | echo_headcxx . . $ echo_head. = 0; |
| 995 | |
| 996 | if (out_ptrcxx . . $ out_ptr. + 2 > out_endcxx . . $ out_end.) |
| 997 | return 1; |
| 998 | } |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | static int SetWithRange0cxx . . $ SetWithRange0(9b79fb6aee4c0440).(int value, int max) |
| 1003 | { |
| 1004 | if (value < 0) |
| 1005 | return 0; |
| 1006 | if (value > max) |
| 1007 | return max; |
| 1008 | return value; |
| 1009 | } |
| 1010 | |
| 1011 | static void SetPitchFormantscxx . . $ SetPitchFormants(49f6e7a06ebc5aa8).(void) |
| 1012 | { |
| 1013 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1014 | return; |
| 1015 | |
| 1016 | int ix; |
| 1017 | int factor = 256; |
| 1018 | int pitch_value; |
| 1019 | |
| 1020 | // adjust formants to give better results for a different voice pitch |
| 1021 | if ((pitch_value = embedded_valuecxx . . $ embedded_value.[EMBED_Pcxx . . $ `external/espeak/synthesize.h:63:9`!]) > MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`!) |
| 1022 | pitch_value = MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`!; |
| 1023 | |
| 1024 | if (pitch_value > 50) { |
| 1025 | // only adjust if the pitch is higher than normal |
| 1026 | factor = 256 + (25 * (pitch_value - 50))/50; |
| 1027 | } |
| 1028 | |
| 1029 | for (ix = 0; ix <= 5; ix++) |
| 1030 | wvoicecxx . . $ wvoice.->freq[ix] = (wvoicecxx . . $ wvoice.->freq2[ix] * factor)/256; |
| 1031 | |
| 1032 | factor = embedded_valuecxx . . $ embedded_value.[EMBED_Tcxx . . $ `external/espeak/synthesize.h:68:9`!]*3; |
| 1033 | wvoicecxx . . $ wvoice.->height[0] = (wvoicecxx . . $ wvoice.->height2[0] * (256 - factor*2))/256; |
| 1034 | wvoicecxx . . $ wvoice.->height[1] = (wvoicecxx . . $ wvoice.->height2[1] * (256 - factor))/256; |
| 1035 | } |
| 1036 | |
| 1037 | void SetEmbeddedcxx . . $ SetEmbedded(3e454b8ccf442868).(int control, int value) |
| 1038 | { |
| 1039 | // there was an embedded command in the text at this point |
| 1040 | int sign = 0; |
| 1041 | int command; |
| 1042 | |
| 1043 | command = control & 0x1f; |
| 1044 | if ((control & 0x60) == 0x60) |
| 1045 | sign = -1; |
| 1046 | else if ((control & 0x60) == 0x40) |
| 1047 | sign = 1; |
| 1048 | |
| 1049 | if (command < N_EMBEDDED_VALUEScxx . . $ `external/espeak/synthesize.h:77:9`!) { |
| 1050 | if (sign == 0) |
| 1051 | embedded_valuecxx . . $ embedded_value.[command] = value; |
| 1052 | else |
| 1053 | embedded_valuecxx . . $ embedded_value.[command] += (value * sign); |
| 1054 | embedded_valuecxx . . $ embedded_value.[command] = SetWithRange0cxx . . $ SetWithRange0(9b79fb6aee4c0440).(embedded_valuecxx . . $ embedded_value.[command], embedded_maxcxx . . $ embedded_max.[command]); |
| 1055 | } |
| 1056 | |
| 1057 | switch (command) |
| 1058 | { |
| 1059 | case EMBED_Tcxx . . $ `external/espeak/synthesize.h:68:9`!: |
| 1060 | WavegenSetEchocxx . . $ WavegenSetEcho(49f6e7a06ebc5aa8).(); // and drop through to case P |
| 1061 | case EMBED_Pcxx . . $ `external/espeak/synthesize.h:63:9`!: |
| 1062 | SetPitchFormantscxx . . $ SetPitchFormants(49f6e7a06ebc5aa8).(); |
| 1063 | break; |
| 1064 | case EMBED_Acxx . . $ `external/espeak/synthesize.h:65:9`!: // amplitude |
| 1065 | general_amplitudecxx . . $ general_amplitude. = GetAmplitudecxx . . $ GetAmplitude(b126dc7c1de90089).(); |
| 1066 | break; |
| 1067 | case EMBED_Fcxx . . $ `external/espeak/synthesize.h:75:9`!: // emphasis |
| 1068 | general_amplitudecxx . . $ general_amplitude. = GetAmplitudecxx . . $ GetAmplitude(b126dc7c1de90089).(); |
| 1069 | break; |
| 1070 | case EMBED_Hcxx . . $ `external/espeak/synthesize.h:67:9`!: |
| 1071 | WavegenSetEchocxx . . $ WavegenSetEcho(49f6e7a06ebc5aa8).(); |
| 1072 | break; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | void WavegenSetVoicecxx . . $ WavegenSetVoice(d80a4fbed906f5aa).(voice_t *v) |
| 1077 | { |
| 1078 | static voice_t v2; |
| 1079 | |
| 1080 | memcpy(&v2, v, sizeof(v2)); |
| 1081 | wvoicecxx . . $ wvoice. = &v2; |
| 1082 | |
| 1083 | if (v->peak_shape == 0) |
| 1084 | pk_shapecxx . . $ pk_shape. = pk_shape1cxx . . $ pk_shape1.; |
| 1085 | else |
| 1086 | pk_shapecxx . . $ pk_shape. = pk_shape2cxx . . $ pk_shape2.; |
| 1087 | |
| 1088 | consonant_ampcxx . . $ consonant_amp. = (v->consonant_amp * 26) /100; |
| 1089 | if (sampleratecxx . . $ samplerate. <= 11000) { |
| 1090 | consonant_ampcxx . . $ consonant_amp. = consonant_ampcxx . . $ consonant_amp.*2; // emphasize consonants at low sample rates |
| 1091 | option_harmonic1cxx . . $ option_harmonic1. = 6; |
| 1092 | } |
| 1093 | WavegenSetEchocxx . . $ WavegenSetEcho(49f6e7a06ebc5aa8).(); |
| 1094 | SetPitchFormantscxx . . $ SetPitchFormants(49f6e7a06ebc5aa8).(); |
| 1095 | MarkerEvent(espeakEVENT_SAMPLERATEcxx . . $ espeakEVENT_SAMPLERATE., 0, wvoicecxx . . $ wvoice.->samplerate, 0, out_ptrcxx . . $ out_ptr.); |
| 1096 | } |
| 1097 | |
| 1098 | static void SetAmplitudecxx . . $ SetAmplitude(dde21517a502ab05).(int length, unsigned char *amp_env, int value) |
| 1099 | { |
| 1100 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1101 | return; |
| 1102 | |
| 1103 | amp_ixcxx . . $ amp_ix. = 0; |
| 1104 | if (length == 0) |
| 1105 | amp_inccxx . . $ amp_inc. = 0; |
| 1106 | else |
| 1107 | amp_inccxx . . $ amp_inc. = (256 * ENV_LENcxx . . $ `external/espeak/synthesize.h:446:9`! * STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!)/length; |
| 1108 | |
| 1109 | wdatacxx . . $ wdata..amplitude = (value * general_amplitudecxx . . $ general_amplitude.)/16; |
| 1110 | wdatacxx . . $ wdata..amplitude_v = (wdatacxx . . $ wdata..amplitude * wvoicecxx . . $ wvoice.->consonant_ampv * 15)/100; // for wave mixed with voiced sounds |
| 1111 | |
| 1112 | amplitude_envcxx . . $ amplitude_env. = amp_env; |
| 1113 | } |
| 1114 | |
| 1115 | void SetPitch2cxx . . $ SetPitch2(3f655e8a4d0474eb).(voice_t *voicet, int pitch1, int pitch2, int *pitch_base, int *pitch_range) |
| 1116 | { |
| 1117 | int base; |
| 1118 | int range; |
| 1119 | int pitch_value; |
| 1120 | |
| 1121 | if (pitch1 > pitch2) { |
| 1122 | int x; |
| 1123 | x = pitch1; // swap values |
| 1124 | pitch1 = pitch2; |
| 1125 | pitch2 = x; |
| 1126 | } |
| 1127 | |
| 1128 | if ((pitch_value = embedded_valuecxx . . $ embedded_value.[EMBED_Pcxx . . $ `external/espeak/synthesize.h:63:9`!]) > MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`!) |
| 1129 | pitch_value = MAX_PITCH_VALUEcxx . . $ `external/espeak/wavegen.cpp:222:9`!; |
| 1130 | pitch_value -= embedded_valuecxx . . $ embedded_value.[EMBED_Tcxx . . $ `external/espeak/synthesize.h:68:9`!]; // adjust tone for announcing punctuation |
| 1131 | if (pitch_value < 0) |
| 1132 | pitch_value = 0; |
| 1133 | |
| 1134 | base = (voicet->pitch_base * pitch_adjust_tabcxx . . $ pitch_adjust_tab.[pitch_value])/128; |
| 1135 | range = (voicet->pitch_range * embedded_valuecxx . . $ embedded_value.[EMBED_Rcxx . . $ `external/espeak/synthesize.h:66:9`!])/50; |
| 1136 | |
| 1137 | // compensate for change in pitch when the range is narrowed or widened |
| 1138 | base -= (range - voicet->pitch_range)*18; |
| 1139 | |
| 1140 | *pitch_base = base + (pitch1 * range)/2; |
| 1141 | *pitch_range = base + (pitch2 * range)/2 - *pitch_base; |
| 1142 | } |
| 1143 | |
| 1144 | static void SetPitchcxx . . $ SetPitch(34ee600be5240935).(int length, unsigned char *env, int pitch1, int pitch2) |
| 1145 | { |
| 1146 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1147 | return; |
| 1148 | |
| 1149 | // length in samples |
| 1150 | |
| 1151 | if ((wdatacxx . . $ wdata..pitch_env = env) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1152 | wdatacxx . . $ wdata..pitch_env = env_fall; // default |
| 1153 | |
| 1154 | wdatacxx . . $ wdata..pitch_ix = 0; |
| 1155 | if (length == 0) |
| 1156 | wdatacxx . . $ wdata..pitch_inc = 0; |
| 1157 | else |
| 1158 | wdatacxx . . $ wdata..pitch_inc = (256 * ENV_LENcxx . . $ `external/espeak/synthesize.h:446:9`! * STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!)/length; |
| 1159 | |
| 1160 | SetPitch2cxx . . $ SetPitch2(3f655e8a4d0474eb).(wvoicecxx . . $ wvoice., pitch1, pitch2, &wdatacxx . . $ wdata..pitch_base, &wdatacxx . . $ wdata..pitch_range); |
| 1161 | // set initial pitch |
| 1162 | wdatacxx . . $ wdata..pitch = ((wdatacxx . . $ wdata..pitch_env[0] * wdatacxx . . $ wdata..pitch_range) >>8) + wdatacxx . . $ wdata..pitch_base; // Hz << 12 |
| 1163 | |
| 1164 | flutter_ampcxx . . $ flutter_amp. = wvoicecxx . . $ wvoice.->flutter; |
| 1165 | } |
| 1166 | |
| 1167 | static void SetSynthcxx . . $ SetSynth(cdd8e8d4e631e94e).(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v) |
| 1168 | { |
| 1169 | if (wvoicecxx . . $ wvoice. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || v == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1170 | return; |
| 1171 | |
| 1172 | int ix; |
| 1173 | double next; |
| 1174 | int length2; |
| 1175 | int length4; |
| 1176 | int qix; |
| 1177 | static const int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256 |
| 1178 | static const int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256 |
| 1179 | |
| 1180 | end_wavecxx . . $ end_wave. = 1; |
| 1181 | |
| 1182 | // any additional information in the param1 ? |
| 1183 | modulation_typecxx . . $ modulation_type. = modn & 0xff; |
| 1184 | |
| 1185 | glottal_flagcxx . . $ glottal_flag. = 0; |
| 1186 | if (modn & 0x400) { |
| 1187 | glottal_flagcxx . . $ glottal_flag. = 3; // before a glottal stop |
| 1188 | glottal_reducecxx . . $ glottal_reduce. = glottal_reduce_tab1[(modn >> 8) & 3]; |
| 1189 | } |
| 1190 | if (modn & 0x800) { |
| 1191 | glottal_flagcxx . . $ glottal_flag. = 4; // after a glottal stop |
| 1192 | glottal_reducecxx . . $ glottal_reduce. = glottal_reduce_tab2[(modn >> 8) & 3]; |
| 1193 | } |
| 1194 | |
| 1195 | for (qix = wcmdq_headcxx . . $ wcmdq_head.+1;; qix++) { |
| 1196 | if (qix >= N_WCMDQcxx . . $ `external/espeak/synthesize.h:415:9`!) qix = 0; |
| 1197 | if (qix == wcmdq_tailcxx . . $ wcmdq_tail.) break; |
| 1198 | |
| 1199 | int cmd = wcmdqcxx . . $ wcmdq.[qix][0]; |
| 1200 | if (cmd == WCMD_SPECTcxx . . $ `external/espeak/synthesize.h:400:9`!) { |
| 1201 | end_wavecxx . . $ end_wave. = 0; // next wave generation is from another spectrum |
| 1202 | break; |
| 1203 | } |
| 1204 | if ((cmd == WCMD_WAVEcxx . . $ `external/espeak/synthesize.h:403:9`!) || (cmd == WCMD_PAUSEcxx . . $ `external/espeak/synthesize.h:402:9`!)) |
| 1205 | break; // next is not from spectrum, so continue until end of wave cycle |
| 1206 | } |
| 1207 | |
| 1208 | // round the length to a multiple of the stepsize |
| 1209 | length2 = (length + STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!/2) & ~0x3f; |
| 1210 | if (length2 == 0) |
| 1211 | length2 = STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!; |
| 1212 | |
| 1213 | // add this length to any left over from the previous synth |
| 1214 | samplecount_startcxx . . $ samplecount_start. = samplecountcxx . . $ samplecount.; |
| 1215 | nsamplescxx . . $ nsamples. += length2; |
| 1216 | |
| 1217 | length4 = length2/4; |
| 1218 | |
| 1219 | peakscxx . . $ peaks.[7].freq = (7800 * v->freq[7] + v->freqadd[7]*256) << 8; |
| 1220 | peakscxx . . $ peaks.[8].freq = (9000 * v->freq[8] + v->freqadd[8]*256) << 8; |
| 1221 | |
| 1222 | for (ix = 0; ix < 8; ix++) { |
| 1223 | if (ix < 7) { |
| 1224 | peakscxx . . $ peaks.[ix].freq1 = (fr1->ffreq[ix] * v->freq[ix] + v->freqadd[ix]*256) << 8; |
| 1225 | peakscxx . . $ peaks.[ix].freq = (int)peakscxx . . $ peaks.[ix].freq1; |
| 1226 | next = (fr2->ffreq[ix] * v->freq[ix] + v->freqadd[ix]*256) << 8; |
| 1227 | peakscxx . . $ peaks.[ix].freq_inc = ((next - peakscxx . . $ peaks.[ix].freq1) * (STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!/4)) / length4; // lower headroom for fixed point math |
| 1228 | } |
| 1229 | |
| 1230 | peakscxx . . $ peaks.[ix].height1 = (fr1->fheight[ix] * v->height[ix]) << 6; |
| 1231 | peakscxx . . $ peaks.[ix].height = (int)peakscxx . . $ peaks.[ix].height1; |
| 1232 | next = (fr2->fheight[ix] * v->height[ix]) << 6; |
| 1233 | peakscxx . . $ peaks.[ix].height_inc = ((next - peakscxx . . $ peaks.[ix].height1) * STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!) / length2; |
| 1234 | |
| 1235 | if ((ix <= 5) && (ix <= wvoicecxx . . $ wvoice.->n_harmonic_peaks)) { |
| 1236 | peakscxx . . $ peaks.[ix].left1 = (fr1->fwidth[ix] * v->width[ix]) << 10; |
| 1237 | peakscxx . . $ peaks.[ix].left = (int)peakscxx . . $ peaks.[ix].left1; |
| 1238 | next = (fr2->fwidth[ix] * v->width[ix]) << 10; |
| 1239 | peakscxx . . $ peaks.[ix].left_inc = ((next - peakscxx . . $ peaks.[ix].left1) * STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!) / length2; |
| 1240 | |
| 1241 | if (ix < 3) { |
| 1242 | peakscxx . . $ peaks.[ix].right1 = (fr1->fright[ix] * v->width[ix]) << 10; |
| 1243 | peakscxx . . $ peaks.[ix].right = (int)peakscxx . . $ peaks.[ix].right1; |
| 1244 | next = (fr2->fright[ix] * v->width[ix]) << 10; |
| 1245 | peakscxx . . $ peaks.[ix].right_inc = ((next - peakscxx . . $ peaks.[ix].right1) * STEPSIZEcxx . . $ `external/espeak/synthesize.h:38:9`!) / length2; |
| 1246 | } else |
| 1247 | peakscxx . . $ peaks.[ix].right = peakscxx . . $ peaks.[ix].left; |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | void Write4Bytescxx . . $ Write4Bytes(e780f64711fb334f).(FILE *f, int value) |
| 1253 | { |
| 1254 | // Write 4 bytes to a file, least significant first |
| 1255 | int ix; |
| 1256 | |
| 1257 | for (ix = 0; ix < 4; ix++) { |
| 1258 | fputc(value & 0xff, f); |
| 1259 | value = value >> 8; |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | static int WavegenFill2cxx . . $ WavegenFill2(b126dc7c1de90089).(void) |
| 1264 | { |
| 1265 | // Pick up next wavegen commands from the queue |
| 1266 | // return: 0 output buffer has been filled |
| 1267 | // return: 1 input command queue is now empty |
| 1268 | intptr_tcxx . . $ intptr_t# *q; |
| 1269 | int length; |
| 1270 | int result; |
| 1271 | int marker_type; |
| 1272 | static bool resume = false; |
| 1273 | static int echo_complete = 0; |
| 1274 | |
| 1275 | if (wdatacxx . . $ wdata..pitch < 102400) |
| 1276 | wdatacxx . . $ wdata..pitch = 102400; // min pitch, 25 Hz (25 << 12) |
| 1277 | |
| 1278 | while (out_ptrcxx . . $ out_ptr. < out_endcxx . . $ out_end.) { |
| 1279 | if (WcmdqUsedcxx . . $ WcmdqUsed(b126dc7c1de90089).() <= 0) { |
| 1280 | if (echo_complete > 0) { |
| 1281 | // continue to play silence until echo is completed |
| 1282 | resume = PlaySilencecxx . . $ PlaySilence(d455ce14f374a3ab).(echo_complete, resume); |
| 1283 | if (resume == true) |
| 1284 | return 0; // not yet finished |
| 1285 | } |
| 1286 | return 1; // queue empty, close sound channel |
| 1287 | } |
| 1288 | |
| 1289 | result = 0; |
| 1290 | q = wcmdqcxx . . $ wcmdq.[wcmdq_headcxx . . $ wcmdq_head.]; |
| 1291 | length = q[1]; |
| 1292 | |
| 1293 | switch (q[0] & 0xff) |
| 1294 | { |
| 1295 | case WCMD_PITCHcxx . . $ `external/espeak/synthesize.h:406:9`!: |
| 1296 | SetPitchcxx . . $ SetPitch(34ee600be5240935).(length, (unsigned char *)q[2], q[3] >> 16, q[3] & 0xffff); |
| 1297 | break; |
| 1298 | case WCMD_PHONEME_ALIGNMENTcxx . . $ `external/espeak/synthesize.h:413:9`!: |
| 1299 | { |
| 1300 | char* data = (char*)q[1]; |
| 1301 | output_hookscxx . . $ output_hooks.->outputPhoSymbol(data,q[2]); |
| 1302 | freecxx . . $ free(bd21765a0afc8e3c).(data); |
| 1303 | } |
| 1304 | break; |
| 1305 | case WCMD_PAUSEcxx . . $ `external/espeak/synthesize.h:402:9`!: |
| 1306 | if (resume == false) |
| 1307 | echo_complete -= length; |
| 1308 | wdatacxx . . $ wdata..n_mix_wavefile = 0; |
| 1309 | wdatacxx . . $ wdata..amplitude_fmt = 100; |
| 1310 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 1311 | KlattReset(1); |
| 1312 | #endif |
| 1313 | result = PlaySilencecxx . . $ PlaySilence(d455ce14f374a3ab).(length, resume); |
| 1314 | break; |
| 1315 | case WCMD_WAVEcxx . . $ `external/espeak/synthesize.h:403:9`!: |
| 1316 | echo_complete = echo_lengthcxx . . $ echo_length.; |
| 1317 | wdatacxx . . $ wdata..n_mix_wavefile = 0; |
| 1318 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 1319 | KlattReset(1); |
| 1320 | #endif |
| 1321 | result = PlayWavecxx . . $ PlayWave(78401365e8fb678e).(length, resume, (unsigned char *)q[2], q[3] & 0xff, q[3] >> 8); |
| 1322 | break; |
| 1323 | case WCMD_WAVE2cxx . . $ `external/espeak/synthesize.h:404:9`!: |
| 1324 | // wave file to be played at the same time as synthesis |
| 1325 | wdatacxx . . $ wdata..mix_wave_amp = q[3] >> 8; |
| 1326 | wdatacxx . . $ wdata..mix_wave_scale = q[3] & 0xff; |
| 1327 | wdatacxx . . $ wdata..n_mix_wavefile = (length & 0xffff); |
| 1328 | wdatacxx . . $ wdata..mix_wavefile_max = (length >> 16) & 0xffff; |
| 1329 | if (wdatacxx . . $ wdata..mix_wave_scale == 0) { |
| 1330 | wdatacxx . . $ wdata..n_mix_wavefile *= 2; |
| 1331 | wdatacxx . . $ wdata..mix_wavefile_max *= 2; |
| 1332 | } |
| 1333 | wdatacxx . . $ wdata..mix_wavefile_ix = 0; |
| 1334 | wdatacxx . . $ wdata..mix_wavefile_offset = 0; |
| 1335 | wdatacxx . . $ wdata..mix_wavefile = (unsigned char *)q[2]; |
| 1336 | break; |
| 1337 | case WCMD_SPECT2cxx . . $ `external/espeak/synthesize.h:401:9`!: // as WCMD_SPECT but stop any concurrent wave file |
| 1338 | wdatacxx . . $ wdata..n_mix_wavefile = 0; // ... and drop through to WCMD_SPECT case |
| 1339 | case WCMD_SPECTcxx . . $ `external/espeak/synthesize.h:400:9`!: |
| 1340 | echo_complete = echo_lengthcxx . . $ echo_length.; |
| 1341 | result = Wavegencxx . . $ Wavegen(dc5db46c9e56eacc).(length & 0xffff, q[1] >> 16, resume, (frame_t *)q[2], (frame_t *)q[3], wvoicecxx . . $ wvoice.); |
| 1342 | break; |
| 1343 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 1344 | case WCMD_KLATT2cxx . . $ `external/espeak/synthesize.h:399:9`!: // as WCMD_SPECT but stop any concurrent wave file |
| 1345 | wdatacxx . . $ wdata..n_mix_wavefile = 0; // ... and drop through to WCMD_SPECT case |
| 1346 | case WCMD_KLATTcxx . . $ `external/espeak/synthesize.h:398:9`!: |
| 1347 | echo_complete = echo_lengthcxx . . $ echo_length.; |
| 1348 | result = Wavegen_Klatt(length & 0xffff, resume, (frame_t *)q[2], (frame_t *)q[3], &wdatacxx . . $ wdata., wvoicecxx . . $ wvoice.); |
| 1349 | break; |
| 1350 | #endif |
| 1351 | case WCMD_MARKERcxx . . $ `external/espeak/synthesize.h:407:9`!: { |
| 1352 | marker_type = q[0] >> 8; |
| 1353 | //TRACE |
| 1354 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"marker ", marker_type, U" ", q [1], U" ", q [2], U" ", q [3]); |
| 1355 | /* |
| 1356 | ppgb: |
| 1357 | These are the possible marker types: |
| 1358 | espeakEVENT_LIST_TERMINATED = 0, // Retrieval mode: terminates the event list. |
| 1359 | espeakEVENT_WORD = 1, // Start of word |
| 1360 | espeakEVENT_SENTENCE = 2, // Start of sentence |
| 1361 | espeakEVENT_MARK = 3, // Mark |
| 1362 | espeakEVENT_PLAY = 4, // Audio element |
| 1363 | espeakEVENT_END = 5, // End of sentence or clause |
| 1364 | espeakEVENT_MSG_TERMINATED = 6, // End of message |
| 1365 | espeakEVENT_PHONEME = 7, // Phoneme, if enabled in espeak_Initialize() |
| 1366 | espeakEVENT_SAMPLERATE = 8 // internal use, set sample rate |
| 1367 | Of these: |
| 1368 | - espeakEVENT_PHONEME takes all 8 bytes of the `string` branch of the union `espeak_EVENT.id` (see `speak_lib.h`), |
| 1369 | which was set in DoPhonemeMarker(). |
| 1370 | - espeakEVENT_WORD |
| 1371 | */ |
| 1372 | /* |
| 1373 | Whether the split version occurs always or only in case of espeakEVENT_PHONEME doesn't seme to matter: |
| 1374 | - here we have only WORD, SENTENCE and PHONEME (also END) |
| 1375 | - WORD seems to set `id.number`, end there we do see a difference if we are on 64-bit big-endian |
| 1376 | - however WORD ignores `id.number` (`id.number is used only by SAMPLE_RATE, which doesn't arrive here) |
| 1377 | - yes, these assumptions are brittle |
| 1378 | - so we repair only if PHONEME, although we sent a pull request to eSpeak to always split |
| 1379 | - the eSpeak version will break as soom as WORD starts to interpret `id.number`. |
| 1380 | */ |
| 1381 | /* |
| 1382 | The incorrect eSpeak version: |
| 1383 | */ |
| 1384 | //MarkerEvent(marker_type, q[1], q[2], q[3], out_ptr); |
| 1385 | /* |
| 1386 | The corrected eSpeak-Praat version: |
| 1387 | */ |
| 1388 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (q[1] >= 0); // check that we are allowed to do a signedness conversion |
| 1389 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (q[1] <= INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!); // check that we are allowed to convert from a 64-bit intptr_t to a 32-bit int |
| 1390 | const unsigned int position = (unsigned int) q[1]; |
| 1391 | if (marker_type == espeakEVENT_PHONEMEcxx . . $ espeakEVENT_PHONEME.) { |
| 1392 | MarkerEvent(marker_type, position, * (int *) & q[2], * ((int *) & q[2] + 1), out_ptrcxx . . $ out_ptr.); |
| 1393 | // ppgb-espeak: split up q [2] into two ints (eSpeak issue #1970, pull request #1973) |
| 1394 | } else if (marker_type == espeakEVENT_SENTENCEcxx . . $ espeakEVENT_SENTENCE.) { |
| 1395 | MarkerEvent(marker_type, position, 12345, 123456, out_ptrcxx . . $ out_ptr.); |
| 1396 | //MarkerEvent(marker_type, position, q[2], q[3], out_ptr); |
| 1397 | //MarkerEvent(marker_type, position, * (int *) & q[2], * ((int *) & q[2] + 1), out_ptr); |
| 1398 | } else if (marker_type == espeakEVENT_WORDcxx . . $ espeakEVENT_WORD.) { |
| 1399 | MarkerEvent(marker_type, position, 1234567, 12345678, out_ptrcxx . . $ out_ptr.); |
| 1400 | //MarkerEvent(marker_type, position, q[2], q[3], out_ptr); |
| 1401 | //MarkerEvent(marker_type, position, * (int *) & q[2], * ((int *) & q[2] + 1), out_ptr); |
| 1402 | } else if (marker_type == espeakEVENT_ENDcxx . . $ espeakEVENT_END.) { |
| 1403 | MarkerEvent(marker_type, position, 123456789, 1234567890, out_ptrcxx . . $ out_ptr.); |
| 1404 | //MarkerEvent(marker_type, position, q[2], q[3], out_ptr); |
| 1405 | //MarkerEvent(marker_type, position, * (int *) & q[2], * ((int *) & q[2] + 1), out_ptr); |
| 1406 | } else { |
| 1407 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"(WavegenFill2:) Uninterpretable marker type ", marker_type); |
| 1408 | } |
| 1409 | break; |
| 1410 | } case WCMD_AMPLITUDEcxx . . $ `external/espeak/synthesize.h:405:9`!: |
| 1411 | SetAmplitudecxx . . $ SetAmplitude(dde21517a502ab05).(length, (unsigned char *)q[2], q[3]); |
| 1412 | break; |
| 1413 | case WCMD_VOICEcxx . . $ `external/espeak/synthesize.h:408:9`!: |
| 1414 | WavegenSetVoicecxx . . $ WavegenSetVoice(d80a4fbed906f5aa).((voice_t *)q[2]); |
| 1415 | freecxx . . $ free(bd21765a0afc8e3c).((voice_t *)q[2]); |
| 1416 | break; |
| 1417 | case WCMD_EMBEDDEDcxx . . $ `external/espeak/synthesize.h:409:9`!: |
| 1418 | SetEmbeddedcxx . . $ SetEmbedded(3e454b8ccf442868).(q[1], q[2]); |
| 1419 | break; |
| 1420 | #if USE_MBROLAcxx . . $ `external/espeak/espeak__config.h:18:9`! |
| 1421 | case WCMD_MBROLA_DATA: |
| 1422 | if (wvoice != NULL) |
| 1423 | result = MbrolaFill(length, resume, (general_amplitude * wvoice->voicing)/64); |
| 1424 | break; |
| 1425 | #endif |
| 1426 | case WCMD_FMT_AMPLITUDEcxx . . $ `external/espeak/synthesize.h:411:9`!: |
| 1427 | if ((wdatacxx . . $ wdata..amplitude_fmt = q[1]) == 0) |
| 1428 | wdatacxx . . $ wdata..amplitude_fmt = 100; // percentage, but value=0 means 100% |
| 1429 | break; |
| 1430 | #if USE_LIBSONIC |
| 1431 | case WCMD_SONIC_SPEED: |
| 1432 | sonicSpeed = (double)q[1] / 1024; |
| 1433 | if (sonicSpeedupStream && (sonicSpeed <= 1.0)) { |
| 1434 | sonicFlushStream(sonicSpeedupStream); |
| 1435 | int length = (out_end - out_ptr); |
| 1436 | length = sonicReadShortFromStream(sonicSpeedupStream, (short*)out_ptr, length/2); |
| 1437 | out_ptr += length * 2; |
| 1438 | } |
| 1439 | break; |
| 1440 | #endif |
| 1441 | } |
| 1442 | |
| 1443 | if (result == 0) { |
| 1444 | WcmdqIncHeadcxx . . $ WcmdqIncHead(49f6e7a06ebc5aa8).(); |
| 1445 | resume = false; |
| 1446 | } else |
| 1447 | resume = true; |
| 1448 | } |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | #if USE_LIBSONIC |
| 1454 | // Speed up the audio samples with libsonic. |
| 1455 | static int SpeedUp(short *outbuf, int length_in, int length_out, int end_of_text) |
| 1456 | { |
| 1457 | if (length_in > 0) { |
| 1458 | if (sonicSpeedupStream == NULL) |
| 1459 | sonicSpeedupStream = sonicCreateStream(22050, 1); |
| 1460 | if (sonicGetSpeed(sonicSpeedupStream) != sonicSpeed) |
| 1461 | sonicSetSpeed(sonicSpeedupStream, sonicSpeed); |
| 1462 | |
| 1463 | sonicWriteShortToStream(sonicSpeedupStream, outbuf, length_in); |
| 1464 | } |
| 1465 | |
| 1466 | if (sonicSpeedupStream == NULL) |
| 1467 | return 0; |
| 1468 | |
| 1469 | if (end_of_text) |
| 1470 | sonicFlushStream(sonicSpeedupStream); |
| 1471 | return sonicReadShortFromStream(sonicSpeedupStream, outbuf, length_out); |
| 1472 | } |
| 1473 | #endif |
| 1474 | |
| 1475 | // Call WavegenFill2, and then speed up the output samples. |
| 1476 | int WavegenFillcxx . . $ WavegenFill(b126dc7c1de90089).(void) |
| 1477 | { |
| 1478 | int finished; |
| 1479 | #if USE_LIBSONIC |
| 1480 | unsigned char *p_start; |
| 1481 | |
| 1482 | p_start = out_ptr; |
| 1483 | #endif |
| 1484 | |
| 1485 | finished = WavegenFill2cxx . . $ WavegenFill2(b126dc7c1de90089).(); |
| 1486 | |
| 1487 | #if USE_LIBSONIC |
| 1488 | if (sonicSpeed > 1.0) { |
| 1489 | int length; |
| 1490 | int max_length; |
| 1491 | |
| 1492 | max_length = (out_end - p_start); |
| 1493 | length = 2*SpeedUp((short *)p_start, (out_ptr-p_start)/2, max_length/2, finished); |
| 1494 | out_ptr = p_start + length; |
| 1495 | |
| 1496 | if (length >= max_length) |
| 1497 | finished = 0; // there may be more data to flush |
| 1498 | } |
| 1499 | #endif |
| 1500 | return finished; |
| 1501 | } |
| 1502 | |
| 1503 | #pragma GCC visibility push(default) |
| 1504 | |
| 1505 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! espeak_ng_STATUS |
| 1506 | espeak_ng_SetOutputHookscxx . . $ espeak_ng_SetOutputHooks(afd959b975ba5726).(espeak_ng_OUTPUT_HOOKS* hooks) |
| 1507 | { |
| 1508 | output_hookscxx . . $ output_hooks. = hooks; |
| 1509 | return static_cast<espeak_ng_STATUS> (0); |
| 1510 | } |
| 1511 | |
| 1512 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! espeak_ng_STATUS |
| 1513 | espeak_ng_SetConstF0cxx . . $ espeak_ng_SetConstF0(15d8a1704e8e46cc).(int f0) |
| 1514 | { |
| 1515 | const_f0cxx . . $ const_f0. = f0; |
| 1516 | return ENS_OK; |
| 1517 | } |
| 1518 | |
| 1519 | #pragma GCC visibility pop |