From 2e713cfff505908d88cee784c4a68e8718e83d1d Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Mon, 23 Feb 2026 21:19:03 +0800 Subject: [PATCH] fixed compile issue, trying out 8bit pcm --- koboldcpp.py | 2 +- otherarch/acestep/ace-qwen3.cpp | 1 + otherarch/tts_adapter.cpp | 42 ------------------ otherarch/utils.cpp | 79 +++++++++++++++++++++++++++++++++ otherarch/utils.h | 36 +++++++++++++++ 5 files changed, 117 insertions(+), 43 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index d95cb5850..f01db1f0d 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -9074,7 +9074,7 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False): print(f"Flags: {benchflagstr}") print(f"Timestamp: {datetimestamp}") print(f"Backend: {libname}") - print(f"Layers: {args.gpulayers}") + print(f"Layers: {args.gpulayers if not args.autofit else 'Autofit'}") print(f"Model: {benchmodel}") print(f"MaxCtx: {benchmaxctx}") print(f"GenAmount: {benchlen}\n-----") diff --git a/otherarch/acestep/ace-qwen3.cpp b/otherarch/acestep/ace-qwen3.cpp index e24af1b43..5c566c09f 100644 --- a/otherarch/acestep/ace-qwen3.cpp +++ b/otherarch/acestep/ace-qwen3.cpp @@ -17,6 +17,7 @@ #include #include #include +#include // Timer struct Timer { diff --git a/otherarch/tts_adapter.cpp b/otherarch/tts_adapter.cpp index c7d26a533..b69419871 100644 --- a/otherarch/tts_adapter.cpp +++ b/otherarch/tts_adapter.cpp @@ -57,48 +57,6 @@ enum TTS_VER TTS_VER_3 }; -struct wav_header { - char riff[4] = {'R', 'I', 'F', 'F'}; - uint32_t chunk_size; - char wave[4] = {'W', 'A', 'V', 'E'}; - char fmt[4] = {'f', 'm', 't', ' '}; - uint32_t fmt_chunk_size = 16; - uint16_t audio_format = 1; // PCM - uint16_t num_channels = 1; // Mono - uint32_t sample_rate; - uint32_t byte_rate; - uint16_t block_align; - uint16_t bits_per_sample = 16; - char data[4] = {'d', 'a', 't', 'a'}; - uint32_t data_size; -}; - - -static std::string save_wav16_base64(const std::vector &data, int sample_rate) { - std::ostringstream oss; - wav_header header; - - // Fill header fields - header.sample_rate = sample_rate; - header.byte_rate = header.sample_rate * header.num_channels * (header.bits_per_sample / 8); - header.block_align = header.num_channels * (header.bits_per_sample / 8); - header.data_size = data.size() * (header.bits_per_sample / 8); - header.chunk_size = 36 + header.data_size; - - // Write header - oss.write(reinterpret_cast(&header), sizeof(header)); - - // Write samples - for (const auto &sample : data) { - int16_t pcm_sample = static_cast(std::clamp(sample * 32767.0, -32768.0, 32767.0)); - oss.write(reinterpret_cast(&pcm_sample), sizeof(pcm_sample)); - } - - // Get binary WAV data - std::string wav_data = oss.str(); - return kcpp_base64_encode(wav_data); //return as base64 string -} - static void fill_hann_window(int length, bool periodic, float * output) { int offset = -1; if (periodic) { diff --git a/otherarch/utils.cpp b/otherarch/utils.cpp index df73f8e83..e311c7e90 100644 --- a/otherarch/utils.cpp +++ b/otherarch/utils.cpp @@ -389,6 +389,85 @@ std::vector resample_wav(const std::vector& input, uint32_t input_ return output; } +static uint8_t linear_to_mulaw(int16_t sample) +{ + const int16_t BIAS = 0x84; // 132 + const int16_t CLIP = 32635; + + int16_t sign = (sample >> 8) & 0x80; + if (sign) + sample = -sample; + + if (sample > CLIP) + sample = CLIP; + + sample += BIAS; + + int16_t exponent = 7; + for (int16_t expMask = 0x4000; + (sample & expMask) == 0 && exponent > 0; + exponent--, expMask >>= 1); + + int16_t mantissa = (sample >> (exponent + 3)) & 0x0F; + + uint8_t ulaw = ~(sign | (exponent << 4) | mantissa); + return ulaw; +} + +std::string save_ulaw_wav8_base64(const std::vector &data, int sample_rate) +{ + std::ostringstream oss; + wav_ulaw_header header; + + header.sample_rate = sample_rate; + header.byte_rate = sample_rate; // 1 byte per sample (mono) + header.block_align = 1; + header.data_size = static_cast(data.size()); + header.chunk_size = 4 // "WAVE" + + 8 + header.fmt_chunk_size + + 8 + header.data_size; + + // Write header + oss.write(reinterpret_cast(&header), sizeof(header)); + + // Convert and write samples + for (float s : data) + { + float clamped = std::clamp(s, -1.0f, 1.0f); + int16_t pcm = static_cast(clamped * 32767.0f); + uint8_t mu = linear_to_mulaw(pcm); + oss.write(reinterpret_cast(&mu), 1); + } + + std::string wav_data = oss.str(); + return kcpp_base64_encode(wav_data); +} + +std::string save_wav16_base64(const std::vector &data, int sample_rate) { + std::ostringstream oss; + wav16_header header; + + // Fill header fields + header.sample_rate = sample_rate; + header.byte_rate = header.sample_rate * header.num_channels * (header.bits_per_sample / 8); + header.block_align = header.num_channels * (header.bits_per_sample / 8); + header.data_size = data.size() * (header.bits_per_sample / 8); + header.chunk_size = 36 + header.data_size; + + // Write header + oss.write(reinterpret_cast(&header), sizeof(header)); + + // Write samples + for (const auto &sample : data) { + int16_t pcm_sample = static_cast(std::clamp(sample * 32767.0, -32768.0, 32767.0)); + oss.write(reinterpret_cast(&pcm_sample), sizeof(pcm_sample)); + } + + // Get binary WAV data + std::string wav_data = oss.str(); + return kcpp_base64_encode(wav_data); //return as base64 string +} + //a very rudimentary all in one sampling function which has no dependencies int32_t kcpp_quick_sample(float * logits, const int n_logits, const std::vector & last_n_tokens, float rep_pen, float top_p, int top_k, float temp, std::mt19937 & rng) { diff --git a/otherarch/utils.h b/otherarch/utils.h index 0309c9840..cdd86e7ad 100644 --- a/otherarch/utils.h +++ b/otherarch/utils.h @@ -116,3 +116,39 @@ private: int img_ny ); }; + +struct wav16_header { + char riff[4] = {'R', 'I', 'F', 'F'}; + uint32_t chunk_size; + char wave[4] = {'W', 'A', 'V', 'E'}; + char fmt[4] = {'f', 'm', 't', ' '}; + uint32_t fmt_chunk_size = 16; + uint16_t audio_format = 1; // PCM + uint16_t num_channels = 1; // Mono + uint32_t sample_rate; + uint32_t byte_rate; + uint16_t block_align; + uint16_t bits_per_sample = 16; + char data[4] = {'d', 'a', 't', 'a'}; + uint32_t data_size; +}; + +struct wav_ulaw_header { + char riff[4] = {'R','I','F','F'}; + uint32_t chunk_size; // 36 + data_size + 2 (for cbSize) + char wave[4] = {'W','A','V','E'}; + char fmt[4] = {'f','m','t',' '}; + uint32_t fmt_chunk_size = 18; // 18 for non-PCM + uint16_t audio_format = 7; // 7 = μ-law + uint16_t num_channels = 1; // mono + uint32_t sample_rate; + uint32_t byte_rate; // sample_rate * channels * 1 + uint16_t block_align; // channels * 1 + uint16_t bits_per_sample = 8; // 8-bit μ-law + uint16_t cbSize = 0; // required for non-PCM + char data[4] = {'d','a','t','a'}; + uint32_t data_size; +}; + +std::string save_ulaw_wav8_base64(const std::vector &data, int sample_rate); +std::string save_wav16_base64(const std::vector &data, int sample_rate); \ No newline at end of file