cohere-transcribe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE.txt +201 -0
- data/NOTICE +5 -0
- data/README.md +265 -0
- data/THIRD_PARTY_NOTICES.md +67 -0
- data/exe/cohere-transcribe +8 -0
- data/exe/cohere-transcribe-doctor +8 -0
- data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
- data/ext/cohere_transcribe_native/README.md +26 -0
- data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
- data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
- data/ext/cohere_transcribe_native/audio_exports.map +10 -0
- data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
- data/ext/cohere_transcribe_native/exports.macos +40 -0
- data/ext/cohere_transcribe_native/exports.map +45 -0
- data/ext/cohere_transcribe_native/extconf.rb +89 -0
- data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
- data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
- data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
- data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
- data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
- data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
- data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
- data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
- data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
- data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
- data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
- data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
- data/lib/cohere/transcribe/alignment/text.rb +237 -0
- data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
- data/lib/cohere/transcribe/api.rb +173 -0
- data/lib/cohere/transcribe/asr/batching.rb +472 -0
- data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
- data/lib/cohere/transcribe/asr/native.rb +676 -0
- data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
- data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
- data/lib/cohere/transcribe/audio/decoder.rb +315 -0
- data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
- data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
- data/lib/cohere/transcribe/cli.rb +727 -0
- data/lib/cohere/transcribe/configuration.rb +282 -0
- data/lib/cohere/transcribe/constants.rb +14 -0
- data/lib/cohere/transcribe/dense_converter.rb +548 -0
- data/lib/cohere/transcribe/doctor.rb +576 -0
- data/lib/cohere/transcribe/errors.rb +57 -0
- data/lib/cohere/transcribe/gguf_writer.rb +268 -0
- data/lib/cohere/transcribe/hub.rb +436 -0
- data/lib/cohere/transcribe/input.rb +110 -0
- data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
- data/lib/cohere/transcribe/loader.rb +128 -0
- data/lib/cohere/transcribe/model_identity.rb +440 -0
- data/lib/cohere/transcribe/output/publication.rb +1118 -0
- data/lib/cohere/transcribe/output/rendering.rb +105 -0
- data/lib/cohere/transcribe/output/timing.rb +86 -0
- data/lib/cohere/transcribe/python_text.rb +70 -0
- data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
- data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
- data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
- data/lib/cohere/transcribe/runtime/precision.rb +57 -0
- data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
- data/lib/cohere/transcribe/runtime/resources.rb +165 -0
- data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
- data/lib/cohere/transcribe/safetensors.rb +579 -0
- data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
- data/lib/cohere/transcribe/state/contracts.rb +141 -0
- data/lib/cohere/transcribe/state/io.rb +727 -0
- data/lib/cohere/transcribe/state/locking.rb +211 -0
- data/lib/cohere/transcribe/state/manifest.rb +155 -0
- data/lib/cohere/transcribe/state.rb +7 -0
- data/lib/cohere/transcribe/types.rb +535 -0
- data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
- data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
- data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
- data/lib/cohere/transcribe/vad/silero.rb +344 -0
- data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
- data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
- data/lib/cohere/transcribe/version.rb +7 -0
- data/lib/cohere/transcribe.rb +26 -0
- data/sig/cohere/transcribe.rbs +250 -0
- data/vendor/crispasr/AUTHORS +510 -0
- data/vendor/crispasr/LICENSE +21 -0
- data/vendor/crispasr/UPSTREAM.md +9 -0
- data/vendor/crispasr/VERSION +1 -0
- data/vendor/crispasr/ggml/AUTHORS +335 -0
- data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
- data/vendor/crispasr/ggml/LICENSE +21 -0
- data/vendor/crispasr/ggml/README.md +49 -0
- data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
- data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/crispasr/ggml/ggml.pc.in +10 -0
- data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
- data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
- data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
- data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
- data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
- data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
- data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
- data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
- data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
- data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
- data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
- data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
- data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
- data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/crispasr/ggml/include/ggml.h +2887 -0
- data/vendor/crispasr/ggml/include/gguf.h +204 -0
- data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
- data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
- data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
- data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
- data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
- data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
- data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
- data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
- data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
- data/vendor/crispasr/ggml/src/ggml.c +7925 -0
- data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
- data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
- data/vendor/crispasr/src/cohere-arch.h +137 -0
- data/vendor/crispasr/src/cohere.cpp +5642 -0
- data/vendor/crispasr/src/cohere.h +327 -0
- data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
- data/vendor/crispasr/src/cohere_chunking.h +64 -0
- data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
- data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
- data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
- data/vendor/crispasr/src/cohere_frontend.h +31 -0
- data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
- data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
- data/vendor/crispasr/src/core/attention.h +924 -0
- data/vendor/crispasr/src/core/audio_chunking.h +97 -0
- data/vendor/crispasr/src/core/beam_decode.h +486 -0
- data/vendor/crispasr/src/core/cpu_ops.h +135 -0
- data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
- data/vendor/crispasr/src/core/gguf_loader.h +216 -0
- data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
- data/vendor/crispasr/src/core/mel.cpp +519 -0
- data/vendor/crispasr/src/core/mel.h +265 -0
- data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
- data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
- data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
- data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
- metadata +596 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
// src/core/mel.cpp — implementation of compute_log_mel().
|
|
2
|
+
// See src/core/mel.h for the interface contract.
|
|
3
|
+
|
|
4
|
+
#include "mel.h"
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <chrono>
|
|
8
|
+
#include <cmath>
|
|
9
|
+
#include <cstdio>
|
|
10
|
+
#include <cstdlib>
|
|
11
|
+
#include <cstring>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
#if defined(HAVE_BLAS)
|
|
15
|
+
#if defined(__APPLE__)
|
|
16
|
+
#include <Accelerate/Accelerate.h>
|
|
17
|
+
#else
|
|
18
|
+
#include <cblas.h>
|
|
19
|
+
#endif
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
#ifdef _OPENMP
|
|
23
|
+
#include <omp.h>
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace core_mel {
|
|
27
|
+
|
|
28
|
+
std::vector<float> compute(const float* samples, int n_samples, const float* window_in, int win_length,
|
|
29
|
+
const float* mel_fb, int n_freqs, FftR2C fft, const Params& p, int& T_out) {
|
|
30
|
+
const int n_fft = p.n_fft;
|
|
31
|
+
const int hop = p.hop_length;
|
|
32
|
+
const int nmels = p.n_mels;
|
|
33
|
+
const auto t_mel0 = std::chrono::steady_clock::now();
|
|
34
|
+
|
|
35
|
+
// -----------------------------------------------------------------
|
|
36
|
+
// 1a. Optional pre-emphasis: y[0] = x[0]; y[i] = x[i] - α*x[i-1].
|
|
37
|
+
// NeMo applies this to the raw input before center-padding,
|
|
38
|
+
// so the high-pass filter sees the true first sample (not the
|
|
39
|
+
// zero pad) — see NeMo FilterbankFeatures.forward.
|
|
40
|
+
// -----------------------------------------------------------------
|
|
41
|
+
std::vector<float> preemph_in;
|
|
42
|
+
const float* base_ptr = samples;
|
|
43
|
+
if (p.preemph != 0.0f && n_samples > 0) {
|
|
44
|
+
preemph_in.resize((size_t)n_samples);
|
|
45
|
+
preemph_in[0] = samples[0];
|
|
46
|
+
const float a = p.preemph;
|
|
47
|
+
for (int i = 1; i < n_samples; i++)
|
|
48
|
+
preemph_in[i] = samples[i] - a * samples[i - 1];
|
|
49
|
+
base_ptr = preemph_in.data();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// -----------------------------------------------------------------
|
|
53
|
+
// 1b. Optional center-pad of the input by n_fft/2 on each side.
|
|
54
|
+
// -----------------------------------------------------------------
|
|
55
|
+
std::vector<float> padded_in;
|
|
56
|
+
const float* in_ptr;
|
|
57
|
+
int in_len;
|
|
58
|
+
if (p.center_pad) {
|
|
59
|
+
const int pad = n_fft / 2;
|
|
60
|
+
padded_in.assign((size_t)(pad + n_samples + pad), 0.0f);
|
|
61
|
+
std::memcpy(padded_in.data() + pad, base_ptr, (size_t)n_samples * sizeof(float));
|
|
62
|
+
if (p.center_pad_reflect) {
|
|
63
|
+
// Reflect-pad matching PyTorch's torch.nn.functional.pad(x, (pad, pad), "reflect").
|
|
64
|
+
// Left: padded[pad-1-i] = base_ptr[i+1] for i in [0, pad)
|
|
65
|
+
for (int i = 0; i < pad; i++) {
|
|
66
|
+
int src = (i + 1) < n_samples ? (i + 1) : n_samples - 1;
|
|
67
|
+
padded_in[pad - 1 - i] = base_ptr[src];
|
|
68
|
+
}
|
|
69
|
+
// Right: padded[pad+n_samples+i] = base_ptr[n_samples-2-i] for i in [0, pad)
|
|
70
|
+
for (int i = 0; i < pad; i++) {
|
|
71
|
+
int src = (n_samples - 2 - i) >= 0 ? (n_samples - 2 - i) : 0;
|
|
72
|
+
padded_in[pad + n_samples + i] = base_ptr[src];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// else: zero-pad (padded_in already zero-initialized via resize)
|
|
76
|
+
in_ptr = padded_in.data();
|
|
77
|
+
in_len = (int)padded_in.size();
|
|
78
|
+
} else {
|
|
79
|
+
in_ptr = base_ptr;
|
|
80
|
+
in_len = n_samples;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// -----------------------------------------------------------------
|
|
84
|
+
// 2. Build the STFT window, center-padded to n_fft if win_length is
|
|
85
|
+
// shorter. NeMo cluster stores a win_length-sized window; the
|
|
86
|
+
// HF cluster stores it already padded to n_fft. Both work: the
|
|
87
|
+
// center-pad is a no-op when win_length == n_fft.
|
|
88
|
+
// -----------------------------------------------------------------
|
|
89
|
+
std::vector<float> window(n_fft, 0.0f);
|
|
90
|
+
{
|
|
91
|
+
const int lpad = (n_fft - win_length) / 2;
|
|
92
|
+
const int wn = std::min(win_length, n_fft);
|
|
93
|
+
for (int i = 0; i < wn; i++)
|
|
94
|
+
window[lpad + i] = window_in[i];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// -----------------------------------------------------------------
|
|
98
|
+
// 3. STFT → power spectrum (stored [T, n_freqs] row-major).
|
|
99
|
+
// -----------------------------------------------------------------
|
|
100
|
+
int T = in_len >= n_fft ? (in_len - n_fft) / hop + 1 : 0;
|
|
101
|
+
if (p.drop_last_frame && T > 0)
|
|
102
|
+
T -= 1;
|
|
103
|
+
// Optional even-T guarantee: when the remaining frame count is odd,
|
|
104
|
+
// shift the window start by one hop to produce an even T. This is
|
|
105
|
+
// what voxtral4b needs (it feeds the mel into a stride-2 conv).
|
|
106
|
+
int t_start = 0;
|
|
107
|
+
if (p.drop_first_frame_if_odd && T > 0 && (T % 2 != 0)) {
|
|
108
|
+
T -= 1;
|
|
109
|
+
t_start = 1;
|
|
110
|
+
}
|
|
111
|
+
if (T <= 0) {
|
|
112
|
+
T_out = 0;
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const bool mel_timing = (std::getenv("CRISPASR_MEL_TIMING") != nullptr);
|
|
117
|
+
const bool env_parallel = (std::getenv("CRISPASR_MEL_PARALLEL") != nullptr);
|
|
118
|
+
const bool parallel_stft = env_parallel || p.allow_parallel || p.allow_parallel_stft;
|
|
119
|
+
const bool parallel_outer = env_parallel || p.allow_parallel;
|
|
120
|
+
#ifdef _OPENMP
|
|
121
|
+
const int parallel_threads = p.parallel_threads > 0 ? p.parallel_threads : omp_get_max_threads();
|
|
122
|
+
#endif
|
|
123
|
+
// §176f: OpenMP-parallel STFT. Each frame's window-multiply + FFT + power
|
|
124
|
+
// write touches only its own [t] row of `power` and thread-private scratch,
|
|
125
|
+
// so the loop is data-race free and bit-identical to the serial path. It is
|
|
126
|
+
// OPT-IN (CRISPASR_MEL_PARALLEL=1, default serial) because the `fft` callable
|
|
127
|
+
// is supplied per backend (cohere_fft_r2c, glm_fft, voxtral_fft_wrapper, …)
|
|
128
|
+
// and the parallel path is only safe when that callable is re-entrant. Flip
|
|
129
|
+
// a backend to parallel-by-default once its fft is confirmed thread-safe
|
|
130
|
+
// (audit: see Params::allow_parallel_stft) AND benched faster on the arch.
|
|
131
|
+
// Measured (cohere, M1, 8 cores): warm STFT ~2.4× (43→18 ms / 800 frames).
|
|
132
|
+
// Enabled by the global env var OR either per-backend Params flag.
|
|
133
|
+
const auto t_stft0 = std::chrono::steady_clock::now();
|
|
134
|
+
bool ran_parallel = false;
|
|
135
|
+
|
|
136
|
+
std::vector<float> power((size_t)T * n_freqs, 0.0f);
|
|
137
|
+
{
|
|
138
|
+
const bool use_magnitude = (p.spec_kind == SpecKind::Magnitude);
|
|
139
|
+
auto compute_frame = [&](int t, float* fft_in, float* fft_out) {
|
|
140
|
+
const float* frame = in_ptr + (size_t)(t + t_start) * hop;
|
|
141
|
+
for (int n = 0; n < n_fft; n++)
|
|
142
|
+
fft_in[n] = frame[n] * window[n];
|
|
143
|
+
fft(fft_in, n_fft, fft_out);
|
|
144
|
+
for (int k = 0; k < n_freqs; k++) {
|
|
145
|
+
const float re = fft_out[2 * k];
|
|
146
|
+
const float im = fft_out[2 * k + 1];
|
|
147
|
+
const float pw = re * re + im * im;
|
|
148
|
+
power[(size_t)t * n_freqs + k] = use_magnitude ? std::sqrt(pw) : pw;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
#ifdef _OPENMP
|
|
152
|
+
// Threshold: below ~256 frames (≈2.5 s at 100 fps) thread-spawn overhead
|
|
153
|
+
// dominates the handful of FFTs, so stay serial regardless of the flag.
|
|
154
|
+
if (parallel_stft && T >= 256) {
|
|
155
|
+
ran_parallel = true;
|
|
156
|
+
#pragma omp parallel num_threads(parallel_threads)
|
|
157
|
+
{
|
|
158
|
+
std::vector<float> fft_in((size_t)n_fft);
|
|
159
|
+
std::vector<float> fft_out((size_t)n_fft * 2);
|
|
160
|
+
#pragma omp for schedule(static)
|
|
161
|
+
for (int t = 0; t < T; t++)
|
|
162
|
+
compute_frame(t, fft_in.data(), fft_out.data());
|
|
163
|
+
}
|
|
164
|
+
} else
|
|
165
|
+
#endif
|
|
166
|
+
{
|
|
167
|
+
std::vector<float> fft_in((size_t)n_fft);
|
|
168
|
+
std::vector<float> fft_out((size_t)n_fft * 2);
|
|
169
|
+
for (int t = 0; t < T; t++)
|
|
170
|
+
compute_frame(t, fft_in.data(), fft_out.data());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (mel_timing) {
|
|
175
|
+
const double stft_ms =
|
|
176
|
+
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t_stft0).count();
|
|
177
|
+
int nthreads = 1;
|
|
178
|
+
#ifdef _OPENMP
|
|
179
|
+
if (ran_parallel)
|
|
180
|
+
nthreads = omp_get_max_threads();
|
|
181
|
+
#endif
|
|
182
|
+
fprintf(stderr, "core_mel: STFT %d frames (n_fft=%d) %.2f ms [%d thread(s)%s]\n", T, n_fft, stft_ms, nthreads,
|
|
183
|
+
ran_parallel ? "" : ", serial");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// -----------------------------------------------------------------
|
|
187
|
+
// 4. Mel projection: mel[t, m] = sum_k power[t, k] * fb[m, k]
|
|
188
|
+
// (or fb[k, m] if fb_layout == FreqsMels).
|
|
189
|
+
// Two accumulator precisions.
|
|
190
|
+
// -----------------------------------------------------------------
|
|
191
|
+
const auto t_projection0 = std::chrono::steady_clock::now();
|
|
192
|
+
bool ran_parallel_projection = false;
|
|
193
|
+
std::vector<float> mel_tn((size_t)T * nmels, 0.0f);
|
|
194
|
+
|
|
195
|
+
auto do_matmul = [&](auto acc_zero) {
|
|
196
|
+
using Acc = decltype(acc_zero);
|
|
197
|
+
auto project_frame = [&](int t) {
|
|
198
|
+
const float* pp = power.data() + (size_t)t * n_freqs;
|
|
199
|
+
float* mp = mel_tn.data() + (size_t)t * nmels;
|
|
200
|
+
for (int m = 0; m < nmels; m++) {
|
|
201
|
+
Acc s = 0;
|
|
202
|
+
if (p.fb_layout == FbLayout::MelsFreqs) {
|
|
203
|
+
const float* fb = mel_fb + (size_t)m * n_freqs;
|
|
204
|
+
for (int k = 0; k < n_freqs; k++) {
|
|
205
|
+
s += static_cast<Acc>(pp[k]) * static_cast<Acc>(fb[k]);
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
for (int k = 0; k < n_freqs; k++) {
|
|
209
|
+
s += static_cast<Acc>(pp[k]) * static_cast<Acc>(mel_fb[(size_t)k * nmels + m]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
mp[m] = (float)s;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
#ifdef _OPENMP
|
|
216
|
+
if (parallel_outer && T >= 256) {
|
|
217
|
+
ran_parallel_projection = true;
|
|
218
|
+
#pragma omp parallel for schedule(static) num_threads(parallel_threads)
|
|
219
|
+
for (int t = 0; t < T; t++)
|
|
220
|
+
project_frame(t);
|
|
221
|
+
} else
|
|
222
|
+
#endif
|
|
223
|
+
{
|
|
224
|
+
for (int t = 0; t < T; t++)
|
|
225
|
+
project_frame(t);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
if (p.matmul == MatmulPrecision::Double) {
|
|
229
|
+
do_matmul(double{0});
|
|
230
|
+
} else {
|
|
231
|
+
#if defined(HAVE_BLAS)
|
|
232
|
+
if (p.fb_layout == FbLayout::MelsFreqs) {
|
|
233
|
+
// mel[T, nmels] = power[T, n_freqs] × mel_fb^T[n_freqs, nmels]
|
|
234
|
+
// mel_fb is row-major (nmels, n_freqs); CblasTrans transposes for the multiply.
|
|
235
|
+
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, T, nmels, n_freqs, 1.0f, power.data(), n_freqs, mel_fb,
|
|
236
|
+
n_freqs, 0.0f, mel_tn.data(), nmels);
|
|
237
|
+
} else {
|
|
238
|
+
// FreqsMels: mel_fb is (n_freqs, nmels); mel = power × mel_fb (no transpose).
|
|
239
|
+
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, T, nmels, n_freqs, 1.0f, power.data(), n_freqs,
|
|
240
|
+
mel_fb, nmels, 0.0f, mel_tn.data(), nmels);
|
|
241
|
+
}
|
|
242
|
+
#else
|
|
243
|
+
do_matmul(float{0.0f});
|
|
244
|
+
#endif
|
|
245
|
+
}
|
|
246
|
+
const auto t_projection1 = std::chrono::steady_clock::now();
|
|
247
|
+
|
|
248
|
+
// -----------------------------------------------------------------
|
|
249
|
+
// 5. log with guard (no-op when log_base == None)
|
|
250
|
+
// -----------------------------------------------------------------
|
|
251
|
+
auto apply_log = [&](float v) -> float {
|
|
252
|
+
if (p.log_base == LogBase::None) {
|
|
253
|
+
// Skip log entirely; let the rest of the pipeline see the raw
|
|
254
|
+
// mel-projected spectrum. Used by the Resemble VoiceEncoder
|
|
255
|
+
// (mel_type='amp').
|
|
256
|
+
return v;
|
|
257
|
+
}
|
|
258
|
+
if (p.log_guard == LogGuard::MaxClip) {
|
|
259
|
+
if (v < p.log_eps)
|
|
260
|
+
v = p.log_eps;
|
|
261
|
+
return (p.log_base == LogBase::Log10) ? std::log10(v) : std::log(v);
|
|
262
|
+
} else { // AddEpsilon
|
|
263
|
+
const float vv = v + p.log_eps;
|
|
264
|
+
return (p.log_base == LogBase::Log10) ? std::log10(vv) : std::log(vv);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
if (p.log_base != LogBase::None) {
|
|
268
|
+
for (size_t i = 0; i < mel_tn.size(); i++) {
|
|
269
|
+
mel_tn[i] = apply_log(mel_tn[i]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// -----------------------------------------------------------------
|
|
274
|
+
// 6. Optional right-pad in LOG space with log_guard(0).
|
|
275
|
+
// Padding here (before normalization) lets the padded frames
|
|
276
|
+
// participate correctly in the GlobalClipMax mean/max step.
|
|
277
|
+
// Voxtral relies on this.
|
|
278
|
+
// -----------------------------------------------------------------
|
|
279
|
+
const int T_final = (p.pad_to_T > 0 && p.pad_to_T > T) ? p.pad_to_T : T;
|
|
280
|
+
|
|
281
|
+
if (T_final > T) {
|
|
282
|
+
const float pad_val = apply_log(0.0f);
|
|
283
|
+
std::vector<float> ext((size_t)T_final * nmels, 0.0f);
|
|
284
|
+
// Copy existing [T, n_mels] into leading [T, n_mels] slot.
|
|
285
|
+
std::memcpy(ext.data(), mel_tn.data(), (size_t)T * nmels * sizeof(float));
|
|
286
|
+
// Fill trailing frames with pad_val.
|
|
287
|
+
for (int t = T; t < T_final; t++) {
|
|
288
|
+
for (int m = 0; m < nmels; m++)
|
|
289
|
+
ext[(size_t)t * nmels + m] = pad_val;
|
|
290
|
+
}
|
|
291
|
+
mel_tn = std::move(ext);
|
|
292
|
+
}
|
|
293
|
+
T_out = T_final;
|
|
294
|
+
|
|
295
|
+
// -----------------------------------------------------------------
|
|
296
|
+
// 7. Normalization
|
|
297
|
+
// -----------------------------------------------------------------
|
|
298
|
+
const auto t_normalization0 = std::chrono::steady_clock::now();
|
|
299
|
+
bool ran_parallel_normalization = false;
|
|
300
|
+
switch (p.norm) {
|
|
301
|
+
case Normalization::PerFeatureZ: {
|
|
302
|
+
// Per-mel band z-score across time. Matches NeMo
|
|
303
|
+
// FilterbankFeatures.normalize_batch("per_feature"):
|
|
304
|
+
// var = sum_sq / (T - 1) # Bessel-corrected sample variance
|
|
305
|
+
// std = sqrt(var); std = 0 if NaN # NaN guard for T == 1
|
|
306
|
+
// std += 1e-5 # eps on std, OUTSIDE the sqrt
|
|
307
|
+
// y = (x - mean) / std
|
|
308
|
+
// The placement of eps matters on low-variance mel bands
|
|
309
|
+
// (silence / high-freq during quiet speech). Adding it inside the
|
|
310
|
+
// sqrt under-amplifies those bands relative to NeMo, which can
|
|
311
|
+
// shift downstream encoder activations enough to cause TDT token
|
|
312
|
+
// deletions on conversational JA audio (issue #37).
|
|
313
|
+
const int denom = (T_final > 1) ? (T_final - 1) : 1;
|
|
314
|
+
auto normalize_band = [&](int m) {
|
|
315
|
+
double sum = 0.0, sq = 0.0;
|
|
316
|
+
for (int t = 0; t < T_final; t++)
|
|
317
|
+
sum += mel_tn[(size_t)t * nmels + m];
|
|
318
|
+
const double mean = sum / T_final;
|
|
319
|
+
for (int t = 0; t < T_final; t++) {
|
|
320
|
+
const double d = mel_tn[(size_t)t * nmels + m] - mean;
|
|
321
|
+
sq += d * d;
|
|
322
|
+
}
|
|
323
|
+
float std_val = std::sqrt((float)(sq / denom));
|
|
324
|
+
if (!(std_val == std_val))
|
|
325
|
+
std_val = 0.0f;
|
|
326
|
+
std_val += 1e-5f;
|
|
327
|
+
const float inv_std = 1.0f / std_val;
|
|
328
|
+
for (int t = 0; t < T_final; t++) {
|
|
329
|
+
mel_tn[(size_t)t * nmels + m] = (float)(mel_tn[(size_t)t * nmels + m] - mean) * inv_std;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
#ifdef _OPENMP
|
|
333
|
+
if (parallel_outer && T_final >= 256 && nmels >= 16) {
|
|
334
|
+
ran_parallel_normalization = true;
|
|
335
|
+
#pragma omp parallel for schedule(static) num_threads(parallel_threads)
|
|
336
|
+
for (int m = 0; m < nmels; m++)
|
|
337
|
+
normalize_band(m);
|
|
338
|
+
} else
|
|
339
|
+
#endif
|
|
340
|
+
{
|
|
341
|
+
for (int m = 0; m < nmels; m++)
|
|
342
|
+
normalize_band(m);
|
|
343
|
+
}
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case Normalization::GlobalClipMax: {
|
|
347
|
+
float mx = -1e30f;
|
|
348
|
+
for (size_t i = 0; i < mel_tn.size(); i++)
|
|
349
|
+
if (mel_tn[i] > mx)
|
|
350
|
+
mx = mel_tn[i];
|
|
351
|
+
const float floor_v = mx - 8.0f;
|
|
352
|
+
for (size_t i = 0; i < mel_tn.size(); i++) {
|
|
353
|
+
float v = mel_tn[i];
|
|
354
|
+
if (v < floor_v)
|
|
355
|
+
v = floor_v;
|
|
356
|
+
mel_tn[i] = (v + 4.0f) / 4.0f;
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case Normalization::GlobalClipFixed: {
|
|
361
|
+
const float floor_v = p.fixed_max - 8.0f;
|
|
362
|
+
for (size_t i = 0; i < mel_tn.size(); i++) {
|
|
363
|
+
float v = mel_tn[i];
|
|
364
|
+
if (v < floor_v)
|
|
365
|
+
v = floor_v;
|
|
366
|
+
mel_tn[i] = (v + 4.0f) / 4.0f;
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case Normalization::None:
|
|
371
|
+
// Raw log-mel — no post-log normalization. Gemma4 uses this.
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
const auto t_normalization1 = std::chrono::steady_clock::now();
|
|
375
|
+
|
|
376
|
+
// -----------------------------------------------------------------
|
|
377
|
+
// 8. Optional frame stacking (TimeMels only).
|
|
378
|
+
// Collapses `stacked_frames` consecutive rows into one wider row.
|
|
379
|
+
// Because mel_tn is already row-major [T_final, n_mels] and the
|
|
380
|
+
// output layout keeps rows contiguous, stacking is a pure memory
|
|
381
|
+
// reinterpret: drop any trailing frames that don't fill a full
|
|
382
|
+
// group, then pretend the buffer is [T_final / s, n_mels * s].
|
|
383
|
+
// -----------------------------------------------------------------
|
|
384
|
+
if (p.stacked_frames > 1 && p.layout == Layout::TimeMels) {
|
|
385
|
+
const int s = p.stacked_frames;
|
|
386
|
+
const int T_stacked = T_final / s;
|
|
387
|
+
if (T_stacked > 0) {
|
|
388
|
+
mel_tn.resize((size_t)T_stacked * s * nmels);
|
|
389
|
+
} else {
|
|
390
|
+
mel_tn.clear();
|
|
391
|
+
}
|
|
392
|
+
T_out = T_stacked;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// -----------------------------------------------------------------
|
|
396
|
+
// 9. Output layout
|
|
397
|
+
// -----------------------------------------------------------------
|
|
398
|
+
std::vector<float> out;
|
|
399
|
+
if (p.layout == Layout::MelsTime) {
|
|
400
|
+
// Transpose to (n_mels, T_final) row-major.
|
|
401
|
+
out.assign((size_t)nmels * T_final, 0.0f);
|
|
402
|
+
for (int t = 0; t < T_final; t++) {
|
|
403
|
+
for (int m = 0; m < nmels; m++) {
|
|
404
|
+
out[(size_t)m * T_final + t] = mel_tn[(size_t)t * nmels + m];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (mel_timing) {
|
|
410
|
+
const auto t_mel1 = std::chrono::steady_clock::now();
|
|
411
|
+
const double projection_ms = std::chrono::duration<double, std::milli>(t_projection1 - t_projection0).count();
|
|
412
|
+
const double normalization_ms =
|
|
413
|
+
std::chrono::duration<double, std::milli>(t_normalization1 - t_normalization0).count();
|
|
414
|
+
const double total_ms = std::chrono::duration<double, std::milli>(t_mel1 - t_mel0).count();
|
|
415
|
+
fprintf(stderr, "core_mel: projection %.2f ms [%s]\n", projection_ms,
|
|
416
|
+
ran_parallel_projection ? "parallel" : "serial/BLAS");
|
|
417
|
+
fprintf(stderr, "core_mel: normalization %.2f ms [%s]\n", normalization_ms,
|
|
418
|
+
ran_parallel_normalization ? "parallel" : "serial");
|
|
419
|
+
fprintf(stderr, "core_mel: total %.2f ms\n", total_ms);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (p.layout == Layout::TimeMels)
|
|
423
|
+
return mel_tn;
|
|
424
|
+
return out;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
std::vector<float> build_htk_fb(int sr, int n_fft, int n_mels, float fmin, float fmax, FbLayout layout) {
|
|
428
|
+
const int n_freqs = n_fft / 2 + 1;
|
|
429
|
+
if (fmax <= 0.0f)
|
|
430
|
+
fmax = (float)sr * 0.5f;
|
|
431
|
+
auto hz2mel = [](float hz) { return 2595.0f * std::log10(1.0f + hz / 700.0f); };
|
|
432
|
+
auto mel2hz = [](float m) { return 700.0f * (std::pow(10.0f, m / 2595.0f) - 1.0f); };
|
|
433
|
+
const float ml = hz2mel(fmin);
|
|
434
|
+
const float mh = hz2mel(fmax);
|
|
435
|
+
std::vector<float> centers((size_t)n_mels + 2);
|
|
436
|
+
for (int i = 0; i < n_mels + 2; i++)
|
|
437
|
+
centers[i] = mel2hz(ml + (mh - ml) * (float)i / (float)(n_mels + 1));
|
|
438
|
+
|
|
439
|
+
std::vector<float> fb((size_t)n_mels * n_freqs, 0.0f);
|
|
440
|
+
for (int m = 0; m < n_mels; m++) {
|
|
441
|
+
const float lo = centers[m];
|
|
442
|
+
const float md = centers[m + 1];
|
|
443
|
+
const float hi = centers[m + 2];
|
|
444
|
+
for (int k = 0; k < n_freqs; k++) {
|
|
445
|
+
const float f = (float)k * (float)sr / (float)n_fft;
|
|
446
|
+
float w = 0.0f;
|
|
447
|
+
if (f >= lo && f <= md && md > lo)
|
|
448
|
+
w = (f - lo) / (md - lo);
|
|
449
|
+
else if (f >= md && f <= hi && hi > md)
|
|
450
|
+
w = (hi - f) / (hi - md);
|
|
451
|
+
if (w < 0.0f)
|
|
452
|
+
w = 0.0f;
|
|
453
|
+
if (layout == FbLayout::MelsFreqs)
|
|
454
|
+
fb[(size_t)m * n_freqs + k] = w;
|
|
455
|
+
else
|
|
456
|
+
fb[(size_t)k * n_mels + m] = w;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return fb;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
std::vector<float> build_slaney_fb(int sr, int n_fft, int n_mels, float fmin, float fmax, FbLayout layout) {
|
|
463
|
+
const int n_freqs = n_fft / 2 + 1;
|
|
464
|
+
if (fmax <= 0.0f)
|
|
465
|
+
fmax = (float)sr * 0.5f;
|
|
466
|
+
|
|
467
|
+
// Slaney mel scale: linear below 1 kHz at f_sp = 200/3 Hz/mel, log
|
|
468
|
+
// above 1 kHz with logstep = ln(6.4)/27. Matches librosa's
|
|
469
|
+
// `mel_to_hz(..., htk=False)` exactly.
|
|
470
|
+
const float f_sp = 200.0f / 3.0f;
|
|
471
|
+
const float min_log_hz = 1000.0f;
|
|
472
|
+
const float min_log_mel = min_log_hz / f_sp; // = 15
|
|
473
|
+
const float logstep = std::log(6.4f) / 27.0f;
|
|
474
|
+
auto hz2mel = [&](float hz) -> float {
|
|
475
|
+
if (hz >= min_log_hz)
|
|
476
|
+
return min_log_mel + std::log(hz / min_log_hz) / logstep;
|
|
477
|
+
return hz / f_sp;
|
|
478
|
+
};
|
|
479
|
+
auto mel2hz = [&](float m) -> float {
|
|
480
|
+
if (m >= min_log_mel)
|
|
481
|
+
return min_log_hz * std::exp(logstep * (m - min_log_mel));
|
|
482
|
+
return f_sp * m;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const float ml = hz2mel(fmin);
|
|
486
|
+
const float mh = hz2mel(fmax);
|
|
487
|
+
std::vector<float> centers((size_t)n_mels + 2);
|
|
488
|
+
for (int i = 0; i < n_mels + 2; i++)
|
|
489
|
+
centers[i] = mel2hz(ml + (mh - ml) * (float)i / (float)(n_mels + 1));
|
|
490
|
+
|
|
491
|
+
std::vector<float> fb((size_t)n_mels * n_freqs, 0.0f);
|
|
492
|
+
for (int m = 0; m < n_mels; m++) {
|
|
493
|
+
const float lo = centers[m];
|
|
494
|
+
const float md = centers[m + 1];
|
|
495
|
+
const float hi = centers[m + 2];
|
|
496
|
+
// Slaney area normalization: 2 / (f_hi - f_lo). Each triangle's
|
|
497
|
+
// weights get scaled so its integral is approximately constant.
|
|
498
|
+
// librosa applies this when norm='slaney' (its default).
|
|
499
|
+
const float enorm = (hi > lo) ? (2.0f / (hi - lo)) : 0.0f;
|
|
500
|
+
for (int k = 0; k < n_freqs; k++) {
|
|
501
|
+
const float f = (float)k * (float)sr / (float)n_fft;
|
|
502
|
+
float w = 0.0f;
|
|
503
|
+
if (f >= lo && f <= md && md > lo)
|
|
504
|
+
w = (f - lo) / (md - lo);
|
|
505
|
+
else if (f >= md && f <= hi && hi > md)
|
|
506
|
+
w = (hi - f) / (hi - md);
|
|
507
|
+
if (w < 0.0f)
|
|
508
|
+
w = 0.0f;
|
|
509
|
+
w *= enorm;
|
|
510
|
+
if (layout == FbLayout::MelsFreqs)
|
|
511
|
+
fb[(size_t)m * n_freqs + k] = w;
|
|
512
|
+
else
|
|
513
|
+
fb[(size_t)k * n_mels + m] = w;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return fb;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
} // namespace core_mel
|