@mentra/bluetooth-sdk 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.
- package/README.md +278 -0
- package/android/build.gradle +167 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +109 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/mentra/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +528 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +610 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +1616 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +314 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothModels.kt +1710 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +554 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/ObservableStore.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +934 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +175 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/PhoneMic.kt +1109 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.java +3974 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +3551 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.java +1327 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.java +6959 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +1655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraosBle.java +53675 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +202 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +224 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +340 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +465 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +221 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +179 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/Constants.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleUploadService.java +76 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/K900ProtocolUtils.java +791 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/MessageChunker.java +186 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/NexSGCUtils.kt +589 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/PhoneAudioMonitor.kt +303 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/app.plugin.js +1 -0
- package/build/BluetoothSdk.types.d.ts +498 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +23 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/BluetoothSdkModule.d.ts +71 -0
- package/build/BluetoothSdkModule.d.ts.map +1 -0
- package/build/BluetoothSdkModule.js +106 -0
- package/build/BluetoothSdkModule.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/BluetoothSdkModule.swift +665 -0
- package/ios/MentraBluetoothSDK.podspec +77 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +1659 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/cargs.h +162 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/c-api.h +1852 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/cxx-api.h +674 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +44 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/sherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/sherpa-onnx.a +0 -0
- package/ios/Packages/VAD/Common/VAD/VADQuality.swift +41 -0
- package/ios/Packages/VAD/Common/VAD/VADState.swift +26 -0
- package/ios/Packages/VAD/Common/VAD/VADStrategy.swift +29 -0
- package/ios/Packages/VAD/Common/VAD/VADType.swift +14 -0
- package/ios/Packages/VAD/Data/Configuration.swift +68 -0
- package/ios/Packages/VAD/Data/FrameSize.swift +39 -0
- package/ios/Packages/VAD/Data/Record.swift +13 -0
- package/ios/Packages/VAD/Data/Result.swift +22 -0
- package/ios/Packages/VAD/Data/SampleRate.swift +48 -0
- package/ios/Packages/VAD/Silero/Model/silero_vad.onnx +0 -0
- package/ios/Packages/VAD/Silero/SileroVAD.swift +284 -0
- package/ios/Packages/VAD/Silero/SileroVADStrategy.swift +64 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/Source/Bridge.swift +353 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +1478 -0
- package/ios/Source/DeviceStore.swift +295 -0
- package/ios/Source/MentraBluetoothSDK.swift +2439 -0
- package/ios/Source/ObservableStore.swift +88 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/controllers/ControllerManager.swift +187 -0
- package/ios/Source/controllers/R1.swift +827 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Frame.swift +651 -0
- package/ios/Source/sgcs/G1.swift +2505 -0
- package/ios/Source/sgcs/G2.swift +3730 -0
- package/ios/Source/sgcs/Mach1.swift +543 -0
- package/ios/Source/sgcs/MentraLive.swift +4708 -0
- package/ios/Source/sgcs/MentraNex.swift +2479 -0
- package/ios/Source/sgcs/SGCManager.swift +243 -0
- package/ios/Source/sgcs/Simulated.swift +270 -0
- package/ios/Source/sgcs/mentraos_ble.pb.swift +3811 -0
- package/ios/Source/stt/STTTools.swift +154 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +401 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/Constants.swift +74 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2067 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunker.swift +164 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +226 -0
- package/ios/Source/utils/TarBz2Extractor.swift +206 -0
- package/package.json +78 -0
- package/plugin/build/index.d.ts +6 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +4 -0
- package/plugin/build/withAndroid.js +80 -0
- package/plugin/build/withIos.d.ts +4 -0
- package/plugin/build/withIos.js +64 -0
- package/src/BluetoothSdk.types.ts +581 -0
- package/src/BluetoothSdkModule.ts +259 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/* Copyright (C) 2007 Jean-Marc Valin
|
|
2
|
+
|
|
3
|
+
File: speex_resampler.h
|
|
4
|
+
Resampling code
|
|
5
|
+
|
|
6
|
+
The design goals of this code are:
|
|
7
|
+
- Very fast algorithm
|
|
8
|
+
- Low memory requirement
|
|
9
|
+
- Good *perceptual* quality (and not best SNR)
|
|
10
|
+
|
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
|
12
|
+
modification, are permitted provided that the following conditions are
|
|
13
|
+
met:
|
|
14
|
+
|
|
15
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
16
|
+
this list of conditions and the following disclaimer.
|
|
17
|
+
|
|
18
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
19
|
+
notice, this list of conditions and the following disclaimer in the
|
|
20
|
+
documentation and/or other materials provided with the distribution.
|
|
21
|
+
|
|
22
|
+
3. The name of the author may not be used to endorse or promote products
|
|
23
|
+
derived from this software without specific prior written permission.
|
|
24
|
+
|
|
25
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
26
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
27
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
28
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
29
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
30
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
31
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
32
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
33
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
34
|
+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
35
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#ifndef SPEEX_RESAMPLER_H
|
|
40
|
+
#define SPEEX_RESAMPLER_H
|
|
41
|
+
|
|
42
|
+
#ifdef OUTSIDE_SPEEX
|
|
43
|
+
|
|
44
|
+
/********* WARNING: MENTAL SANITY ENDS HERE *************/
|
|
45
|
+
|
|
46
|
+
/* If the resampler is defined outside of Speex, we change the symbol names so that
|
|
47
|
+
there won't be any clash if linking with Speex later on. */
|
|
48
|
+
|
|
49
|
+
/* #define RANDOM_PREFIX your software name here */
|
|
50
|
+
#ifndef RANDOM_PREFIX
|
|
51
|
+
#error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
#define CAT_PREFIX2(a,b) a ## b
|
|
55
|
+
#define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
|
|
56
|
+
|
|
57
|
+
#define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
|
|
58
|
+
#define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
|
|
59
|
+
#define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
|
|
60
|
+
#define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
|
|
61
|
+
#define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
|
|
62
|
+
#define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
|
|
63
|
+
#define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
|
|
64
|
+
#define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
|
|
65
|
+
#define speex_resampler_get_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)
|
|
66
|
+
#define speex_resampler_set_rate_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)
|
|
67
|
+
#define speex_resampler_get_ratio CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)
|
|
68
|
+
#define speex_resampler_set_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)
|
|
69
|
+
#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
|
|
70
|
+
#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
|
|
71
|
+
#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
|
|
72
|
+
#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
|
|
73
|
+
#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
|
|
74
|
+
#define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
|
|
75
|
+
#define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
|
|
76
|
+
#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
|
|
77
|
+
#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
|
|
78
|
+
#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
|
|
79
|
+
|
|
80
|
+
#define spx_int16_t short
|
|
81
|
+
#define spx_int32_t int
|
|
82
|
+
#define spx_uint16_t unsigned short
|
|
83
|
+
#define spx_uint32_t unsigned int
|
|
84
|
+
|
|
85
|
+
#else /* OUTSIDE_SPEEX */
|
|
86
|
+
|
|
87
|
+
#ifdef _BUILD_SPEEX
|
|
88
|
+
# include "speex_types.h"
|
|
89
|
+
#else
|
|
90
|
+
# include <speex/speex_types.h>
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
#endif /* OUTSIDE_SPEEX */
|
|
94
|
+
|
|
95
|
+
#ifdef __cplusplus
|
|
96
|
+
extern "C" {
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
#define SPEEX_RESAMPLER_QUALITY_MAX 10
|
|
100
|
+
#define SPEEX_RESAMPLER_QUALITY_MIN 0
|
|
101
|
+
#define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
|
|
102
|
+
#define SPEEX_RESAMPLER_QUALITY_VOIP 3
|
|
103
|
+
#define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
|
|
104
|
+
|
|
105
|
+
enum {
|
|
106
|
+
RESAMPLER_ERR_SUCCESS = 0,
|
|
107
|
+
RESAMPLER_ERR_ALLOC_FAILED = 1,
|
|
108
|
+
RESAMPLER_ERR_BAD_STATE = 2,
|
|
109
|
+
RESAMPLER_ERR_INVALID_ARG = 3,
|
|
110
|
+
RESAMPLER_ERR_PTR_OVERLAP = 4,
|
|
111
|
+
|
|
112
|
+
RESAMPLER_ERR_MAX_ERROR
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
struct SpeexResamplerState_;
|
|
116
|
+
typedef struct SpeexResamplerState_ SpeexResamplerState;
|
|
117
|
+
|
|
118
|
+
/** Create a new resampler with integer input and output rates.
|
|
119
|
+
* @param nb_channels Number of channels to be processed
|
|
120
|
+
* @param in_rate Input sampling rate (integer number of Hz).
|
|
121
|
+
* @param out_rate Output sampling rate (integer number of Hz).
|
|
122
|
+
* @param quality Resampling quality between 0 and 10, where 0 has poor quality
|
|
123
|
+
* and 10 has very high quality.
|
|
124
|
+
* @return Newly created resampler state
|
|
125
|
+
* @retval NULL Error: not enough memory
|
|
126
|
+
*/
|
|
127
|
+
SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels,
|
|
128
|
+
spx_uint32_t in_rate,
|
|
129
|
+
spx_uint32_t out_rate,
|
|
130
|
+
int quality,
|
|
131
|
+
int *err);
|
|
132
|
+
|
|
133
|
+
/** Create a new resampler with fractional input/output rates. The sampling
|
|
134
|
+
* rate ratio is an arbitrary rational number with both the numerator and
|
|
135
|
+
* denominator being 32-bit integers.
|
|
136
|
+
* @param nb_channels Number of channels to be processed
|
|
137
|
+
* @param ratio_num Numerator of the sampling rate ratio
|
|
138
|
+
* @param ratio_den Denominator of the sampling rate ratio
|
|
139
|
+
* @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
|
|
140
|
+
* @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
|
|
141
|
+
* @param quality Resampling quality between 0 and 10, where 0 has poor quality
|
|
142
|
+
* and 10 has very high quality.
|
|
143
|
+
* @return Newly created resampler state
|
|
144
|
+
* @retval NULL Error: not enough memory
|
|
145
|
+
*/
|
|
146
|
+
SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
|
|
147
|
+
spx_uint32_t ratio_num,
|
|
148
|
+
spx_uint32_t ratio_den,
|
|
149
|
+
spx_uint32_t in_rate,
|
|
150
|
+
spx_uint32_t out_rate,
|
|
151
|
+
int quality,
|
|
152
|
+
int *err);
|
|
153
|
+
|
|
154
|
+
/** Destroy a resampler state.
|
|
155
|
+
* @param st Resampler state
|
|
156
|
+
*/
|
|
157
|
+
void speex_resampler_destroy(SpeexResamplerState *st);
|
|
158
|
+
|
|
159
|
+
/** Resample a float array. The input and output buffers must *not* overlap.
|
|
160
|
+
* @param st Resampler state
|
|
161
|
+
* @param channel_index Index of the channel to process for the multi-channel
|
|
162
|
+
* base (0 otherwise)
|
|
163
|
+
* @param in Input buffer
|
|
164
|
+
* @param in_len Number of input samples in the input buffer. Returns the
|
|
165
|
+
* number of samples processed
|
|
166
|
+
* @param out Output buffer
|
|
167
|
+
* @param out_len Size of the output buffer. Returns the number of samples written
|
|
168
|
+
*/
|
|
169
|
+
int speex_resampler_process_float(SpeexResamplerState *st,
|
|
170
|
+
spx_uint32_t channel_index,
|
|
171
|
+
const float *in,
|
|
172
|
+
spx_uint32_t *in_len,
|
|
173
|
+
float *out,
|
|
174
|
+
spx_uint32_t *out_len);
|
|
175
|
+
|
|
176
|
+
/** Resample an int array. The input and output buffers must *not* overlap.
|
|
177
|
+
* @param st Resampler state
|
|
178
|
+
* @param channel_index Index of the channel to process for the multi-channel
|
|
179
|
+
* base (0 otherwise)
|
|
180
|
+
* @param in Input buffer
|
|
181
|
+
* @param in_len Number of input samples in the input buffer. Returns the number
|
|
182
|
+
* of samples processed
|
|
183
|
+
* @param out Output buffer
|
|
184
|
+
* @param out_len Size of the output buffer. Returns the number of samples written
|
|
185
|
+
*/
|
|
186
|
+
int speex_resampler_process_int(SpeexResamplerState *st,
|
|
187
|
+
spx_uint32_t channel_index,
|
|
188
|
+
const spx_int16_t *in,
|
|
189
|
+
spx_uint32_t *in_len,
|
|
190
|
+
spx_int16_t *out,
|
|
191
|
+
spx_uint32_t *out_len);
|
|
192
|
+
|
|
193
|
+
/** Resample an interleaved float array. The input and output buffers must *not* overlap.
|
|
194
|
+
* @param st Resampler state
|
|
195
|
+
* @param in Input buffer
|
|
196
|
+
* @param in_len Number of input samples in the input buffer. Returns the number
|
|
197
|
+
* of samples processed. This is all per-channel.
|
|
198
|
+
* @param out Output buffer
|
|
199
|
+
* @param out_len Size of the output buffer. Returns the number of samples written.
|
|
200
|
+
* This is all per-channel.
|
|
201
|
+
*/
|
|
202
|
+
int speex_resampler_process_interleaved_float(SpeexResamplerState *st,
|
|
203
|
+
const float *in,
|
|
204
|
+
spx_uint32_t *in_len,
|
|
205
|
+
float *out,
|
|
206
|
+
spx_uint32_t *out_len);
|
|
207
|
+
|
|
208
|
+
/** Resample an interleaved int array. The input and output buffers must *not* overlap.
|
|
209
|
+
* @param st Resampler state
|
|
210
|
+
* @param in Input buffer
|
|
211
|
+
* @param in_len Number of input samples in the input buffer. Returns the number
|
|
212
|
+
* of samples processed. This is all per-channel.
|
|
213
|
+
* @param out Output buffer
|
|
214
|
+
* @param out_len Size of the output buffer. Returns the number of samples written.
|
|
215
|
+
* This is all per-channel.
|
|
216
|
+
*/
|
|
217
|
+
int speex_resampler_process_interleaved_int(SpeexResamplerState *st,
|
|
218
|
+
const spx_int16_t *in,
|
|
219
|
+
spx_uint32_t *in_len,
|
|
220
|
+
spx_int16_t *out,
|
|
221
|
+
spx_uint32_t *out_len);
|
|
222
|
+
|
|
223
|
+
/** Set (change) the input/output sampling rates (integer value).
|
|
224
|
+
* @param st Resampler state
|
|
225
|
+
* @param in_rate Input sampling rate (integer number of Hz).
|
|
226
|
+
* @param out_rate Output sampling rate (integer number of Hz).
|
|
227
|
+
*/
|
|
228
|
+
int speex_resampler_set_rate(SpeexResamplerState *st,
|
|
229
|
+
spx_uint32_t in_rate,
|
|
230
|
+
spx_uint32_t out_rate);
|
|
231
|
+
|
|
232
|
+
/** Get the current input/output sampling rates (integer value).
|
|
233
|
+
* @param st Resampler state
|
|
234
|
+
* @param in_rate Input sampling rate (integer number of Hz) copied.
|
|
235
|
+
* @param out_rate Output sampling rate (integer number of Hz) copied.
|
|
236
|
+
*/
|
|
237
|
+
void speex_resampler_get_rate(SpeexResamplerState *st,
|
|
238
|
+
spx_uint32_t *in_rate,
|
|
239
|
+
spx_uint32_t *out_rate);
|
|
240
|
+
|
|
241
|
+
/** Set (change) the input/output sampling rates and resampling ratio
|
|
242
|
+
* (fractional values in Hz supported).
|
|
243
|
+
* @param st Resampler state
|
|
244
|
+
* @param ratio_num Numerator of the sampling rate ratio
|
|
245
|
+
* @param ratio_den Denominator of the sampling rate ratio
|
|
246
|
+
* @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
|
|
247
|
+
* @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
|
|
248
|
+
*/
|
|
249
|
+
int speex_resampler_set_rate_frac(SpeexResamplerState *st,
|
|
250
|
+
spx_uint32_t ratio_num,
|
|
251
|
+
spx_uint32_t ratio_den,
|
|
252
|
+
spx_uint32_t in_rate,
|
|
253
|
+
spx_uint32_t out_rate);
|
|
254
|
+
|
|
255
|
+
/** Get the current resampling ratio. This will be reduced to the least
|
|
256
|
+
* common denominator.
|
|
257
|
+
* @param st Resampler state
|
|
258
|
+
* @param ratio_num Numerator of the sampling rate ratio copied
|
|
259
|
+
* @param ratio_den Denominator of the sampling rate ratio copied
|
|
260
|
+
*/
|
|
261
|
+
void speex_resampler_get_ratio(SpeexResamplerState *st,
|
|
262
|
+
spx_uint32_t *ratio_num,
|
|
263
|
+
spx_uint32_t *ratio_den);
|
|
264
|
+
|
|
265
|
+
/** Set (change) the conversion quality.
|
|
266
|
+
* @param st Resampler state
|
|
267
|
+
* @param quality Resampling quality between 0 and 10, where 0 has poor
|
|
268
|
+
* quality and 10 has very high quality.
|
|
269
|
+
*/
|
|
270
|
+
int speex_resampler_set_quality(SpeexResamplerState *st,
|
|
271
|
+
int quality);
|
|
272
|
+
|
|
273
|
+
/** Get the conversion quality.
|
|
274
|
+
* @param st Resampler state
|
|
275
|
+
* @param quality Resampling quality between 0 and 10, where 0 has poor
|
|
276
|
+
* quality and 10 has very high quality.
|
|
277
|
+
*/
|
|
278
|
+
void speex_resampler_get_quality(SpeexResamplerState *st,
|
|
279
|
+
int *quality);
|
|
280
|
+
|
|
281
|
+
/** Set (change) the input stride.
|
|
282
|
+
* @param st Resampler state
|
|
283
|
+
* @param stride Input stride
|
|
284
|
+
*/
|
|
285
|
+
void speex_resampler_set_input_stride(SpeexResamplerState *st,
|
|
286
|
+
spx_uint32_t stride);
|
|
287
|
+
|
|
288
|
+
/** Get the input stride.
|
|
289
|
+
* @param st Resampler state
|
|
290
|
+
* @param stride Input stride copied
|
|
291
|
+
*/
|
|
292
|
+
void speex_resampler_get_input_stride(SpeexResamplerState *st,
|
|
293
|
+
spx_uint32_t *stride);
|
|
294
|
+
|
|
295
|
+
/** Set (change) the output stride.
|
|
296
|
+
* @param st Resampler state
|
|
297
|
+
* @param stride Output stride
|
|
298
|
+
*/
|
|
299
|
+
void speex_resampler_set_output_stride(SpeexResamplerState *st,
|
|
300
|
+
spx_uint32_t stride);
|
|
301
|
+
|
|
302
|
+
/** Get the output stride.
|
|
303
|
+
* @param st Resampler state copied
|
|
304
|
+
* @param stride Output stride
|
|
305
|
+
*/
|
|
306
|
+
void speex_resampler_get_output_stride(SpeexResamplerState *st,
|
|
307
|
+
spx_uint32_t *stride);
|
|
308
|
+
|
|
309
|
+
/** Get the latency introduced by the resampler measured in input samples.
|
|
310
|
+
* @param st Resampler state
|
|
311
|
+
*/
|
|
312
|
+
int speex_resampler_get_input_latency(SpeexResamplerState *st);
|
|
313
|
+
|
|
314
|
+
/** Get the latency introduced by the resampler measured in output samples.
|
|
315
|
+
* @param st Resampler state
|
|
316
|
+
*/
|
|
317
|
+
int speex_resampler_get_output_latency(SpeexResamplerState *st);
|
|
318
|
+
|
|
319
|
+
/** Make sure that the first samples to go out of the resamplers don't have
|
|
320
|
+
* leading zeros. This is only useful before starting to use a newly created
|
|
321
|
+
* resampler. It is recommended to use that when resampling an audio file, as
|
|
322
|
+
* it will generate a file with the same length. For real-time processing,
|
|
323
|
+
* it is probably easier not to use this call (so that the output duration
|
|
324
|
+
* is the same for the first frame).
|
|
325
|
+
* @param st Resampler state
|
|
326
|
+
*/
|
|
327
|
+
int speex_resampler_skip_zeros(SpeexResamplerState *st);
|
|
328
|
+
|
|
329
|
+
/** Reset a resampler so a new (unrelated) stream can be processed.
|
|
330
|
+
* @param st Resampler state
|
|
331
|
+
*/
|
|
332
|
+
int speex_resampler_reset_mem(SpeexResamplerState *st);
|
|
333
|
+
|
|
334
|
+
/** Returns the English meaning for an error code
|
|
335
|
+
* @param err Error code
|
|
336
|
+
* @return English string
|
|
337
|
+
*/
|
|
338
|
+
const char *speex_resampler_strerror(int err);
|
|
339
|
+
|
|
340
|
+
#ifdef __cplusplus
|
|
341
|
+
}
|
|
342
|
+
#endif
|
|
343
|
+
|
|
344
|
+
#endif
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* Copyright (C) 2002 Jean-Marc Valin */
|
|
2
|
+
/**
|
|
3
|
+
@file stack_alloc.h
|
|
4
|
+
@brief Temporary memory allocation on stack
|
|
5
|
+
*/
|
|
6
|
+
/*
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions
|
|
9
|
+
are met:
|
|
10
|
+
|
|
11
|
+
- Redistributions of source code must retain the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
|
13
|
+
|
|
14
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
- Neither the name of the Xiph.org Foundation nor the names of its
|
|
19
|
+
contributors may be used to endorse or promote products derived from
|
|
20
|
+
this software without specific prior written permission.
|
|
21
|
+
|
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
23
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
25
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
26
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
27
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
28
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
29
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
30
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
31
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
32
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
#ifndef STACK_ALLOC_H
|
|
36
|
+
#define STACK_ALLOC_H
|
|
37
|
+
|
|
38
|
+
#ifdef USE_ALLOCA
|
|
39
|
+
# ifdef WIN32
|
|
40
|
+
# include <malloc.h>
|
|
41
|
+
# else
|
|
42
|
+
# ifdef HAVE_ALLOCA_H
|
|
43
|
+
# include <alloca.h>
|
|
44
|
+
# else
|
|
45
|
+
# include <stdlib.h>
|
|
46
|
+
# endif
|
|
47
|
+
# endif
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @def ALIGN(stack, size)
|
|
52
|
+
*
|
|
53
|
+
* Aligns the stack to a 'size' boundary
|
|
54
|
+
*
|
|
55
|
+
* @param stack Stack
|
|
56
|
+
* @param size New size boundary
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @def PUSH(stack, size, type)
|
|
61
|
+
*
|
|
62
|
+
* Allocates 'size' elements of type 'type' on the stack
|
|
63
|
+
*
|
|
64
|
+
* @param stack Stack
|
|
65
|
+
* @param size Number of elements
|
|
66
|
+
* @param type Type of element
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @def VARDECL(var)
|
|
71
|
+
*
|
|
72
|
+
* Declare variable on stack
|
|
73
|
+
*
|
|
74
|
+
* @param var Variable to declare
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @def ALLOC(var, size, type)
|
|
79
|
+
*
|
|
80
|
+
* Allocate 'size' elements of 'type' on stack
|
|
81
|
+
*
|
|
82
|
+
* @param var Name of variable to allocate
|
|
83
|
+
* @param size Number of elements
|
|
84
|
+
* @param type Type of element
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
#ifdef ENABLE_VALGRIND
|
|
88
|
+
|
|
89
|
+
#include <valgrind/memcheck.h>
|
|
90
|
+
|
|
91
|
+
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
|
|
92
|
+
|
|
93
|
+
#define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
|
|
94
|
+
|
|
95
|
+
#else
|
|
96
|
+
|
|
97
|
+
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
|
|
98
|
+
|
|
99
|
+
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
|
|
100
|
+
|
|
101
|
+
#endif
|
|
102
|
+
|
|
103
|
+
#if defined(VAR_ARRAYS)
|
|
104
|
+
#define VARDECL(var)
|
|
105
|
+
#define ALLOC(var, size, type) type var[size]
|
|
106
|
+
#elif defined(USE_ALLOCA)
|
|
107
|
+
#define VARDECL(var) var
|
|
108
|
+
#define ALLOC(var, size, type) var = alloca(sizeof(type)*(size))
|
|
109
|
+
#else
|
|
110
|
+
#define VARDECL(var) var
|
|
111
|
+
#define ALLOC(var, size, type) var = PUSH(stack, size, type)
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
#endif
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* Copyright (C) 2002 Jean-Marc Valin
|
|
2
|
+
File: wav_io.c
|
|
3
|
+
Routines to handle wav (RIFF) headers
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions
|
|
7
|
+
are met:
|
|
8
|
+
|
|
9
|
+
- Redistributions of source code must retain the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
documentation and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
#ifdef HAVE_CONFIG_H
|
|
30
|
+
# include "config.h"
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#include <stdio.h>
|
|
34
|
+
#include <string.h>
|
|
35
|
+
#include "wav_io.h"
|
|
36
|
+
#include "opus_header.h"
|
|
37
|
+
|
|
38
|
+
/* Adjust the stream->channel mapping to ensure the proper output order for
|
|
39
|
+
WAV files. */
|
|
40
|
+
void adjust_wav_mapping(int mapping_family, int channels, unsigned char *stream_map)
|
|
41
|
+
{
|
|
42
|
+
unsigned char new_stream_map[8];
|
|
43
|
+
int i;
|
|
44
|
+
/* If we aren't using one of the defined semantic channel maps, or we have
|
|
45
|
+
more channels than we know what to do with, use a default 1-1 mapping. */
|
|
46
|
+
if(mapping_family != 1 || channels > 8)
|
|
47
|
+
return;
|
|
48
|
+
for(i = 0; i < channels; i++)
|
|
49
|
+
{
|
|
50
|
+
new_stream_map[wav_permute_matrix[channels-1][i]] = stream_map[i];
|
|
51
|
+
}
|
|
52
|
+
memcpy(stream_map, new_stream_map, channels*sizeof(*stream_map));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static size_t fwrite_le32(opus_int32 i32, FILE *file)
|
|
56
|
+
{
|
|
57
|
+
unsigned char buf[4];
|
|
58
|
+
buf[0]=(unsigned char)(i32&0xFF);
|
|
59
|
+
buf[1]=(unsigned char)(i32>>8&0xFF);
|
|
60
|
+
buf[2]=(unsigned char)(i32>>16&0xFF);
|
|
61
|
+
buf[3]=(unsigned char)(i32>>24&0xFF);
|
|
62
|
+
return fwrite(buf,4,1,file);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static size_t fwrite_le16(int i16, FILE *file)
|
|
66
|
+
{
|
|
67
|
+
unsigned char buf[2];
|
|
68
|
+
buf[0]=(unsigned char)(i16&0xFF);
|
|
69
|
+
buf[1]=(unsigned char)(i16>>8&0xFF);
|
|
70
|
+
return fwrite(buf,2,1,file);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
int write_wav_header(FILE *file, int rate, int mapping_family, int channels)
|
|
74
|
+
{
|
|
75
|
+
int ret;
|
|
76
|
+
int extensible;
|
|
77
|
+
|
|
78
|
+
/* Multichannel files require a WAVEFORMATEXTENSIBLE header to declare the
|
|
79
|
+
proper channel meanings. */
|
|
80
|
+
extensible = mapping_family == 1 && 3 <= channels && channels <= 8;
|
|
81
|
+
|
|
82
|
+
ret = fprintf (file, "RIFF") >= 0;
|
|
83
|
+
ret &= fwrite_le32 (0x7fffffff, file);
|
|
84
|
+
|
|
85
|
+
ret &= fprintf (file, "WAVEfmt ") >= 0;
|
|
86
|
+
ret &= fwrite_le32 (extensible ? 40 : 16, file);
|
|
87
|
+
ret &= fwrite_le16 (extensible ? 0xfffe : 1, file);
|
|
88
|
+
ret &= fwrite_le16 (channels, file);
|
|
89
|
+
ret &= fwrite_le32 (rate, file);
|
|
90
|
+
ret &= fwrite_le32 (2*channels*rate, file);
|
|
91
|
+
ret &= fwrite_le16 (2*channels, file);
|
|
92
|
+
ret &= fwrite_le16 (16, file);
|
|
93
|
+
|
|
94
|
+
if(extensible)
|
|
95
|
+
{
|
|
96
|
+
static const unsigned char ksdataformat_subtype_pcm[16]=
|
|
97
|
+
{
|
|
98
|
+
0x01, 0x00, 0x00, 0x00,
|
|
99
|
+
0x00, 0x00,
|
|
100
|
+
0x10, 0x00,
|
|
101
|
+
0x80, 0x00,
|
|
102
|
+
0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
|
|
103
|
+
};
|
|
104
|
+
static const int wav_channel_masks[8] =
|
|
105
|
+
{
|
|
106
|
+
1, /* 1.0 mono */
|
|
107
|
+
1|2, /* 2.0 stereo */
|
|
108
|
+
1|2|4, /* 3.0 channel ('wide') stereo */
|
|
109
|
+
1|2|16|32, /* 4.0 discrete quadrophonic */
|
|
110
|
+
1|2|4|16|32, /* 5.0 */
|
|
111
|
+
1|2|4|8|16|32, /* 5.1 */
|
|
112
|
+
1|2|4|8|256|512|1024, /* 6.1 */
|
|
113
|
+
1|2|4|8|16|32|512|1024, /* 7.1 */
|
|
114
|
+
};
|
|
115
|
+
ret &= fwrite_le16 (22, file);
|
|
116
|
+
ret &= fwrite_le16 (16, file);
|
|
117
|
+
ret &= fwrite_le32 (wav_channel_masks[channels-1], file);
|
|
118
|
+
ret &= fwrite (ksdataformat_subtype_pcm, 16, 1, file);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
ret &= fprintf (file, "data") >= 0;
|
|
122
|
+
ret &= fwrite_le32 (0x7fffffff, file);
|
|
123
|
+
|
|
124
|
+
return !ret ? -1 : extensible ? 40 : 16;
|
|
125
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* Copyright (C) 2002 Jean-Marc Valin
|
|
2
|
+
File: wav_io.h
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifndef WAV_IO_H
|
|
29
|
+
#define WAV_IO_H
|
|
30
|
+
|
|
31
|
+
#include <stdio.h>
|
|
32
|
+
#include <opus_types.h>
|
|
33
|
+
|
|
34
|
+
#if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
|
|
35
|
+
#define le_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
|
|
36
|
+
#define be_short(s) ((short) (s))
|
|
37
|
+
#else
|
|
38
|
+
#define le_short(s) ((short) (s))
|
|
39
|
+
#define be_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
/** Convert little endian */
|
|
43
|
+
static inline opus_int32 le_int(opus_int32 i)
|
|
44
|
+
{
|
|
45
|
+
#if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
|
|
46
|
+
opus_uint32 ui, ret;
|
|
47
|
+
ui = i;
|
|
48
|
+
ret = ui>>24;
|
|
49
|
+
ret |= (ui>>8)&0x0000ff00;
|
|
50
|
+
ret |= (ui<<8)&0x00ff0000;
|
|
51
|
+
ret |= (ui<<24);
|
|
52
|
+
return ret;
|
|
53
|
+
#else
|
|
54
|
+
return i;
|
|
55
|
+
#endif
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void adjust_wav_mapping(int mapping_family, int channels, unsigned char *stream_map);
|
|
59
|
+
|
|
60
|
+
int write_wav_header(FILE *file, int rate, int mapping_family, int channels);
|
|
61
|
+
|
|
62
|
+
#endif
|