@glassly/bluetooth-sdk 0.1.0-dev.26
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 +563 -0
- package/android/build.gradle +450 -0
- package/android/gradle.properties.example +9 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +212 -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/glassly/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 +4 -0
- package/android/silero/LICENSE.md +17 -0
- package/android/silero/build.gradle +50 -0
- package/android/silero/proguard-rules.pro +24 -0
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +79 -0
- package/android/silero/src/main/assets/LICENSE +21 -0
- package/android/silero/src/main/assets/silero_vad.onnx +0 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +160 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +449 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +15 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +14 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +12 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +47 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +41 -0
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +44 -0
- package/android/src/main/AndroidManifest.xml +42 -0
- package/android/src/main/assets/G2Firmware/README.md +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdk.kt +2325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkAnalytics.kt +216 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDebug.kt +14 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDefaults.kt +7 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkModule.kt +1088 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/Bridge.kt +953 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceManager.kt +2528 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceStore.kt +360 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedChangelogCatalog.kt +8 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedReleaseMetadata.kt +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/LocalNetworkModule.kt +414 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ObservableStore.kt +88 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/OtaManifest.kt +191 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ReleaseChangelog.kt +61 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ScopedNetworkReadiness.kt +17 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/audio/AudioModels.kt +144 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/camera/CameraModels.kt +486 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/connection/ConnectionModels.kt +78 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/R1.kt +937 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/debug/BleTraceLogger.kt +165 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/events/BluetoothEvents.kt +178 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/internal/MapParsing.kt +140 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/net/LocalIpv4.kt +57 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServer.kt +304 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/OtaServerModule.kt +120 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistry.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoUploadServer.kt +622 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/PhotoReceiverModule.kt +156 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/requests/DisplayRequests.kt +56 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/Foreground.kt +272 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/PhoneMic.kt +1195 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Ar99.java +2653 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuard.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapper.kt +27 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1.kt +3878 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizer.kt +38 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2.kt +6428 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassification.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwRenderer.kt +1241 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCache.kt +270 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocol.kt +291 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2Flasher.kt +411 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/GlasslyBle.java +43189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Mach1.kt +1280 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLive.kt +10817 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLiveL2capChannel.kt +274 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +54 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraNex.kt +2011 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Nimo.kt +2532 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/SGCManager.kt +470 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Simulated.kt +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/Ar99OtaManager.java +566 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaByteUtils.java +18 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCommandConstants.java +35 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCrc32Util.java +13 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaGattTransport.java +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaProtocol.java +92 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/speakerid/SpeakerIdEngine.kt +525 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/DeviceStatus.kt +669 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/RuntimeState.kt +201 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/WifiHotspotStatus.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/streaming/StreamModels.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/STTTools.kt +391 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/VadGateSpeechPolicy.kt +229 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/tts/TTSTools.kt +248 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/types/DeviceModels.kt +96 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AvifExifStripper.java +573 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleJsonCompact.java +496 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadService.java +677 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleWireProtocol.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/Constants.kt +46 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/HeifExifTagReader.java +199 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleUploadService.java +77 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900LengthCodec.java +115 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtils.java +827 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunkReassembler.java +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunker.java +325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/NexSGCUtils.kt +698 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitor.kt +348 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Ar99OpusPcmDecoder.java +398 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +328 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/BluetoothSdkExceptionTest.kt +18 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaManifestDowngradeTest.kt +86 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaStartResponsePolicyTest.kt +30 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ReleaseChangelogTest.kt +13 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ScopedNetworkReadinessTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/StreamStatusEventTest.kt +29 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/camera/PhotoRequestTest.kt +141 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServerTest.kt +82 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistryTest.java +75 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/services/ForegroundServiceTypeTest.kt +69 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/Ar99AdvertisementMatcherTest.java +22 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuardTest.kt +73 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapperTest.kt +67 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/EvenRleTest.kt +63 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +31 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassificationTest.kt +89 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwRendererTest.kt +344 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCacheTest.kt +200 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocolTest.kt +131 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLiveGattCharacteristicsTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +133 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/NimoProtocolTest.kt +333 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/AvifExifStripperTest.java +46 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BinaryMessageChunkerTest.java +84 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BleJsonCompactTest.java +319 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +107 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsEndiannessTest.java +172 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsTest.java +24 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitorTest.kt +45 -0
- package/android/src/test/resources/avif_with_exif.avif +0 -0
- package/app.plugin.js +3 -0
- package/build/BluetoothSdk.types.d.ts +1354 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +41 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/_internal.d.ts +17 -0
- package/build/_internal.d.ts.map +1 -0
- package/build/_internal.js +16 -0
- package/build/_internal.js.map +1 -0
- package/build/_private/BluetoothSdkModule.d.ts +172 -0
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -0
- package/build/_private/BluetoothSdkModule.js +300 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -0
- package/build/_private/LocalNetworkModule.d.ts +38 -0
- package/build/_private/LocalNetworkModule.d.ts.map +1 -0
- package/build/_private/LocalNetworkModule.js +3 -0
- package/build/_private/LocalNetworkModule.js.map +1 -0
- package/build/_private/cameraRequestPayload.d.ts +4 -0
- package/build/_private/cameraRequestPayload.d.ts.map +1 -0
- package/build/_private/cameraRequestPayload.js +32 -0
- package/build/_private/cameraRequestPayload.js.map +1 -0
- package/build/_private/photoRequestPayload.d.ts +6 -0
- package/build/_private/photoRequestPayload.d.ts.map +1 -0
- package/build/_private/photoRequestPayload.js +86 -0
- package/build/_private/photoRequestPayload.js.map +1 -0
- package/build/_private/sdkOtaManifest.d.ts +11 -0
- package/build/_private/sdkOtaManifest.d.ts.map +1 -0
- package/build/_private/sdkOtaManifest.js +15 -0
- package/build/_private/sdkOtaManifest.js.map +1 -0
- package/build/changelogs.d.ts +7 -0
- package/build/changelogs.d.ts.map +1 -0
- package/build/changelogs.js +46 -0
- package/build/changelogs.js.map +1 -0
- package/build/debug.d.ts +3 -0
- package/build/debug.d.ts.map +1 -0
- package/build/debug.js +8 -0
- package/build/debug.js.map +1 -0
- package/build/generated/changelogCatalog.d.ts +9 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -0
- package/build/generated/changelogCatalog.js +12 -0
- package/build/generated/changelogCatalog.js.map +1 -0
- package/build/generated/releaseMetadata.d.ts +12 -0
- package/build/generated/releaseMetadata.d.ts.map +1 -0
- package/build/generated/releaseMetadata.js +10 -0
- package/build/generated/releaseMetadata.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +171 -0
- package/build/index.js.map +1 -0
- package/build/ota-server/OtaServer.types.d.ts +14 -0
- package/build/ota-server/OtaServer.types.d.ts.map +1 -0
- package/build/ota-server/OtaServer.types.js +2 -0
- package/build/ota-server/OtaServer.types.js.map +1 -0
- package/build/ota-server/OtaServerModule.d.ts +21 -0
- package/build/ota-server/OtaServerModule.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.js +3 -0
- package/build/ota-server/OtaServerModule.js.map +1 -0
- package/build/ota-server/OtaServerModule.web.d.ts +10 -0
- package/build/ota-server/OtaServerModule.web.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.web.js +12 -0
- package/build/ota-server/OtaServerModule.web.js.map +1 -0
- package/build/ota-server/index.d.ts +3 -0
- package/build/ota-server/index.d.ts.map +1 -0
- package/build/ota-server/index.js +3 -0
- package/build/ota-server/index.js.map +1 -0
- package/build/ota-transport/index.d.ts +67 -0
- package/build/ota-transport/index.d.ts.map +1 -0
- package/build/ota-transport/index.js +58 -0
- package/build/ota-transport/index.js.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts +18 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.js +2 -0
- package/build/photo-receiver/PhotoReceiver.types.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.js +3 -0
- package/build/photo-receiver/PhotoReceiverModule.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js +12 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js.map +1 -0
- package/build/photo-receiver/index.d.ts +3 -0
- package/build/photo-receiver/index.d.ts.map +1 -0
- package/build/photo-receiver/index.js +3 -0
- package/build/photo-receiver/index.js.map +1 -0
- package/build/react/index.d.ts +5 -0
- package/build/react/index.d.ts.map +1 -0
- package/build/react/index.js +4 -0
- package/build/react/index.js.map +1 -0
- package/build/react/useBluetooth.d.ts +100 -0
- package/build/react/useBluetooth.d.ts.map +1 -0
- package/build/react/useBluetooth.js +167 -0
- package/build/react/useBluetooth.js.map +1 -0
- package/build/react/useBluetoothEvent.d.ts +6 -0
- package/build/react/useBluetoothEvent.d.ts.map +1 -0
- package/build/react/useBluetoothEvent.js +21 -0
- package/build/react/useBluetoothEvent.js.map +1 -0
- package/build/react/useBluetoothScan.d.ts +22 -0
- package/build/react/useBluetoothScan.d.ts.map +1 -0
- package/build/react/useBluetoothScan.js +135 -0
- package/build/react/useBluetoothScan.js.map +1 -0
- package/build/react/useBluetoothStatus.d.ts +16 -0
- package/build/react/useBluetoothStatus.d.ts.map +1 -0
- package/build/react/useBluetoothStatus.js +137 -0
- package/build/react/useBluetoothStatus.js.map +1 -0
- package/build/react/useGlassesConnection.d.ts +29 -0
- package/build/react/useGlassesConnection.d.ts.map +1 -0
- package/build/react/useGlassesConnection.js +153 -0
- package/build/react/useGlassesConnection.js.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/expo-module.config.json +14 -0
- package/ios/BackgroundOtaArtifactDownloader.swift +125 -0
- package/ios/BluetoothSdkModule.swift +1034 -0
- package/ios/GlasslyBluetoothSDK.podspec +106 -0
- package/ios/LocalIPv4.swift +150 -0
- package/ios/LocalOtaServer.swift +309 -0
- package/ios/LocalPhotoUploadServer.swift +754 -0
- package/ios/OtaServerModule.swift +147 -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/include/PcmConverter.h +22 -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 +2383 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +48 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/PhotoReceiverModule.swift +129 -0
- package/ios/Source/BluetoothSDK.swift +2303 -0
- package/ios/Source/BluetoothSDKDebug.swift +12 -0
- package/ios/Source/BluetoothSdkDefaults.swift +29 -0
- package/ios/Source/Bridge.swift +708 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +2109 -0
- package/ios/Source/DeviceStore.swift +336 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +7 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +11 -0
- package/ios/Source/ObservableStore.swift +118 -0
- package/ios/Source/OtaManifest.swift +211 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/ReleaseChangelog.swift +65 -0
- package/ios/Source/Resources/G2Firmware/README.md +10 -0
- package/ios/Source/audio/AudioModels.swift +178 -0
- package/ios/Source/audio/PcmStreamPlayer.swift +410 -0
- package/ios/Source/camera/CameraModels.swift +866 -0
- package/ios/Source/connection/ScanSession.swift +27 -0
- package/ios/Source/controllers/ControllerManager.swift +184 -0
- package/ios/Source/controllers/R1.swift +829 -0
- package/ios/Source/errors/BluetoothSdkError.swift +19 -0
- package/ios/Source/events/BluetoothEvents.swift +342 -0
- package/ios/Source/internal/BleTraceLogger.swift +192 -0
- package/ios/Source/internal/BluetoothAvailability.swift +78 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +199 -0
- package/ios/Source/internal/ValueParsing.swift +99 -0
- package/ios/Source/requests/DisplayRequests.swift +82 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Ar99.swift +2451 -0
- package/ios/Source/sgcs/Frame.swift +649 -0
- package/ios/Source/sgcs/G1.swift +2554 -0
- package/ios/Source/sgcs/G2.swift +6887 -0
- package/ios/Source/sgcs/G2CfwClassification.swift +43 -0
- package/ios/Source/sgcs/G2CfwRenderer.swift +1279 -0
- package/ios/Source/sgcs/G2CfwTextureCache.swift +233 -0
- package/ios/Source/sgcs/G2FlashProtocol.swift +312 -0
- package/ios/Source/sgcs/G2Flasher.swift +773 -0
- package/ios/Source/sgcs/Mach1.swift +541 -0
- package/ios/Source/sgcs/MentraLive.swift +7011 -0
- package/ios/Source/sgcs/MentraLiveL2capChannel.swift +183 -0
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +64 -0
- package/ios/Source/sgcs/MentraNex.swift +3221 -0
- package/ios/Source/sgcs/Nimo.swift +1886 -0
- package/ios/Source/sgcs/SGCManager.swift +608 -0
- package/ios/Source/sgcs/Simulated.swift +274 -0
- package/ios/Source/sgcs/ar99/ota/Ar99OtaManager.swift +637 -0
- package/ios/Source/sgcs/glassly_ble.pb.swift +4354 -0
- package/ios/Source/speakerid/SpeakerIdEngine.swift +573 -0
- package/ios/Source/status/DeviceStatus.swift +981 -0
- package/ios/Source/status/RuntimeState.swift +359 -0
- package/ios/Source/status/WifiHotspotStatus.swift +345 -0
- package/ios/Source/streaming/StreamModels.swift +693 -0
- package/ios/Source/stt/STTTools.swift +191 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +466 -0
- package/ios/Source/tts/TTSTools.swift +171 -0
- package/ios/Source/types/DeviceModels.swift +177 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/BinaryCodec.swift +61 -0
- package/ios/Source/utils/BleJsonCompact.swift +405 -0
- package/ios/Source/utils/BleWireProtocol.swift +92 -0
- package/ios/Source/utils/Constants.swift +78 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2096 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunkReassembler.swift +190 -0
- package/ios/Source/utils/MessageChunker.swift +294 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +230 -0
- package/ios/Source/utils/TarBz2Extractor.swift +257 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwClassificationTests.swift +78 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwRendererTests.swift +372 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwTextureCacheTests.swift +162 -0
- package/ios/Tests/BluetoothSDKTests/G2FlashProtocolTests.swift +182 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +160 -0
- package/ios/Tests/ReleaseChangelogTests.swift +13 -0
- package/package.json +129 -0
- package/plugin/build/index.d.ts +10 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +3 -0
- package/plugin/build/withAndroid.js +190 -0
- package/plugin/build/withIos.d.ts +5 -0
- package/plugin/build/withIos.js +108 -0
- package/scripts/inject-ios-sdk-version.mjs +65 -0
- package/scripts/public-ota-api.test.mjs +37 -0
- package/scripts/verify-release-package.mjs +45 -0
- package/scripts/write-release-metadata.mjs +152 -0
- package/scripts/write-release-metadata.test.mjs +37 -0
- package/src/BluetoothSdk.types.ts +1623 -0
- package/src/_internal.ts +16 -0
- package/src/_private/BluetoothSdkModule.ts +684 -0
- package/src/_private/LocalNetworkModule.ts +50 -0
- package/src/_private/cameraRequestPayload.ts +34 -0
- package/src/_private/photoRequestPayload.ts +90 -0
- package/src/_private/sdkOtaManifest.ts +18 -0
- package/src/changelogs.ts +46 -0
- package/src/debug.ts +9 -0
- package/src/generated/changelogCatalog.ts +13 -0
- package/src/generated/releaseMetadata.ts +20 -0
- package/src/index.ts +321 -0
- package/src/ota-server/OtaServer.types.ts +10 -0
- package/src/ota-server/OtaServerModule.ts +23 -0
- package/src/ota-server/OtaServerModule.web.ts +17 -0
- package/src/ota-server/index.ts +2 -0
- package/src/ota-transport/index.ts +116 -0
- package/src/photo-receiver/PhotoReceiver.types.ts +20 -0
- package/src/photo-receiver/PhotoReceiverModule.ts +11 -0
- package/src/photo-receiver/PhotoReceiverModule.web.ts +17 -0
- package/src/photo-receiver/index.ts +2 -0
- package/src/react/index.ts +21 -0
- package/src/react/useBluetooth.ts +309 -0
- package/src/react/useBluetoothEvent.ts +35 -0
- package/src/react/useBluetoothScan.ts +173 -0
- package/src/react/useBluetoothStatus.ts +180 -0
- package/src/react/useGlassesConnection.ts +202 -0
- package/src/types/index.ts +12 -0
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
/* Copyright 2000-2002, Michael Smith <msmith@xiph.org>
|
|
2
|
+
2010, Monty <monty@xiph.org>
|
|
3
|
+
AIFF/AIFC support from OggSquish, (c) 1994-1996 Monty <xiphmont@xiph.org>
|
|
4
|
+
(From GPL code in oggenc relicensed by permission from Monty and Msmith)
|
|
5
|
+
File: audio-in.c
|
|
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
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
22
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
23
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
24
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
25
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
26
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
#ifdef HAVE_CONFIG_H
|
|
32
|
+
# include <config.h>
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#include <stdlib.h>
|
|
36
|
+
#include <stdio.h>
|
|
37
|
+
#include <string.h>
|
|
38
|
+
#include <sys/types.h>
|
|
39
|
+
#include <math.h>
|
|
40
|
+
|
|
41
|
+
#ifdef WIN32
|
|
42
|
+
# include <malloc.h>
|
|
43
|
+
# include <windows.h> /*GetFileType()*/
|
|
44
|
+
# include <io.h> /*_get_osfhandle()*/
|
|
45
|
+
#else
|
|
46
|
+
# ifdef HAVE_ALLOCA_H
|
|
47
|
+
# include <alloca.h>
|
|
48
|
+
# else
|
|
49
|
+
# include <stdlib.h>
|
|
50
|
+
# endif
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
#ifdef ENABLE_NLS
|
|
54
|
+
#include <libintl.h>
|
|
55
|
+
#define _(X) gettext(X)
|
|
56
|
+
#else
|
|
57
|
+
#define _(X) (X)
|
|
58
|
+
#define textdomain(X)
|
|
59
|
+
#define bindtextdomain(X, Y)
|
|
60
|
+
#endif
|
|
61
|
+
#ifdef gettext_noop
|
|
62
|
+
#define N_(X) gettext_noop(X)
|
|
63
|
+
#else
|
|
64
|
+
#define N_(X) (X)
|
|
65
|
+
#endif
|
|
66
|
+
|
|
67
|
+
#include <ogg/ogg.h>
|
|
68
|
+
#include "opusenc.h"
|
|
69
|
+
#include "speex_resampler.h"
|
|
70
|
+
#include "lpc.h"
|
|
71
|
+
#include "opus_header.h"
|
|
72
|
+
|
|
73
|
+
#ifdef HAVE_LIBFLAC
|
|
74
|
+
#include "flac.h"
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
/* Macros to read header data */
|
|
78
|
+
#define READ_U32_LE(buf) \
|
|
79
|
+
(((buf)[3]<<24)|((buf)[2]<<16)|((buf)[1]<<8)|((buf)[0]&0xff))
|
|
80
|
+
|
|
81
|
+
#define READ_U16_LE(buf) \
|
|
82
|
+
(((buf)[1]<<8)|((buf)[0]&0xff))
|
|
83
|
+
|
|
84
|
+
#define READ_U32_BE(buf) \
|
|
85
|
+
(((buf)[0]<<24)|((buf)[1]<<16)|((buf)[2]<<8)|((buf)[3]&0xff))
|
|
86
|
+
|
|
87
|
+
#define READ_U16_BE(buf) \
|
|
88
|
+
(((buf)[0]<<8)|((buf)[1]&0xff))
|
|
89
|
+
|
|
90
|
+
/* Define the supported formats here */
|
|
91
|
+
input_format formats[] = {
|
|
92
|
+
{wav_id, 12, wav_open, wav_close, "wav", N_("WAV file reader")},
|
|
93
|
+
{aiff_id, 12, aiff_open, wav_close, "aiff", N_("AIFF/AIFC file reader")},
|
|
94
|
+
#ifdef HAVE_LIBFLAC
|
|
95
|
+
{flac_id, 4, flac_open, flac_close, "flac", N_("FLAC file reader")},
|
|
96
|
+
{oggflac_id, 32, flac_open, flac_close, "ogg", N_("Ogg FLAC file reader")},
|
|
97
|
+
#endif
|
|
98
|
+
{NULL, 0, NULL, NULL, NULL, NULL}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
input_format *open_audio_file(FILE *in, oe_enc_opt *opt)
|
|
102
|
+
{
|
|
103
|
+
int j=0;
|
|
104
|
+
unsigned char *buf=NULL;
|
|
105
|
+
int buf_size=0, buf_filled=0;
|
|
106
|
+
int size,ret;
|
|
107
|
+
|
|
108
|
+
while(formats[j].id_func)
|
|
109
|
+
{
|
|
110
|
+
size = formats[j].id_data_len;
|
|
111
|
+
if(size >= buf_size)
|
|
112
|
+
{
|
|
113
|
+
buf = realloc(buf, size);
|
|
114
|
+
buf_size = size;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if(size > buf_filled)
|
|
118
|
+
{
|
|
119
|
+
ret = fread(buf+buf_filled, 1, buf_size-buf_filled, in);
|
|
120
|
+
buf_filled += ret;
|
|
121
|
+
|
|
122
|
+
if(buf_filled < size)
|
|
123
|
+
{ /* File truncated */
|
|
124
|
+
j++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if(formats[j].id_func(buf, buf_filled))
|
|
130
|
+
{
|
|
131
|
+
/* ok, we now have something that can handle the file */
|
|
132
|
+
if(formats[j].open_func(in, opt, buf, buf_filled)) {
|
|
133
|
+
free(buf);
|
|
134
|
+
return &formats[j];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
j++;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
free(buf);
|
|
141
|
+
|
|
142
|
+
return NULL;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static int seek_forward(FILE *in, unsigned int length)
|
|
146
|
+
{
|
|
147
|
+
if(fseek(in, length, SEEK_CUR))
|
|
148
|
+
{
|
|
149
|
+
/* Failed. Do it the hard way. */
|
|
150
|
+
unsigned char buf[1024];
|
|
151
|
+
unsigned int seek_needed = length;
|
|
152
|
+
int seeked;
|
|
153
|
+
while(seek_needed > 0)
|
|
154
|
+
{
|
|
155
|
+
seeked = fread(buf, 1, seek_needed>1024?1024:seek_needed, in);
|
|
156
|
+
if(!seeked)
|
|
157
|
+
return 0; /* Couldn't read more, can't read file */
|
|
158
|
+
else
|
|
159
|
+
seek_needed -= seeked;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static int find_wav_chunk(FILE *in, char *type, unsigned int *len)
|
|
166
|
+
{
|
|
167
|
+
unsigned char buf[8];
|
|
168
|
+
|
|
169
|
+
while(1)
|
|
170
|
+
{
|
|
171
|
+
if(fread(buf,1,8,in) < 8) /* Suck down a chunk specifier */
|
|
172
|
+
{
|
|
173
|
+
fprintf(stderr, _("Warning: Unexpected EOF in reading WAV header\n"));
|
|
174
|
+
return 0; /* EOF before reaching the appropriate chunk */
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if(memcmp(buf, type, 4))
|
|
178
|
+
{
|
|
179
|
+
*len = READ_U32_LE(buf+4);
|
|
180
|
+
if(!seek_forward(in, *len))
|
|
181
|
+
return 0;
|
|
182
|
+
|
|
183
|
+
buf[4] = 0;
|
|
184
|
+
fprintf(stderr, _("Skipping chunk of type \"%s\", length %d\n"), buf, *len);
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
{
|
|
188
|
+
*len = READ_U32_LE(buf+4);
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static int find_aiff_chunk(FILE *in, char *type, unsigned int *len)
|
|
195
|
+
{
|
|
196
|
+
unsigned char buf[8];
|
|
197
|
+
int restarted = 0;
|
|
198
|
+
|
|
199
|
+
while(1)
|
|
200
|
+
{
|
|
201
|
+
if(fread(buf,1,8,in) <8)
|
|
202
|
+
{
|
|
203
|
+
if(!restarted) {
|
|
204
|
+
/* Handle out of order chunks by seeking back to the start
|
|
205
|
+
* to retry */
|
|
206
|
+
restarted = 1;
|
|
207
|
+
fseek(in, 12, SEEK_SET);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
fprintf(stderr, _("Warning: Unexpected EOF in AIFF chunk\n"));
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
*len = READ_U32_BE(buf+4);
|
|
215
|
+
|
|
216
|
+
if(memcmp(buf,type,4))
|
|
217
|
+
{
|
|
218
|
+
if((*len) & 0x1)
|
|
219
|
+
(*len)++;
|
|
220
|
+
|
|
221
|
+
if(!seek_forward(in, *len))
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
else
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
double read_IEEE80(unsigned char *buf)
|
|
230
|
+
{
|
|
231
|
+
int s=buf[0]&0xff;
|
|
232
|
+
int e=((buf[0]&0x7f)<<8)|(buf[1]&0xff);
|
|
233
|
+
double f=((unsigned long)(buf[2]&0xff)<<24)|
|
|
234
|
+
((buf[3]&0xff)<<16)|
|
|
235
|
+
((buf[4]&0xff)<<8) |
|
|
236
|
+
(buf[5]&0xff);
|
|
237
|
+
|
|
238
|
+
if(e==32767)
|
|
239
|
+
{
|
|
240
|
+
if(buf[2]&0x80)
|
|
241
|
+
return HUGE_VAL; /* Really NaN, but this won't happen in reality */
|
|
242
|
+
else
|
|
243
|
+
{
|
|
244
|
+
if(s)
|
|
245
|
+
return -HUGE_VAL;
|
|
246
|
+
else
|
|
247
|
+
return HUGE_VAL;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
f=ldexp(f,32);
|
|
252
|
+
f+= ((buf[6]&0xff)<<24)|
|
|
253
|
+
((buf[7]&0xff)<<16)|
|
|
254
|
+
((buf[8]&0xff)<<8) |
|
|
255
|
+
(buf[9]&0xff);
|
|
256
|
+
|
|
257
|
+
return ldexp(f, e-16446);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* AIFF/AIFC support adapted from the old OggSQUISH application */
|
|
261
|
+
int aiff_id(unsigned char *buf, int len)
|
|
262
|
+
{
|
|
263
|
+
if(len<12) return 0; /* Truncated file, probably */
|
|
264
|
+
|
|
265
|
+
if(memcmp(buf, "FORM", 4))
|
|
266
|
+
return 0;
|
|
267
|
+
|
|
268
|
+
if(memcmp(buf+8, "AIF",3))
|
|
269
|
+
return 0;
|
|
270
|
+
|
|
271
|
+
if(buf[11]!='C' && buf[11]!='F')
|
|
272
|
+
return 0;
|
|
273
|
+
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
static int aiff_permute_matrix[6][6] =
|
|
278
|
+
{
|
|
279
|
+
{0}, /* 1.0 mono */
|
|
280
|
+
{0,1}, /* 2.0 stereo */
|
|
281
|
+
{0,2,1}, /* 3.0 channel ('wide') stereo */
|
|
282
|
+
{0,1,2,3}, /* 4.0 discrete quadraphonic (WARN) */
|
|
283
|
+
{0,2,1,3,4}, /* 5.0 surround (WARN) */
|
|
284
|
+
{0,1,2,3,4,5}, /* 5.1 surround (WARN)*/
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
|
|
288
|
+
{
|
|
289
|
+
int aifc; /* AIFC or AIFF? */
|
|
290
|
+
unsigned int len;
|
|
291
|
+
unsigned char *buffer;
|
|
292
|
+
unsigned char buf2[8];
|
|
293
|
+
int bigendian = 1;
|
|
294
|
+
aiff_fmt format;
|
|
295
|
+
aifffile *aiff;
|
|
296
|
+
int i;
|
|
297
|
+
(void)buflen;/*unused*/
|
|
298
|
+
|
|
299
|
+
if(buf[11]=='C')
|
|
300
|
+
aifc=1;
|
|
301
|
+
else
|
|
302
|
+
aifc=0;
|
|
303
|
+
|
|
304
|
+
if(!find_aiff_chunk(in, "COMM", &len))
|
|
305
|
+
{
|
|
306
|
+
fprintf(stderr, _("Warning: No common chunk found in AIFF file\n"));
|
|
307
|
+
return 0; /* EOF before COMM chunk */
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if(len < 18)
|
|
311
|
+
{
|
|
312
|
+
fprintf(stderr, _("Warning: Truncated common chunk in AIFF header\n"));
|
|
313
|
+
return 0; /* Weird common chunk */
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
buffer = alloca(len);
|
|
317
|
+
|
|
318
|
+
if(fread(buffer,1,len,in) < len)
|
|
319
|
+
{
|
|
320
|
+
fprintf(stderr, _("Warning: Unexpected EOF in reading AIFF header\n"));
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
format.channels = READ_U16_BE(buffer);
|
|
325
|
+
format.totalframes = READ_U32_BE(buffer+2);
|
|
326
|
+
format.samplesize = READ_U16_BE(buffer+6);
|
|
327
|
+
format.rate = (int)read_IEEE80(buffer+8);
|
|
328
|
+
|
|
329
|
+
if(aifc)
|
|
330
|
+
{
|
|
331
|
+
if(len < 22)
|
|
332
|
+
{
|
|
333
|
+
fprintf(stderr, _("Warning: AIFF-C header truncated.\n"));
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if(!memcmp(buffer+18, "NONE", 4))
|
|
338
|
+
{
|
|
339
|
+
bigendian = 1;
|
|
340
|
+
}
|
|
341
|
+
else if(!memcmp(buffer+18, "sowt", 4))
|
|
342
|
+
{
|
|
343
|
+
bigendian = 0;
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
{
|
|
347
|
+
fprintf(stderr, _("Warning: Can't handle compressed AIFF-C (%c%c%c%c)\n"), *(buffer+18), *(buffer+19), *(buffer+20), *(buffer+21));
|
|
348
|
+
return 0; /* Compressed. Can't handle */
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if(!find_aiff_chunk(in, "SSND", &len))
|
|
353
|
+
{
|
|
354
|
+
fprintf(stderr, _("Warning: No SSND chunk found in AIFF file\n"));
|
|
355
|
+
return 0; /* No SSND chunk -> no actual audio */
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if(len < 8)
|
|
359
|
+
{
|
|
360
|
+
fprintf(stderr, _("Warning: Corrupted SSND chunk in AIFF header\n"));
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if(fread(buf2,1,8, in) < 8)
|
|
365
|
+
{
|
|
366
|
+
fprintf(stderr, _("Warning: Unexpected EOF reading AIFF header\n"));
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
format.offset = READ_U32_BE(buf2);
|
|
371
|
+
format.blocksize = READ_U32_BE(buf2+4);
|
|
372
|
+
|
|
373
|
+
if( format.blocksize == 0 &&
|
|
374
|
+
(format.samplesize == 16 || format.samplesize == 8))
|
|
375
|
+
{
|
|
376
|
+
/* From here on, this is very similar to the wav code. Oh well. */
|
|
377
|
+
|
|
378
|
+
opt->rate = format.rate;
|
|
379
|
+
opt->channels = format.channels;
|
|
380
|
+
opt->read_samples = wav_read; /* Similar enough, so we use the same */
|
|
381
|
+
opt->total_samples_per_channel = format.totalframes;
|
|
382
|
+
|
|
383
|
+
aiff = malloc(sizeof(aifffile));
|
|
384
|
+
aiff->f = in;
|
|
385
|
+
aiff->samplesread = 0;
|
|
386
|
+
aiff->channels = format.channels;
|
|
387
|
+
aiff->samplesize = format.samplesize;
|
|
388
|
+
aiff->totalsamples = format.totalframes;
|
|
389
|
+
aiff->bigendian = bigendian;
|
|
390
|
+
|
|
391
|
+
if(aiff->channels>3)
|
|
392
|
+
fprintf(stderr,"WARNING: AIFF[-C] files with greater than three channels use\n"
|
|
393
|
+
"speaker locations incompatable with Vorbis suppound definitions.\n"
|
|
394
|
+
"Not performaing channel location mapping.\n");
|
|
395
|
+
|
|
396
|
+
opt->readdata = (void *)aiff;
|
|
397
|
+
|
|
398
|
+
aiff->channel_permute = malloc(aiff->channels * sizeof(int));
|
|
399
|
+
if (aiff->channels <= 6)
|
|
400
|
+
/* Where we know the mappings, use them. */
|
|
401
|
+
memcpy(aiff->channel_permute, aiff_permute_matrix[aiff->channels-1],
|
|
402
|
+
sizeof(int) * aiff->channels);
|
|
403
|
+
else
|
|
404
|
+
/* Use a default 1-1 mapping */
|
|
405
|
+
for (i=0; i < aiff->channels; i++)
|
|
406
|
+
aiff->channel_permute[i] = i;
|
|
407
|
+
|
|
408
|
+
seek_forward(in, format.offset); /* Swallow some data */
|
|
409
|
+
return 1;
|
|
410
|
+
}
|
|
411
|
+
else
|
|
412
|
+
{
|
|
413
|
+
fprintf(stderr,
|
|
414
|
+
_("Warning: OggEnc does not support this type of AIFF/AIFC file\n"
|
|
415
|
+
" Must be 8 or 16 bit PCM.\n"));
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
int wav_id(unsigned char *buf, int len)
|
|
421
|
+
{
|
|
422
|
+
if(len<12) return 0; /* Something screwed up */
|
|
423
|
+
|
|
424
|
+
if(memcmp(buf, "RIFF", 4))
|
|
425
|
+
return 0; /* Not wave */
|
|
426
|
+
|
|
427
|
+
/*flen = READ_U32_LE(buf+4);*/ /* We don't use this */
|
|
428
|
+
|
|
429
|
+
if(memcmp(buf+8, "WAVE",4))
|
|
430
|
+
return 0; /* RIFF, but not wave */
|
|
431
|
+
|
|
432
|
+
return 1;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
int wav_open(FILE *in, oe_enc_opt *opt, unsigned char *oldbuf, int buflen)
|
|
436
|
+
{
|
|
437
|
+
unsigned char buf[40];
|
|
438
|
+
unsigned int len;
|
|
439
|
+
int samplesize;
|
|
440
|
+
wav_fmt format;
|
|
441
|
+
wavfile *wav;
|
|
442
|
+
int i;
|
|
443
|
+
(void)buflen;/*unused*/
|
|
444
|
+
(void)oldbuf;/*unused*/
|
|
445
|
+
|
|
446
|
+
/* Ok. At this point, we know we have a WAV file. Now we have to detect
|
|
447
|
+
* whether we support the subtype, and we have to find the actual data
|
|
448
|
+
* We don't (for the wav reader) need to use the buffer we used to id this
|
|
449
|
+
* as a wav file (oldbuf)
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
if(!find_wav_chunk(in, "fmt ", &len))
|
|
453
|
+
return 0; /* EOF */
|
|
454
|
+
|
|
455
|
+
if(len < 16)
|
|
456
|
+
{
|
|
457
|
+
fprintf(stderr, _("Warning: Unrecognised format chunk in WAV header\n"));
|
|
458
|
+
return 0; /* Weird format chunk */
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/* A common error is to have a format chunk that is not 16, 18 or
|
|
462
|
+
* 40 bytes in size. This is incorrect, but not fatal, so we only
|
|
463
|
+
* warn about it instead of refusing to work with the file.
|
|
464
|
+
* Please, if you have a program that's creating format chunks of
|
|
465
|
+
* sizes other than 16 or 18 bytes in size, report a bug to the
|
|
466
|
+
* author.
|
|
467
|
+
*/
|
|
468
|
+
if(len!=16 && len!=18 && len!=40)
|
|
469
|
+
fprintf(stderr,
|
|
470
|
+
_("Warning: INVALID format chunk in wav header.\n"
|
|
471
|
+
" Trying to read anyway (may not work)...\n"));
|
|
472
|
+
|
|
473
|
+
if(len>40)len=40;
|
|
474
|
+
|
|
475
|
+
if(fread(buf,1,len,in) < len)
|
|
476
|
+
{
|
|
477
|
+
fprintf(stderr, _("Warning: Unexpected EOF in reading WAV header\n"));
|
|
478
|
+
return 0;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
format.format = READ_U16_LE(buf);
|
|
482
|
+
format.channels = READ_U16_LE(buf+2);
|
|
483
|
+
format.samplerate = READ_U32_LE(buf+4);
|
|
484
|
+
format.bytespersec = READ_U32_LE(buf+8);
|
|
485
|
+
format.align = READ_U16_LE(buf+12);
|
|
486
|
+
format.samplesize = READ_U16_LE(buf+14);
|
|
487
|
+
|
|
488
|
+
if(format.format == -2) /* WAVE_FORMAT_EXTENSIBLE */
|
|
489
|
+
{
|
|
490
|
+
if(len<40)
|
|
491
|
+
{
|
|
492
|
+
fprintf(stderr,"ERROR: Extended WAV format header invalid (too small)\n");
|
|
493
|
+
return 0;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
format.mask = READ_U32_LE(buf+20);
|
|
497
|
+
/* warn the user if the format mask is not a supported/expected type */
|
|
498
|
+
switch(format.mask){
|
|
499
|
+
case 1539: /* 4.0 using side surround instead of back */
|
|
500
|
+
fprintf(stderr,"WARNING: WAV file uses side surround instead of rear for quadraphonic;\n"
|
|
501
|
+
"remapping side speakers to rear in encoding.\n");
|
|
502
|
+
break;
|
|
503
|
+
case 1551: /* 5.1 using side instead of rear */
|
|
504
|
+
fprintf(stderr,"WARNING: WAV file uses side surround instead of rear for 5.1;\n"
|
|
505
|
+
"remapping side speakers to rear in encoding.\n");
|
|
506
|
+
break;
|
|
507
|
+
case 319: /* 6.1 using rear instead of side */
|
|
508
|
+
fprintf(stderr,"WARNING: WAV file uses rear surround instead of side for 6.1;\n"
|
|
509
|
+
"remapping rear speakers to side in encoding.\n");
|
|
510
|
+
break;
|
|
511
|
+
case 255: /* 7.1 'Widescreen' */
|
|
512
|
+
fprintf(stderr,"WARNING: WAV file is a 7.1 'Widescreen' channel mapping;\n"
|
|
513
|
+
"remapping speakers to Vorbis 7.1 format.\n");
|
|
514
|
+
break;
|
|
515
|
+
case 0: /* default/undeclared */
|
|
516
|
+
case 1: /* mono */
|
|
517
|
+
case 3: /* stereo */
|
|
518
|
+
case 51: /* quad */
|
|
519
|
+
case 55: /* 5.0 */
|
|
520
|
+
case 63: /* 5.1 */
|
|
521
|
+
case 1807: /* 6.1 */
|
|
522
|
+
case 1599: /* 7.1 */
|
|
523
|
+
break;
|
|
524
|
+
default:
|
|
525
|
+
fprintf(stderr,"WARNING: Unknown WAV surround channel mask: %d\n"
|
|
526
|
+
"blindly mapping speakers using default SMPTE/ITU ordering.\n",
|
|
527
|
+
format.mask);
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
format.format = READ_U16_LE(buf+24);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if(!find_wav_chunk(in, "data", &len))
|
|
534
|
+
return 0; /* EOF */
|
|
535
|
+
|
|
536
|
+
if(format.format == 1)
|
|
537
|
+
{
|
|
538
|
+
samplesize = format.samplesize/8;
|
|
539
|
+
opt->read_samples = wav_read;
|
|
540
|
+
}
|
|
541
|
+
else if(format.format == 3)
|
|
542
|
+
{
|
|
543
|
+
samplesize = 4;
|
|
544
|
+
opt->read_samples = wav_ieee_read;
|
|
545
|
+
}
|
|
546
|
+
else
|
|
547
|
+
{
|
|
548
|
+
fprintf(stderr,
|
|
549
|
+
_("ERROR: Wav file is unsupported type (must be standard PCM\n"
|
|
550
|
+
" or type 3 floating point PCM\n"));
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if(format.align != format.channels * samplesize) {
|
|
555
|
+
/* This is incorrect according to the spec. Warn loudly, then ignore
|
|
556
|
+
* this value.
|
|
557
|
+
*/
|
|
558
|
+
fprintf(stderr, _("Warning: WAV 'block alignment' value is incorrect, "
|
|
559
|
+
"ignoring.\n"
|
|
560
|
+
"The software that created this file is incorrect.\n"));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if(format.samplesize == samplesize*8 &&
|
|
564
|
+
(format.samplesize == 24 || format.samplesize == 16 ||
|
|
565
|
+
format.samplesize == 8 ||
|
|
566
|
+
(format.samplesize == 32 && format.format == 3)))
|
|
567
|
+
{
|
|
568
|
+
/* OK, good - we have the one supported format,
|
|
569
|
+
now we want to find the size of the file */
|
|
570
|
+
opt->rate = format.samplerate;
|
|
571
|
+
opt->channels = format.channels;
|
|
572
|
+
|
|
573
|
+
wav = malloc(sizeof(wavfile));
|
|
574
|
+
wav->f = in;
|
|
575
|
+
wav->samplesread = 0;
|
|
576
|
+
wav->bigendian = 0;
|
|
577
|
+
wav->channels = format.channels; /* This is in several places. The price
|
|
578
|
+
of trying to abstract stuff. */
|
|
579
|
+
wav->samplesize = format.samplesize;
|
|
580
|
+
|
|
581
|
+
if(len>(format.channels*samplesize*4U) && len<((1U<<31)-65536) && opt->ignorelength!=1) /*Length provided is plausible.*/
|
|
582
|
+
{
|
|
583
|
+
opt->total_samples_per_channel = len/(format.channels*samplesize);
|
|
584
|
+
}
|
|
585
|
+
#ifdef WIN32
|
|
586
|
+
/*On Mingw/Win32 fseek() returns zero on pipes.*/
|
|
587
|
+
else if (opt->ignorelength==1 || ((GetFileType((HANDLE)_get_osfhandle(fileno(in)))&~FILE_TYPE_REMOTE)!=FILE_TYPE_DISK))
|
|
588
|
+
#else
|
|
589
|
+
else if (opt->ignorelength==1)
|
|
590
|
+
#endif
|
|
591
|
+
{
|
|
592
|
+
opt->total_samples_per_channel = 0;
|
|
593
|
+
}
|
|
594
|
+
else
|
|
595
|
+
{
|
|
596
|
+
opus_int64 pos;
|
|
597
|
+
pos = ftell(in);
|
|
598
|
+
if(fseek(in, 0, SEEK_END) == -1)
|
|
599
|
+
{
|
|
600
|
+
opt->total_samples_per_channel = 0; /* Give up */
|
|
601
|
+
}
|
|
602
|
+
else
|
|
603
|
+
{
|
|
604
|
+
opt->total_samples_per_channel = (ftell(in) - pos)/
|
|
605
|
+
(format.channels*samplesize);
|
|
606
|
+
fseek(in,pos, SEEK_SET);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
wav->totalsamples = opt->total_samples_per_channel;
|
|
610
|
+
|
|
611
|
+
opt->readdata = (void *)wav;
|
|
612
|
+
|
|
613
|
+
wav->channel_permute = malloc(wav->channels * sizeof(int));
|
|
614
|
+
if (wav->channels <= 8)
|
|
615
|
+
/* Where we know the mappings, use them. */
|
|
616
|
+
memcpy(wav->channel_permute, wav_permute_matrix[wav->channels-1],
|
|
617
|
+
sizeof(int) * wav->channels);
|
|
618
|
+
else
|
|
619
|
+
/* Use a default 1-1 mapping */
|
|
620
|
+
for (i=0; i < wav->channels; i++)
|
|
621
|
+
wav->channel_permute[i] = i;
|
|
622
|
+
|
|
623
|
+
return 1;
|
|
624
|
+
}
|
|
625
|
+
else
|
|
626
|
+
{
|
|
627
|
+
fprintf(stderr,
|
|
628
|
+
_("ERROR: Wav file is unsupported subformat (must be 8,16, or 24 bit PCM\n"
|
|
629
|
+
"or floating point PCM\n"));
|
|
630
|
+
return 0;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
long wav_read(void *in, float *buffer, int samples)
|
|
635
|
+
{
|
|
636
|
+
wavfile *f = (wavfile *)in;
|
|
637
|
+
int sampbyte = f->samplesize / 8;
|
|
638
|
+
signed char *buf = alloca(samples*sampbyte*f->channels);
|
|
639
|
+
long bytes_read = fread(buf, 1, samples*sampbyte*f->channels, f->f);
|
|
640
|
+
int i,j;
|
|
641
|
+
opus_int64 realsamples;
|
|
642
|
+
int *ch_permute = f->channel_permute;
|
|
643
|
+
|
|
644
|
+
if(f->totalsamples && f->samplesread +
|
|
645
|
+
bytes_read/(sampbyte*f->channels) > f->totalsamples) {
|
|
646
|
+
bytes_read = sampbyte*f->channels*(f->totalsamples - f->samplesread);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
realsamples = bytes_read/(sampbyte*f->channels);
|
|
650
|
+
f->samplesread += realsamples;
|
|
651
|
+
|
|
652
|
+
if(f->samplesize==8)
|
|
653
|
+
{
|
|
654
|
+
unsigned char *bufu = (unsigned char *)buf;
|
|
655
|
+
for(i = 0; i < realsamples; i++)
|
|
656
|
+
{
|
|
657
|
+
for(j=0; j < f->channels; j++)
|
|
658
|
+
{
|
|
659
|
+
buffer[i*f->channels+j]=((int)(bufu[i*f->channels + ch_permute[j]])-128)/128.0f;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else if(f->samplesize==16)
|
|
664
|
+
{
|
|
665
|
+
if(!f->bigendian)
|
|
666
|
+
{
|
|
667
|
+
for(i = 0; i < realsamples; i++)
|
|
668
|
+
{
|
|
669
|
+
for(j=0; j < f->channels; j++)
|
|
670
|
+
{
|
|
671
|
+
buffer[i*f->channels+j] = ((buf[i*2*f->channels + 2*ch_permute[j] + 1]<<8) |
|
|
672
|
+
(buf[i*2*f->channels + 2*ch_permute[j]] & 0xff))/32768.0f;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
else
|
|
677
|
+
{
|
|
678
|
+
for(i = 0; i < realsamples; i++)
|
|
679
|
+
{
|
|
680
|
+
for(j=0; j < f->channels; j++)
|
|
681
|
+
{
|
|
682
|
+
buffer[i*f->channels+j]=((buf[i*2*f->channels + 2*ch_permute[j]]<<8) |
|
|
683
|
+
(buf[i*2*f->channels + 2*ch_permute[j] + 1] & 0xff))/32768.0f;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
else if(f->samplesize==24)
|
|
689
|
+
{
|
|
690
|
+
if(!f->bigendian) {
|
|
691
|
+
for(i = 0; i < realsamples; i++)
|
|
692
|
+
{
|
|
693
|
+
for(j=0; j < f->channels; j++)
|
|
694
|
+
{
|
|
695
|
+
buffer[i*f->channels+j] = ((buf[i*3*f->channels + 3*ch_permute[j] + 2] << 16) |
|
|
696
|
+
(((unsigned char *)buf)[i*3*f->channels + 3*ch_permute[j] + 1] << 8) |
|
|
697
|
+
(((unsigned char *)buf)[i*3*f->channels + 3*ch_permute[j]] & 0xff))
|
|
698
|
+
/ 8388608.0f;
|
|
699
|
+
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
fprintf(stderr, _("Big endian 24 bit PCM data is not currently "
|
|
705
|
+
"supported, aborting.\n"));
|
|
706
|
+
return 0;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
fprintf(stderr, _("Internal error: attempt to read unsupported "
|
|
711
|
+
"bitdepth %d\n"), f->samplesize);
|
|
712
|
+
return 0;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
return realsamples;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
long wav_ieee_read(void *in, float *buffer, int samples)
|
|
719
|
+
{
|
|
720
|
+
wavfile *f = (wavfile *)in;
|
|
721
|
+
float *buf = alloca(samples*4*f->channels); /* de-interleave buffer */
|
|
722
|
+
long bytes_read = fread(buf,1,samples*4*f->channels, f->f);
|
|
723
|
+
int i,j;
|
|
724
|
+
opus_int64 realsamples;
|
|
725
|
+
|
|
726
|
+
if(f->totalsamples && f->samplesread +
|
|
727
|
+
bytes_read/(4*f->channels) > f->totalsamples)
|
|
728
|
+
bytes_read = 4*f->channels*(f->totalsamples - f->samplesread);
|
|
729
|
+
|
|
730
|
+
realsamples = bytes_read/(4*f->channels);
|
|
731
|
+
f->samplesread += realsamples;
|
|
732
|
+
|
|
733
|
+
for(i=0; i < realsamples; i++)
|
|
734
|
+
for(j=0; j < f->channels; j++)
|
|
735
|
+
buffer[i*f->channels+j] = buf[i*f->channels + f->channel_permute[j]];
|
|
736
|
+
|
|
737
|
+
return realsamples;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
void wav_close(void *info)
|
|
741
|
+
{
|
|
742
|
+
wavfile *f = (wavfile *)info;
|
|
743
|
+
free(f->channel_permute);
|
|
744
|
+
|
|
745
|
+
free(f);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
int raw_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
|
|
749
|
+
{
|
|
750
|
+
wav_fmt format; /* fake wave header ;) */
|
|
751
|
+
wavfile *wav = malloc(sizeof(wavfile));
|
|
752
|
+
int i;
|
|
753
|
+
(void)buf;/*unused*/
|
|
754
|
+
(void)buflen;/*unused*/
|
|
755
|
+
|
|
756
|
+
/* construct fake wav header ;) */
|
|
757
|
+
format.format = 2;
|
|
758
|
+
format.channels = opt->channels;
|
|
759
|
+
format.samplerate = opt->rate;
|
|
760
|
+
format.samplesize = opt->samplesize;
|
|
761
|
+
format.bytespersec = opt->channels * opt->rate * opt->samplesize / 8;
|
|
762
|
+
format.align = format.bytespersec;
|
|
763
|
+
wav->f = in;
|
|
764
|
+
wav->samplesread = 0;
|
|
765
|
+
wav->bigendian = opt->endianness;
|
|
766
|
+
wav->channels = format.channels;
|
|
767
|
+
wav->samplesize = opt->samplesize;
|
|
768
|
+
wav->totalsamples = 0;
|
|
769
|
+
wav->channel_permute = malloc(wav->channels * sizeof(int));
|
|
770
|
+
for (i=0; i < wav->channels; i++)
|
|
771
|
+
wav->channel_permute[i] = i;
|
|
772
|
+
|
|
773
|
+
opt->read_samples = wav_read;
|
|
774
|
+
opt->readdata = (void *)wav;
|
|
775
|
+
opt->total_samples_per_channel = 0; /* raw mode, don't bother */
|
|
776
|
+
return 1;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
typedef struct {
|
|
780
|
+
audio_read_func real_reader;
|
|
781
|
+
void *real_readdata;
|
|
782
|
+
int channels;
|
|
783
|
+
float scale_factor;
|
|
784
|
+
} scaler;
|
|
785
|
+
|
|
786
|
+
static long read_scaler(void *data, float *buffer, int samples) {
|
|
787
|
+
scaler *d = data;
|
|
788
|
+
long in_samples = d->real_reader(d->real_readdata, buffer, samples);
|
|
789
|
+
int i;
|
|
790
|
+
|
|
791
|
+
for(i=0; i < d->channels*in_samples; i++) {
|
|
792
|
+
buffer[i] *= d->scale_factor;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return in_samples;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
void setup_scaler(oe_enc_opt *opt, float scale) {
|
|
799
|
+
scaler *d = calloc(1, sizeof(scaler));
|
|
800
|
+
|
|
801
|
+
d->real_reader = opt->read_samples;
|
|
802
|
+
d->real_readdata = opt->readdata;
|
|
803
|
+
|
|
804
|
+
opt->read_samples = read_scaler;
|
|
805
|
+
opt->readdata = d;
|
|
806
|
+
d->channels = opt->channels;
|
|
807
|
+
d->scale_factor = scale;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
typedef struct {
|
|
811
|
+
audio_read_func real_reader;
|
|
812
|
+
void *real_readdata;
|
|
813
|
+
ogg_int64_t *original_samples;
|
|
814
|
+
int channels;
|
|
815
|
+
int lpc_ptr;
|
|
816
|
+
int *extra_samples;
|
|
817
|
+
float *lpc_out;
|
|
818
|
+
} padder;
|
|
819
|
+
|
|
820
|
+
static long read_padder(void *data, float *buffer, int samples) {
|
|
821
|
+
padder *d = data;
|
|
822
|
+
long in_samples = d->real_reader(d->real_readdata, buffer, samples);
|
|
823
|
+
int i, extra=0;
|
|
824
|
+
const int lpc_order=32;
|
|
825
|
+
|
|
826
|
+
if(d->original_samples)*d->original_samples+=in_samples;
|
|
827
|
+
|
|
828
|
+
if(in_samples<samples){
|
|
829
|
+
if(d->lpc_ptr<0){
|
|
830
|
+
d->lpc_out=calloc(d->channels * *d->extra_samples, sizeof(*d->lpc_out));
|
|
831
|
+
if(in_samples>lpc_order*2){
|
|
832
|
+
float *lpc=alloca(lpc_order*sizeof(*lpc));
|
|
833
|
+
for(i=0;i<d->channels;i++){
|
|
834
|
+
vorbis_lpc_from_data(buffer+i,lpc,in_samples,lpc_order,d->channels);
|
|
835
|
+
vorbis_lpc_predict(lpc,buffer+i+(in_samples-lpc_order)*d->channels,
|
|
836
|
+
lpc_order,d->lpc_out+i,*d->extra_samples,d->channels);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
d->lpc_ptr=0;
|
|
840
|
+
}
|
|
841
|
+
extra=samples-in_samples;
|
|
842
|
+
if(extra>*d->extra_samples)extra=*d->extra_samples;
|
|
843
|
+
*d->extra_samples-=extra;
|
|
844
|
+
}
|
|
845
|
+
memcpy(buffer+in_samples*d->channels,d->lpc_out+d->lpc_ptr*d->channels,extra*d->channels*sizeof(*buffer));
|
|
846
|
+
d->lpc_ptr+=extra;
|
|
847
|
+
return in_samples+extra;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
void setup_padder(oe_enc_opt *opt,ogg_int64_t *original_samples) {
|
|
851
|
+
padder *d = calloc(1, sizeof(padder));
|
|
852
|
+
|
|
853
|
+
d->real_reader = opt->read_samples;
|
|
854
|
+
d->real_readdata = opt->readdata;
|
|
855
|
+
|
|
856
|
+
opt->read_samples = read_padder;
|
|
857
|
+
opt->readdata = d;
|
|
858
|
+
d->channels = opt->channels;
|
|
859
|
+
d->extra_samples = &opt->extraout;
|
|
860
|
+
d->original_samples=original_samples;
|
|
861
|
+
d->lpc_ptr = -1;
|
|
862
|
+
d->lpc_out = NULL;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
void clear_padder(oe_enc_opt *opt) {
|
|
866
|
+
padder *d = opt->readdata;
|
|
867
|
+
|
|
868
|
+
opt->read_samples = d->real_reader;
|
|
869
|
+
opt->readdata = d->real_readdata;
|
|
870
|
+
|
|
871
|
+
if(d->lpc_out)free(d->lpc_out);
|
|
872
|
+
free(d);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
typedef struct {
|
|
876
|
+
SpeexResamplerState *resampler;
|
|
877
|
+
audio_read_func real_reader;
|
|
878
|
+
void *real_readdata;
|
|
879
|
+
float *bufs;
|
|
880
|
+
int channels;
|
|
881
|
+
int bufpos;
|
|
882
|
+
int bufsize;
|
|
883
|
+
int done;
|
|
884
|
+
} resampler;
|
|
885
|
+
|
|
886
|
+
static long read_resampled(void *d, float *buffer, int samples)
|
|
887
|
+
{
|
|
888
|
+
resampler *rs = d;
|
|
889
|
+
int out_samples=0;
|
|
890
|
+
float *pcmbuf;
|
|
891
|
+
int *inbuf;
|
|
892
|
+
pcmbuf=rs->bufs;
|
|
893
|
+
inbuf=&rs->bufpos;
|
|
894
|
+
while(out_samples<samples){
|
|
895
|
+
int i;
|
|
896
|
+
int reading, ret;
|
|
897
|
+
unsigned in_len, out_len;
|
|
898
|
+
reading=1024-*inbuf;
|
|
899
|
+
ret=rs->real_reader(rs->real_readdata, pcmbuf+*inbuf*rs->channels, reading);
|
|
900
|
+
*inbuf+=ret;
|
|
901
|
+
in_len=*inbuf;
|
|
902
|
+
out_len=samples-out_samples;
|
|
903
|
+
speex_resampler_process_interleaved_float(rs->resampler, pcmbuf, &in_len, buffer+out_samples*rs->channels, &out_len);
|
|
904
|
+
if(ret==0&&in_len==0){
|
|
905
|
+
for(i=out_samples*rs->channels;i<samples*rs->channels;i++)buffer[i]=0;
|
|
906
|
+
return out_samples;
|
|
907
|
+
}
|
|
908
|
+
out_samples+=out_len;
|
|
909
|
+
for(i=0;i<rs->channels*(*inbuf-(long int)in_len);i++)pcmbuf[i]=pcmbuf[i+rs->channels*in_len];
|
|
910
|
+
*inbuf-=in_len;
|
|
911
|
+
}
|
|
912
|
+
return out_samples;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
int setup_resample(oe_enc_opt *opt, int complexity, long outfreq) {
|
|
916
|
+
resampler *rs = calloc(1, sizeof(resampler));
|
|
917
|
+
int err;
|
|
918
|
+
|
|
919
|
+
rs->bufsize = 2048; /* Shrug */
|
|
920
|
+
rs->bufpos = 0;
|
|
921
|
+
|
|
922
|
+
rs->real_reader = opt->read_samples;
|
|
923
|
+
rs->real_readdata = opt->readdata;
|
|
924
|
+
rs->channels = opt->channels;
|
|
925
|
+
rs->done = 0;
|
|
926
|
+
rs->resampler = speex_resampler_init(rs->channels, opt->rate, outfreq, complexity, &err);
|
|
927
|
+
if(err!=0)fprintf(stderr, _("resampler error: %s\n"), speex_resampler_strerror(err));
|
|
928
|
+
|
|
929
|
+
opt->skip+=speex_resampler_get_output_latency(rs->resampler);
|
|
930
|
+
|
|
931
|
+
rs->bufs = malloc(sizeof(float) * rs->bufsize * opt->channels);
|
|
932
|
+
|
|
933
|
+
opt->read_samples = read_resampled;
|
|
934
|
+
opt->readdata = rs;
|
|
935
|
+
if(opt->total_samples_per_channel)
|
|
936
|
+
opt->total_samples_per_channel = (int)((float)opt->total_samples_per_channel *
|
|
937
|
+
((float)outfreq/(float)opt->rate));
|
|
938
|
+
opt->rate = outfreq;
|
|
939
|
+
|
|
940
|
+
return 0;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
void clear_resample(oe_enc_opt *opt) {
|
|
944
|
+
resampler *rs = opt->readdata;
|
|
945
|
+
|
|
946
|
+
opt->read_samples = rs->real_reader;
|
|
947
|
+
opt->readdata = rs->real_readdata;
|
|
948
|
+
speex_resampler_destroy(rs->resampler);
|
|
949
|
+
|
|
950
|
+
free(rs->bufs);
|
|
951
|
+
|
|
952
|
+
free(rs);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
typedef struct {
|
|
956
|
+
audio_read_func real_reader;
|
|
957
|
+
void *real_readdata;
|
|
958
|
+
float *bufs;
|
|
959
|
+
float *matrix;
|
|
960
|
+
int in_channels;
|
|
961
|
+
int out_channels;
|
|
962
|
+
} downmix;
|
|
963
|
+
|
|
964
|
+
static long read_downmix(void *data, float *buffer, int samples)
|
|
965
|
+
{
|
|
966
|
+
downmix *d = data;
|
|
967
|
+
long in_samples = d->real_reader(d->real_readdata, d->bufs, samples);
|
|
968
|
+
int i,j,k,in_ch,out_ch;
|
|
969
|
+
|
|
970
|
+
in_ch=d->in_channels;
|
|
971
|
+
out_ch=d->out_channels;
|
|
972
|
+
|
|
973
|
+
for(i=0;i<in_samples;i++){
|
|
974
|
+
for(j=0;j<out_ch;j++){
|
|
975
|
+
float *samp;
|
|
976
|
+
samp=&buffer[i*out_ch+j];
|
|
977
|
+
*samp=0;
|
|
978
|
+
for(k=0;k<in_ch;k++){
|
|
979
|
+
*samp+=d->bufs[i*in_ch+k]*d->matrix[in_ch*j+k];
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return in_samples;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
int setup_downmix(oe_enc_opt *opt, int out_channels) {
|
|
987
|
+
static const float stupid_matrix[7][8][2]={
|
|
988
|
+
/*2*/ {{1,0},{0,1}},
|
|
989
|
+
/*3*/ {{1,0},{0.7071f,0.7071f},{0,1}},
|
|
990
|
+
/*4*/ {{1,0},{0,1},{0.866f,0.5f},{0.5f,0.866f}},
|
|
991
|
+
/*5*/ {{1,0},{0.7071f,0.7071f},{0,1},{0.866f,0.5f},{0.5f,0.866f}},
|
|
992
|
+
/*6*/ {{1,0},{0.7071f,0.7071f},{0,1},{0.866f,0.5f},{0.5f,0.866f},{0.7071f,0.7071f}},
|
|
993
|
+
/*7*/ {{1,0},{0.7071f,0.7071f},{0,1},{0.866f,0.5f},{0.5f,0.866f},{0.6123f,0.6123f},{0.7071f,0.7071f}},
|
|
994
|
+
/*8*/ {{1,0},{0.7071f,0.7071f},{0,1},{0.866f,0.5f},{0.5f,0.866f},{0.866f,0.5f},{0.5f,0.866f},{0.7071f,0.7071f}},
|
|
995
|
+
};
|
|
996
|
+
float sum;
|
|
997
|
+
downmix *d;
|
|
998
|
+
int i,j;
|
|
999
|
+
|
|
1000
|
+
if(opt->channels<=out_channels || out_channels>2 || (out_channels==2&&opt->channels>8) || opt->channels<=0 || out_channels<=0) {
|
|
1001
|
+
fprintf(stderr, "Downmix must actually downmix and only knows mono/stereo out.\n");
|
|
1002
|
+
if(opt->channels>8)fprintf(stderr, "Downmix also only knows how to mix >8ch to mono.\n");
|
|
1003
|
+
return 0;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
d = calloc(1, sizeof(downmix));
|
|
1007
|
+
d->bufs = malloc(sizeof(float)*opt->channels*4096);
|
|
1008
|
+
d->matrix = malloc(sizeof(float)*opt->channels*out_channels);
|
|
1009
|
+
d->real_reader = opt->read_samples;
|
|
1010
|
+
d->real_readdata = opt->readdata;
|
|
1011
|
+
d->in_channels=opt->channels;
|
|
1012
|
+
d->out_channels=out_channels;
|
|
1013
|
+
|
|
1014
|
+
if(out_channels==1&&d->in_channels>8){
|
|
1015
|
+
for(i=0;i<d->in_channels;i++)d->matrix[i]=1.0f/d->in_channels;
|
|
1016
|
+
}else if(out_channels==2){
|
|
1017
|
+
for(j=0;j<d->out_channels;j++)
|
|
1018
|
+
for(i=0;i<d->in_channels;i++)d->matrix[d->in_channels*j+i]=
|
|
1019
|
+
stupid_matrix[opt->channels-2][i][j];
|
|
1020
|
+
}else{
|
|
1021
|
+
for(i=0;i<d->in_channels;i++)d->matrix[i]=
|
|
1022
|
+
(stupid_matrix[opt->channels-2][i][0])+
|
|
1023
|
+
(stupid_matrix[opt->channels-2][i][1]);
|
|
1024
|
+
}
|
|
1025
|
+
sum=0;
|
|
1026
|
+
for(i=0;i<d->in_channels*d->out_channels;i++)sum+=d->matrix[i];
|
|
1027
|
+
sum=(float)out_channels/sum;
|
|
1028
|
+
for(i=0;i<d->in_channels*d->out_channels;i++)d->matrix[i]*=sum;
|
|
1029
|
+
opt->read_samples = read_downmix;
|
|
1030
|
+
opt->readdata = d;
|
|
1031
|
+
|
|
1032
|
+
opt->channels = out_channels;
|
|
1033
|
+
return out_channels;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
void clear_downmix(oe_enc_opt *opt) {
|
|
1037
|
+
downmix *d = opt->readdata;
|
|
1038
|
+
|
|
1039
|
+
opt->read_samples = d->real_reader;
|
|
1040
|
+
opt->readdata = d->real_readdata;
|
|
1041
|
+
opt->channels = d->in_channels; /* other things in cleanup rely on this */
|
|
1042
|
+
|
|
1043
|
+
free(d->bufs);
|
|
1044
|
+
free(d->matrix);
|
|
1045
|
+
free(d);
|
|
1046
|
+
}
|