├── .github └── workflows │ ├── autotools.yml │ ├── cmake.yml │ ├── dred.yml │ └── repository.yml ├── .gitlab-ci.yml ├── .gitmodules ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── ChangeLog ├── LICENSE_PLEASE_READ.txt ├── Makefile.am ├── Makefile.mips ├── Makefile.unix ├── NEWS ├── README ├── README.draft ├── autogen.bat ├── autogen.sh ├── celt ├── _kiss_fft_guts.h ├── arch.h ├── arm │ ├── arm2gnu.pl │ ├── arm_celt_map.c │ ├── armcpu.c │ ├── armcpu.h │ ├── armopts.s.in │ ├── celt_fft_ne10.c │ ├── celt_mdct_ne10.c │ ├── celt_neon_intr.c │ ├── celt_pitch_xcorr_arm.s │ ├── fft_arm.h │ ├── fixed_arm64.h │ ├── fixed_armv4.h │ ├── fixed_armv5e.h │ ├── kiss_fft_armv4.h │ ├── kiss_fft_armv5e.h │ ├── mathops_arm.h │ ├── mdct_arm.h │ ├── meson.build │ ├── pitch_arm.h │ └── pitch_neon_intr.c ├── bands.c ├── bands.h ├── celt.c ├── celt.h ├── celt_decoder.c ├── celt_encoder.c ├── celt_lpc.c ├── celt_lpc.h ├── cpu_support.h ├── cwrs.c ├── cwrs.h ├── dump_modes │ ├── Makefile │ ├── dump_modes.c │ ├── dump_modes_arch.h │ └── dump_modes_arm_ne10.c ├── ecintrin.h ├── entcode.c ├── entcode.h ├── entdec.c ├── entdec.h ├── entenc.c ├── entenc.h ├── fixed_c5x.h ├── fixed_c6x.h ├── fixed_debug.h ├── fixed_generic.h ├── float_cast.h ├── kiss_fft.c ├── kiss_fft.h ├── laplace.c ├── laplace.h ├── mathops.c ├── mathops.h ├── mdct.c ├── mdct.h ├── meson.build ├── mfrngcod.h ├── mips │ ├── celt_mipsr1.h │ ├── fixed_generic_mipsr1.h │ ├── kiss_fft_mipsr1.h │ ├── mdct_mipsr1.h │ ├── pitch_mipsr1.h │ └── vq_mipsr1.h ├── modes.c ├── modes.h ├── opus_custom_demo.c ├── os_support.h ├── pitch.c ├── pitch.h ├── quant_bands.c ├── quant_bands.h ├── rate.c ├── rate.h ├── stack_alloc.h ├── static_modes_fixed.h ├── static_modes_fixed_arm_ne10.h ├── static_modes_float.h ├── static_modes_float_arm_ne10.h ├── tests │ ├── meson.build │ ├── test_unit_cwrs32.c │ ├── test_unit_dft.c │ ├── test_unit_entropy.c │ ├── test_unit_laplace.c │ ├── test_unit_mathops.c │ ├── test_unit_mdct.c │ ├── test_unit_rotation.c │ └── test_unit_types.c ├── vq.c ├── vq.h └── x86 │ ├── celt_lpc_sse.h │ ├── celt_lpc_sse4_1.c │ ├── pitch_avx.c │ ├── pitch_sse.c │ ├── pitch_sse.h │ ├── pitch_sse2.c │ ├── pitch_sse4_1.c │ ├── vq_sse.h │ ├── vq_sse2.c │ ├── x86_arch_macros.h │ ├── x86_celt_map.c │ ├── x86cpu.c │ └── x86cpu.h ├── celt_headers.mk ├── celt_sources.mk ├── cmake ├── CFeatureCheck.cmake ├── OpusBuildtype.cmake ├── OpusConfig.cmake ├── OpusConfig.cmake.in ├── OpusFunctions.cmake ├── OpusPackageVersion.cmake ├── OpusSources.cmake ├── README.md ├── RunTest.cmake ├── config.h.cmake.in ├── cpu_info_by_asm.c ├── cpu_info_by_c.c └── vla.c ├── configure.ac ├── dnn ├── LPCNet.yml ├── README ├── README.md ├── adaconvtest.c ├── arm │ ├── arm_dnn_map.c │ ├── dnn_arm.h │ ├── nnet_dotprod.c │ └── nnet_neon.c ├── burg.c ├── burg.h ├── common.h ├── datasets.txt ├── download_model.bat ├── download_model.sh ├── dred_coding.c ├── dred_coding.h ├── dred_config.h ├── dred_decoder.c ├── dred_decoder.h ├── dred_encoder.c ├── dred_encoder.h ├── dred_rdovae.h ├── dred_rdovae_dec.c ├── dred_rdovae_dec.h ├── dred_rdovae_enc.c ├── dred_rdovae_enc.h ├── dump_data.c ├── dump_lpcnet_tables.c ├── fargan.c ├── fargan.h ├── fargan_demo.c ├── freq.c ├── freq.h ├── fwgan.c ├── fwgan.h ├── kiss99.c ├── kiss99.h ├── lossgen.c ├── lossgen.h ├── lossgen_demo.c ├── lpcnet.c ├── lpcnet.h ├── lpcnet_enc.c ├── lpcnet_plc.c ├── lpcnet_private.h ├── lpcnet_tables.c ├── meson.build ├── nndsp.c ├── nndsp.h ├── nnet.c ├── nnet.h ├── nnet_arch.h ├── nnet_default.c ├── osce.c ├── osce.h ├── osce_config.h ├── osce_features.c ├── osce_features.h ├── osce_structs.h ├── parse_lpcnet_weights.c ├── pitchdnn.c ├── pitchdnn.h ├── tansig_table.h ├── test_vec.c ├── torch │ ├── dnntools │ │ ├── dnntools │ │ │ ├── __init__.py │ │ │ ├── quantization │ │ │ │ ├── __init__.py │ │ │ │ └── softquant.py │ │ │ ├── relegance │ │ │ │ ├── __init__.py │ │ │ │ ├── meta_critic.py │ │ │ │ └── relegance.py │ │ │ └── sparsification │ │ │ │ ├── __init__.py │ │ │ │ ├── base_sparsifier.py │ │ │ │ ├── common.py │ │ │ │ ├── conv1d_sparsifier.py │ │ │ │ ├── conv_transpose1d_sparsifier.py │ │ │ │ ├── gru_sparsifier.py │ │ │ │ ├── linear_sparsifier.py │ │ │ │ └── utils.py │ │ ├── requirements.txt │ │ └── setup.py │ ├── fargan │ │ ├── README.md │ │ ├── adv_train_fargan.py │ │ ├── dataset.py │ │ ├── dump_fargan_weights.py │ │ ├── fargan.py │ │ ├── filters.py │ │ ├── rc.py │ │ ├── stft_loss.py │ │ ├── test_fargan.py │ │ └── train_fargan.py │ ├── fwgan │ │ ├── dump_model_weights.py │ │ ├── inference.py │ │ └── models │ │ │ ├── __init__.py │ │ │ ├── fwgan400.py │ │ │ └── fwgan500.py │ ├── lossgen │ │ ├── README.md │ │ ├── export_lossgen.py │ │ ├── lossgen.py │ │ ├── process_data.sh │ │ ├── test_lossgen.py │ │ └── train_lossgen.py │ ├── lpcnet │ │ ├── README.md │ │ ├── add_dataset_config.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ └── lpcnet_dataset.py │ │ ├── engine │ │ │ └── lpcnet_engine.py │ │ ├── make_default_setup.py │ │ ├── make_test_config.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── lpcnet.py │ │ │ └── multi_rate_lpcnet.py │ │ ├── print_lpcnet_complexity.py │ │ ├── scripts │ │ │ ├── collect_multi_run_results.py │ │ │ ├── loop_run.sh │ │ │ ├── make_animation.py │ │ │ ├── modify_dataset_target.py │ │ │ ├── multi_run.sh │ │ │ ├── run_inference_test.sh │ │ │ ├── update_checkpoints.py │ │ │ ├── update_output_folder.sh │ │ │ └── update_setups.py │ │ ├── test_lpcnet.py │ │ ├── train_lpcnet.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── data.py │ │ │ ├── endoscopy.py │ │ │ ├── layers │ │ │ ├── __init__.py │ │ │ ├── dual_fc.py │ │ │ ├── pcm_embeddings.py │ │ │ └── subconditioner.py │ │ │ ├── misc.py │ │ │ ├── pcm.py │ │ │ ├── sample.py │ │ │ ├── sparsification │ │ │ ├── __init__.py │ │ │ ├── common.py │ │ │ └── gru_sparsifier.py │ │ │ ├── templates.py │ │ │ ├── ulaw.py │ │ │ └── wav.py │ ├── neural-pitch │ │ ├── README.md │ │ ├── data_augmentation.py │ │ ├── download_demand.sh │ │ ├── evaluation.py │ │ ├── experiments.py │ │ ├── export_neuralpitch_weights.py │ │ ├── models.py │ │ ├── neural_pitch_update.py │ │ ├── ptdb_process.sh │ │ ├── run_crepe.py │ │ ├── training.py │ │ └── utils.py │ ├── osce │ │ ├── README.md │ │ ├── adv_train_model.py │ │ ├── adv_train_vocoder.py │ │ ├── create_testvectors.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── lpcnet_vocoding_dataset.py │ │ │ ├── silk_conversion_set.py │ │ │ └── silk_enhancement_set.py │ │ ├── engine │ │ │ ├── engine.py │ │ │ └── vocoder_engine.py │ │ ├── export_model_weights.py │ │ ├── losses │ │ │ ├── stft_loss.py │ │ │ └── td_lowpass.py │ │ ├── make_default_setup.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── fd_discriminator.py │ │ │ ├── lace.py │ │ │ ├── lavoce.py │ │ │ ├── lavoce_400.py │ │ │ ├── lpcnet_feature_net.py │ │ │ ├── nns_base.py │ │ │ ├── no_lace.py │ │ │ ├── scale_embedding.py │ │ │ ├── shape_up_48.py │ │ │ ├── silk_feature_net.py │ │ │ └── silk_feature_net_pl.py │ │ ├── requirements.txt │ │ ├── resources │ │ │ ├── training_files.txt │ │ │ └── validation_files.txt │ │ ├── scripts │ │ │ └── concatenator.py │ │ ├── silk_16_to_48.py │ │ ├── stndrd │ │ │ ├── evaluation │ │ │ │ ├── commonvoice_clip_selection.py │ │ │ │ ├── create_input_data.sh │ │ │ │ ├── env.rc │ │ │ │ ├── evaluate.py │ │ │ │ ├── lace_loss_metric.py │ │ │ │ ├── make_boxplots.py │ │ │ │ ├── make_boxplots_moctest.py │ │ │ │ ├── make_tables.py │ │ │ │ ├── make_tables_moctest.py │ │ │ │ ├── moc.py │ │ │ │ ├── moc2.py │ │ │ │ ├── process_dataset.sh │ │ │ │ ├── run_nomad.py │ │ │ │ └── run_osce_test.py │ │ │ └── presentation │ │ │ │ ├── endoscopy.py │ │ │ │ ├── lace_demo.ipynb │ │ │ │ ├── linear_prediction.ipynb │ │ │ │ ├── playback.py │ │ │ │ ├── postfilter.ipynb │ │ │ │ └── spectrogram.ipynb │ │ ├── test_model.py │ │ ├── test_vocoder.py │ │ ├── train_model.py │ │ ├── train_vocoder.py │ │ └── utils │ │ │ ├── ada_conv.py │ │ │ ├── complexity.py │ │ │ ├── endoscopy.py │ │ │ ├── layers │ │ │ ├── fir.py │ │ │ ├── limited_adaptive_comb1d.py │ │ │ ├── limited_adaptive_conv1d.py │ │ │ ├── noise_shaper.py │ │ │ ├── pitch_auto_correlator.py │ │ │ ├── silk_upsampler.py │ │ │ └── td_shaper.py │ │ │ ├── lpcnet_features.py │ │ │ ├── misc.py │ │ │ ├── moc.py │ │ │ ├── pitch.py │ │ │ ├── silk_features.py │ │ │ ├── softquant.py │ │ │ ├── spec.py │ │ │ └── templates.py │ ├── plc │ │ ├── export_plc.py │ │ ├── plc.py │ │ ├── plc_dataset.py │ │ └── train_plc.py │ ├── rdovae │ │ ├── README.md │ │ ├── download_datasets.sh │ │ ├── export_rdovae_weights.py │ │ ├── fec_encoder.py │ │ ├── import_rdovae_weights.py │ │ ├── packets │ │ │ ├── __init__.py │ │ │ ├── fec_packets.c │ │ │ ├── fec_packets.h │ │ │ └── fec_packets.py │ │ ├── process_speech.sh │ │ ├── rdovae │ │ │ ├── __init__.py │ │ │ ├── dataset.py │ │ │ └── rdovae.py │ │ ├── requirements.txt │ │ └── train_rdovae.py │ ├── testsuite │ │ ├── README.md │ │ ├── examples │ │ │ ├── lpcnet_c_example.yml │ │ │ ├── lpcnet_c_plc_example.yml │ │ │ └── lpcnet_torch_example.yml │ │ ├── requirements.txt │ │ ├── run_test.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── files.py │ │ │ ├── pesq.py │ │ │ └── pitch.py │ └── weight-exchange │ │ ├── README.md │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── wexchange │ │ ├── __init__.py │ │ ├── c_export │ │ ├── __init__.py │ │ ├── c_writer.py │ │ └── common.py │ │ ├── tf │ │ ├── __init__.py │ │ └── tf.py │ │ └── torch │ │ ├── __init__.py │ │ └── torch.py ├── training_tf2 │ ├── dataloader.py │ ├── decode_rdovae.py │ ├── diffembed.py │ ├── dump_lpcnet.py │ ├── dump_plc.py │ ├── dump_rdovae.py │ ├── encode_rdovae.py │ ├── fec_encoder.py │ ├── fec_packets.c │ ├── fec_packets.h │ ├── fec_packets.py │ ├── keraslayerdump.py │ ├── lossfuncs.py │ ├── lpcnet.py │ ├── lpcnet_plc.py │ ├── mdense.py │ ├── pade.py │ ├── parameters.py │ ├── plc_loader.py │ ├── rdovae.py │ ├── rdovae_exchange.py │ ├── rdovae_import.py │ ├── test_lpcnet.py │ ├── test_plc.py │ ├── tf_funcs.py │ ├── train_lpcnet.py │ ├── train_plc.py │ ├── train_rdovae.py │ ├── ulaw.py │ └── uniform_noise.py ├── vec.h ├── vec_avx.h ├── vec_neon.h ├── write_lpcnet_weights.c └── x86 │ ├── dnn_x86.h │ ├── nnet_avx2.c │ ├── nnet_sse2.c │ ├── nnet_sse4_1.c │ └── x86_dnn_map.c ├── doc ├── Doxyfile.in ├── Makefile.am ├── build_draft.sh ├── build_isobmff.sh ├── build_oggdraft.sh ├── customdoxygen.css ├── draft-ietf-codec-oggopus.xml ├── draft-ietf-codec-opus-update.xml ├── draft-ietf-codec-opus.xml ├── draft-ietf-payload-rtp-opus.xml ├── footer.html ├── header.html ├── meson.build ├── opus_in_isobmff.css ├── opus_in_isobmff.html ├── opus_logo.svg ├── opus_update.patch ├── release.txt └── trivial_example.c ├── include ├── meson.build ├── opus.h ├── opus_custom.h ├── opus_defines.h ├── opus_multistream.h ├── opus_projection.h └── opus_types.h ├── lpcnet_headers.mk ├── lpcnet_sources.mk ├── m4 ├── as-gcc-inline-assembly.m4 ├── ax_add_fortify_source.m4 └── opus-intrinsics.m4 ├── meson.build ├── meson ├── README.md ├── get-version.py └── read-sources-list.py ├── meson_options.txt ├── opus-uninstalled.pc.in ├── opus.m4 ├── opus.pc.in ├── opus_headers.mk ├── opus_sources.mk ├── releases.sha2 ├── scripts ├── dump_rnn.py ├── local_build.py ├── rnn_train.py └── shrink_model.sh ├── silk ├── A2NLSF.c ├── API.h ├── CNG.c ├── HP_variable_cutoff.c ├── Inlines.h ├── LPC_analysis_filter.c ├── LPC_fit.c ├── LPC_inv_pred_gain.c ├── LP_variable_cutoff.c ├── MacroCount.h ├── MacroDebug.h ├── NLSF2A.c ├── NLSF_VQ.c ├── NLSF_VQ_weights_laroia.c ├── NLSF_decode.c ├── NLSF_del_dec_quant.c ├── NLSF_encode.c ├── NLSF_stabilize.c ├── NLSF_unpack.c ├── NSQ.c ├── NSQ.h ├── NSQ_del_dec.c ├── PLC.c ├── PLC.h ├── SigProc_FIX.h ├── VAD.c ├── VQ_WMat_EC.c ├── ana_filt_bank_1.c ├── arm │ ├── LPC_inv_pred_gain_arm.h │ ├── LPC_inv_pred_gain_neon_intr.c │ ├── NSQ_del_dec_arm.h │ ├── NSQ_del_dec_neon_intr.c │ ├── NSQ_neon.c │ ├── NSQ_neon.h │ ├── SigProc_FIX_armv4.h │ ├── SigProc_FIX_armv5e.h │ ├── arm_silk_map.c │ ├── biquad_alt_arm.h │ ├── biquad_alt_neon_intr.c │ ├── macros_arm64.h │ ├── macros_armv4.h │ └── macros_armv5e.h ├── biquad_alt.c ├── bwexpander.c ├── bwexpander_32.c ├── check_control_input.c ├── code_signs.c ├── control.h ├── control_SNR.c ├── control_audio_bandwidth.c ├── control_codec.c ├── debug.c ├── debug.h ├── dec_API.c ├── decode_core.c ├── decode_frame.c ├── decode_indices.c ├── decode_parameters.c ├── decode_pitch.c ├── decode_pulses.c ├── decoder_set_fs.c ├── define.h ├── enc_API.c ├── encode_indices.c ├── encode_pulses.c ├── errors.h ├── fixed │ ├── LTP_analysis_filter_FIX.c │ ├── LTP_scale_ctrl_FIX.c │ ├── apply_sine_window_FIX.c │ ├── arm │ │ ├── warped_autocorrelation_FIX_arm.h │ │ └── warped_autocorrelation_FIX_neon_intr.c │ ├── autocorr_FIX.c │ ├── burg_modified_FIX.c │ ├── corrMatrix_FIX.c │ ├── encode_frame_FIX.c │ ├── find_LPC_FIX.c │ ├── find_LTP_FIX.c │ ├── find_pitch_lags_FIX.c │ ├── find_pred_coefs_FIX.c │ ├── k2a_FIX.c │ ├── k2a_Q16_FIX.c │ ├── main_FIX.h │ ├── mips │ │ ├── noise_shape_analysis_FIX_mipsr1.h │ │ ├── prefilter_FIX_mipsr1.h │ │ └── warped_autocorrelation_FIX_mipsr1.h │ ├── noise_shape_analysis_FIX.c │ ├── pitch_analysis_core_FIX.c │ ├── process_gains_FIX.c │ ├── regularize_correlations_FIX.c │ ├── residual_energy16_FIX.c │ ├── residual_energy_FIX.c │ ├── schur64_FIX.c │ ├── schur_FIX.c │ ├── structs_FIX.h │ ├── vector_ops_FIX.c │ ├── warped_autocorrelation_FIX.c │ └── x86 │ │ ├── burg_modified_FIX_sse4_1.c │ │ └── vector_ops_FIX_sse4_1.c ├── float │ ├── LPC_analysis_filter_FLP.c │ ├── LPC_inv_pred_gain_FLP.c │ ├── LTP_analysis_filter_FLP.c │ ├── LTP_scale_ctrl_FLP.c │ ├── SigProc_FLP.h │ ├── apply_sine_window_FLP.c │ ├── autocorrelation_FLP.c │ ├── burg_modified_FLP.c │ ├── bwexpander_FLP.c │ ├── corrMatrix_FLP.c │ ├── encode_frame_FLP.c │ ├── energy_FLP.c │ ├── find_LPC_FLP.c │ ├── find_LTP_FLP.c │ ├── find_pitch_lags_FLP.c │ ├── find_pred_coefs_FLP.c │ ├── inner_product_FLP.c │ ├── k2a_FLP.c │ ├── main_FLP.h │ ├── noise_shape_analysis_FLP.c │ ├── pitch_analysis_core_FLP.c │ ├── process_gains_FLP.c │ ├── regularize_correlations_FLP.c │ ├── residual_energy_FLP.c │ ├── scale_copy_vector_FLP.c │ ├── scale_vector_FLP.c │ ├── schur_FLP.c │ ├── sort_FLP.c │ ├── structs_FLP.h │ ├── warped_autocorrelation_FLP.c │ ├── wrappers_FLP.c │ └── x86 │ │ └── inner_product_FLP_avx2.c ├── gain_quant.c ├── init_decoder.c ├── init_encoder.c ├── inner_prod_aligned.c ├── interpolate.c ├── lin2log.c ├── log2lin.c ├── macros.h ├── main.h ├── meson.build ├── mips │ ├── NSQ_del_dec_mipsr1.h │ ├── macros_mipsr1.h │ └── sigproc_fix_mipsr1.h ├── pitch_est_defines.h ├── pitch_est_tables.c ├── process_NLSFs.c ├── quant_LTP_gains.c ├── resampler.c ├── resampler_down2.c ├── resampler_down2_3.c ├── resampler_private.h ├── resampler_private_AR2.c ├── resampler_private_IIR_FIR.c ├── resampler_private_down_FIR.c ├── resampler_private_up2_HQ.c ├── resampler_rom.c ├── resampler_rom.h ├── resampler_structs.h ├── shell_coder.c ├── sigm_Q15.c ├── sort.c ├── stereo_LR_to_MS.c ├── stereo_MS_to_LR.c ├── stereo_decode_pred.c ├── stereo_encode_pred.c ├── stereo_find_predictor.c ├── stereo_quant_pred.c ├── structs.h ├── sum_sqr_shift.c ├── table_LSF_cos.c ├── tables.h ├── tables_LTP.c ├── tables_NLSF_CB_NB_MB.c ├── tables_NLSF_CB_WB.c ├── tables_gain.c ├── tables_other.c ├── tables_pitch_lag.c ├── tables_pulses_per_block.c ├── tests │ ├── meson.build │ └── test_unit_LPC_inv_pred_gain.c ├── tuning_parameters.h ├── typedef.h ├── x86 │ ├── NSQ_del_dec_avx2.c │ ├── NSQ_del_dec_sse4_1.c │ ├── NSQ_sse4_1.c │ ├── SigProc_FIX_sse.h │ ├── VAD_sse4_1.c │ ├── VQ_WMat_EC_sse4_1.c │ ├── main_sse.h │ └── x86_silk_map.c └── xtensa │ ├── SigProc_FIX_lx7.h │ └── macros_lx7.h ├── silk_headers.mk ├── silk_sources.mk ├── src ├── analysis.c ├── analysis.h ├── extensions.c ├── mapping_matrix.c ├── mapping_matrix.h ├── meson.build ├── mlp.c ├── mlp.h ├── mlp_data.c ├── opus.c ├── opus_compare.c ├── opus_decoder.c ├── opus_demo.c ├── opus_encoder.c ├── opus_multistream.c ├── opus_multistream_decoder.c ├── opus_multistream_encoder.c ├── opus_private.h ├── opus_projection_decoder.c ├── opus_projection_encoder.c ├── repacketizer.c ├── repacketizer_demo.c └── tansig_table.h ├── tar_list.txt ├── tests ├── meson.build ├── opus_build_test.sh ├── opus_decode_fuzzer.c ├── opus_decode_fuzzer.options ├── opus_encode_regressions.c ├── random_config.sh ├── run_vectors.sh ├── test_opus_api.c ├── test_opus_common.h ├── test_opus_custom.c ├── test_opus_decode.c ├── test_opus_dred.c ├── test_opus_encode.c ├── test_opus_extensions.c ├── test_opus_padding.c └── test_opus_projection.c └── training ├── rnn_dump.py ├── rnn_train.py └── txt2hdf5.py /.github/workflows/autotools.yml: -------------------------------------------------------------------------------- 1 | name: Autotools 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | 7 | AutoMakeBuild: 8 | name: AutoMake/${{ matrix.config.name }} 9 | runs-on: ${{ matrix.config.os }} 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | config: 14 | - { 15 | name: "Linux/GCC", 16 | os: ubuntu-latest, 17 | compiler: gcc, 18 | automakeconfig: 19 | } 20 | - { 21 | name: "Linux/GCC/EnableAssertions", 22 | os: ubuntu-latest, 23 | compiler: gcc, 24 | buildconfig: --enable-assertions 25 | } 26 | - { 27 | name: "Linux/GCC/EnableCustomModes", 28 | os: ubuntu-latest, 29 | compiler: gcc, 30 | buildconfig: --enable-assertions --enable-custom-modes 31 | } 32 | - { 33 | name: "Linux/GCC/EnableDNN", 34 | os: ubuntu-latest, 35 | compiler: gcc, 36 | buildconfig: --enable-assertions --enable-custom-modes --enable-dred --enable-osce 37 | } 38 | steps: 39 | - uses: actions/checkout@v3 40 | # No AutoMake on Mac so let's install it 41 | - name: Install AutoConf, AutoMake and LibTool on MacOSX 42 | if: matrix.config.os == 'macos-latest' 43 | run: brew install autoconf automake libtool 44 | - name: Autogen 45 | run: CC=${{ matrix.config.compiler }} ./autogen.sh 46 | - name: Configure 47 | run: CFLAGS="-mavx -mfma -mavx2 -O2 -ffast-math" ./configure --enable-float-approx ${{ matrix.config.buildconfig }} 48 | - name: Build 49 | run: make -j 2 50 | - name: Test 51 | run: make check -j 2 52 | -------------------------------------------------------------------------------- /.github/workflows/repository.yml: -------------------------------------------------------------------------------- 1 | name: Repository 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | CheckTrailingWhiteSpaces: 7 | name: Check trailing white spaces 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | with: 12 | fetch-depth: 0 13 | - name: Check Whitespaces 14 | run: | 15 | git diff-tree --check origin/opus-ng HEAD 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiph/opus/2941f08a616290f291579df9c8dbc0801d8d3f18/.gitmodules -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jean-Marc Valin (jmvalin@jmvalin.ca) 2 | Koen Vos (koenvos74@gmail.com) 3 | Timothy Terriberry (tterribe@xiph.org) 4 | Karsten Vandborg Sorensen (karsten.vandborg.sorensen@skype.net) 5 | Soren Skak Jensen (ssjensen@gn.com) 6 | Gregory Maxwell (greg@xiph.org) 7 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic, 2 | Jean-Marc Valin, Timothy B. Terriberry, 3 | CSIRO, Gregory Maxwell, Mark Borgerding, 4 | Erik de Castro Lopo, Mozilla, Amazon 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 18 | names of specific contributors, may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | 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 COPYRIGHT OWNER 26 | OR 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 | Opus is subject to the royalty-free patent licenses which are 35 | specified at: 36 | 37 | Xiph.Org Foundation: 38 | https://datatracker.ietf.org/ipr/1524/ 39 | 40 | Microsoft Corporation: 41 | https://datatracker.ietf.org/ipr/1914/ 42 | 43 | Broadcom Corporation: 44 | https://datatracker.ietf.org/ipr/1526/ 45 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiph/opus/2941f08a616290f291579df9c8dbc0801d8d3f18/ChangeLog -------------------------------------------------------------------------------- /LICENSE_PLEASE_READ.txt: -------------------------------------------------------------------------------- 1 | Contributions to the collaboration shall not be considered confidential. 2 | 3 | Each contributor represents and warrants that it has the right and 4 | authority to license copyright in its contributions to the collaboration. 5 | 6 | Each contributor agrees to license the copyright in the contributions 7 | under the Modified (2-clause or 3-clause) BSD License or the Clear BSD License. 8 | 9 | Please see the IPR statements submitted to the IETF for the complete 10 | patent licensing details: 11 | 12 | Xiph.Org Foundation: 13 | https://datatracker.ietf.org/ipr/1524/ 14 | 15 | Microsoft Corporation: 16 | https://datatracker.ietf.org/ipr/1914/ 17 | 18 | Skype Limited: 19 | https://datatracker.ietf.org/ipr/1602/ 20 | 21 | Broadcom Corporation: 22 | https://datatracker.ietf.org/ipr/1526/ 23 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiph/opus/2941f08a616290f291579df9c8dbc0801d8d3f18/NEWS -------------------------------------------------------------------------------- /README.draft: -------------------------------------------------------------------------------- 1 | To build this source code, simply type: 2 | 3 | % make 4 | 5 | If this does not work, or if you want to change the default configuration 6 | (e.g., to compile for a fixed-point architecture), simply edit the options 7 | in the Makefile. 8 | 9 | An up-to-date implementation conforming to this standard is available in a 10 | Git repository at https://gitlab.xiph.org/xiph/opus.git or on a website at: 11 | https://opus-codec.org/ 12 | However, although that implementation is expected to remain conformant 13 | with the standard, it is the code in this RFC that shall remain normative. 14 | To build from the git repository instead of using this RFC, follow these 15 | steps: 16 | 17 | 1) Clone the repository (latest implementation of this standard at the time 18 | of publication) 19 | 20 | % git clone https://gitlab.xiph.org/xiph/opus.git 21 | % cd opus 22 | 23 | 2) Compile 24 | 25 | % ./autogen.sh 26 | % ./configure 27 | % make 28 | 29 | Once you have compiled the codec, there will be a opus_demo executable in 30 | the top directory. 31 | 32 | Usage: opus_demo [-e] 33 | [options] 34 | opus_demo -d [options] 35 | 36 | 37 | mode: voip | audio | restricted-lowdelay 38 | options: 39 | -e : only runs the encoder (output the bit-stream) 40 | -d : only runs the decoder (reads the bit-stream as input) 41 | -cbr : enable constant bitrate; default: variable bitrate 42 | -cvbr : enable constrained variable bitrate; default: unconstrained 43 | -bandwidth : audio bandwidth (from narrowband to fullband); 44 | default: sampling rate 45 | -framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20 46 | -max_payload : maximum payload size in bytes, default: 1024 47 | -complexity : complexity, 0 (lowest) ... 10 (highest); default: 10 48 | -inbandfec : enable SILK inband FEC 49 | -forcemono : force mono encoding, even for stereo input 50 | -dtx : enable SILK DTX 51 | -loss : simulate packet loss, in percent (0-100); default: 0 52 | 53 | input and output are little endian signed 16-bit PCM files or opus bitstreams 54 | with simple opus_demo proprietary framing. 55 | -------------------------------------------------------------------------------- /autogen.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Run this to set up the build system: configure, makefiles, etc. 3 | 4 | setlocal enabledelayedexpansion 5 | 6 | REM Parse the real autogen.sh script for version 7 | for /F "tokens=2 delims= " %%A in ('findstr "dnn/download_model.sh" autogen.sh') do ( 8 | set "model=%%A" 9 | ) 10 | 11 | call dnn\download_model.bat %model% 12 | 13 | echo Updating build configuration files, please wait.... 14 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2010-2015 Xiph.Org Foundation and contributors. 3 | # Use of this source code is governed by a BSD-style license that can be 4 | # found in the COPYING file. 5 | 6 | # Run this to set up the build system: configure, makefiles, etc. 7 | set -e 8 | 9 | srcdir=`dirname $0` 10 | test -n "$srcdir" && cd "$srcdir" 11 | 12 | dnn/download_model.sh "a86f0a9db852691d4335608733ec8384a407e585801ab9e4b490e0be297ac382" 13 | 14 | echo "Updating build configuration files, please wait...." 15 | 16 | autoreconf -isf 17 | -------------------------------------------------------------------------------- /celt/arm/armopts.s.in: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Mozilla Corporation */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | ; Set the following to 1 if we have EDSP instructions 28 | ; (LDRD/STRD, etc., ARMv5E and later). 29 | OPUS_ARM_MAY_HAVE_EDSP * @OPUS_ARM_MAY_HAVE_EDSP@ 30 | 31 | ; Set the following to 1 if we have ARMv6 media instructions. 32 | OPUS_ARM_MAY_HAVE_MEDIA * @OPUS_ARM_MAY_HAVE_MEDIA@ 33 | 34 | ; Set the following to 1 if we have NEON (some ARMv7) 35 | OPUS_ARM_MAY_HAVE_NEON * @OPUS_ARM_MAY_HAVE_NEON@ 36 | 37 | END 38 | -------------------------------------------------------------------------------- /celt/arm/fixed_arm64.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Vidyo */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef FIXED_ARM64_H 28 | #define FIXED_ARM64_H 29 | 30 | #include 31 | 32 | #undef SIG2WORD16 33 | #define SIG2WORD16(x) (vqmovns_s32(PSHR32((x), SIG_SHIFT))) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /celt/arm/meson.build: -------------------------------------------------------------------------------- 1 | arm2gnu = [find_program('arm2gnu.pl')] + arm2gnu_args 2 | celt_sources_arm_asm = configure_file(input: 'celt_pitch_xcorr_arm.s', 3 | output: '@BASENAME@-gnu.S', 4 | command: arm2gnu + ['@INPUT@'], 5 | capture: true) 6 | celt_arm_armopts_s_in = configure_file(input: 'armopts.s.in', 7 | output: 'armopts.s', 8 | configuration: opus_conf) 9 | celt_arm_armopts_s = configure_file(input: [celt_arm_armopts_s_in], 10 | output: '@BASENAME@-gnu.S', 11 | command: arm2gnu + ['@INPUT@'], 12 | capture: true) 13 | -------------------------------------------------------------------------------- /celt/celt_lpc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009-2010 Xiph.Org Foundation 2 | Written by Jean-Marc Valin */ 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 COPYRIGHT OWNER 19 | OR 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 PLC_H 29 | #define PLC_H 30 | 31 | #include "arch.h" 32 | #include "cpu_support.h" 33 | 34 | #if defined(OPUS_X86_MAY_HAVE_SSE4_1) 35 | #include "x86/celt_lpc_sse.h" 36 | #endif 37 | 38 | #define CELT_LPC_ORDER 24 39 | 40 | void _celt_lpc(opus_val16 *_lpc, const opus_val32 *ac, int p); 41 | 42 | void celt_fir_c( 43 | const opus_val16 *x, 44 | const opus_val16 *num, 45 | opus_val16 *y, 46 | int N, 47 | int ord, 48 | int arch); 49 | 50 | #if !defined(OVERRIDE_CELT_FIR) 51 | #define celt_fir(x, num, y, N, ord, arch) \ 52 | (celt_fir_c(x, num, y, N, ord, arch)) 53 | #endif 54 | 55 | void celt_iir(const opus_val32 *x, 56 | const opus_val16 *den, 57 | opus_val32 *y, 58 | int N, 59 | int ord, 60 | opus_val16 *mem, 61 | int arch); 62 | 63 | int _celt_autocorr(const opus_val16 *x, opus_val32 *ac, 64 | const celt_coef *window, int overlap, int lag, int n, int arch); 65 | 66 | #endif /* PLC_H */ 67 | -------------------------------------------------------------------------------- /celt/cwrs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Copyright (c) 2007-2009 Timothy B. Terriberry 4 | Written by Timothy B. Terriberry and Jean-Marc Valin */ 5 | /* 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef CWRS_H 31 | #define CWRS_H 32 | 33 | #include "arch.h" 34 | #include "stack_alloc.h" 35 | #include "entenc.h" 36 | #include "entdec.h" 37 | 38 | #ifdef CUSTOM_MODES 39 | int log2_frac(opus_uint32 val, int frac); 40 | #endif 41 | 42 | void get_required_bits(opus_int16 *bits, int N, int K, int frac); 43 | 44 | void encode_pulses(const int *_y, int N, int K, ec_enc *enc); 45 | 46 | opus_val32 decode_pulses(int *_y, int N, int K, ec_dec *dec); 47 | 48 | #endif /* CWRS_H */ 49 | -------------------------------------------------------------------------------- /celt/dump_modes/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CFLAGS=-O2 -Wall -Wextra -DHAVE_CONFIG_H 3 | INCLUDES=-I. -I../ -I../.. -I../../include 4 | 5 | SOURCES = dump_modes.c \ 6 | ../modes.c \ 7 | ../cwrs.c \ 8 | ../rate.c \ 9 | ../entcode.c \ 10 | ../entenc.c \ 11 | ../entdec.c \ 12 | ../mathops.c \ 13 | ../mdct.c \ 14 | ../celt.c \ 15 | ../kiss_fft.c 16 | 17 | ifdef HAVE_ARM_NE10 18 | CC = gcc 19 | CFLAGS += -mfpu=neon 20 | INCLUDES += -I$(NE10_INCDIR) -DHAVE_ARM_NE10 -DOPUS_ARM_PRESUME_NEON_INTR 21 | LIBS = -L$(NE10_LIBDIR) -lNE10 22 | SOURCES += ../arm/celt_ne10_fft.c \ 23 | dump_modes_arm_ne10.c \ 24 | ../arm/armcpu.c 25 | endif 26 | 27 | all: dump_modes 28 | 29 | dump_modes: 30 | $(PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -DCUSTOM_MODES_ONLY -DCUSTOM_MODES $(SOURCES) -o $@ $(LIBS) -lm 31 | 32 | clean: 33 | rm -f dump_modes 34 | -------------------------------------------------------------------------------- /celt/dump_modes/dump_modes_arch.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Xiph.Org Foundation 2 | Written by Viswanath Puttagunta */ 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 COPYRIGHT OWNER 19 | OR 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 DUMP_MODE_ARCH_H 29 | #define DUMP_MODE_ARCH_H 30 | 31 | void dump_modes_arch_init(); 32 | void dump_mode_arch(CELTMode *mode); 33 | void dump_modes_arch_finalize(); 34 | 35 | #if !defined(FIXED_POINT) 36 | #define ARM_NE10_ARCH_FILE_NAME "static_modes_float_arm_ne10.h" 37 | #else 38 | #define ARM_NE10_ARCH_FILE_NAME "static_modes_fixed_arm_ne10.h" 39 | #endif 40 | 41 | #if defined(HAVE_ARM_NE10) 42 | #define OVERRIDE_FFT (1) 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /celt/fixed_c6x.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2008 CSIRO */ 2 | /** 3 | @file fixed_c6x.h 4 | @brief Fixed-point operations for the TI C6x DSP family 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 | 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 COPYRIGHT OWNER 22 | OR 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 | #ifndef FIXED_C6X_H 32 | #define FIXED_C6X_H 33 | 34 | #undef MULT16_16SU 35 | #define MULT16_16SU(a,b) _mpysu(a,b) 36 | 37 | #undef MULT_16_16 38 | #define MULT_16_16(a,b) _mpy(a,b) 39 | 40 | #define celt_ilog2(x) (30 - _norm(x)) 41 | #define OVERRIDE_CELT_ILOG2 42 | 43 | #undef MULT16_32_Q15 44 | #define MULT16_32_Q15(a,b) (_mpylill(a, b) >> 15) 45 | 46 | #if 0 47 | #include "dsplib.h" 48 | 49 | #undef MAX16 50 | #define MAX16(a,b) _max(a,b) 51 | 52 | #undef MIN16 53 | #define MIN16(a,b) _min(a,b) 54 | 55 | #undef MAX32 56 | #define MAX32(a,b) _lmax(a,b) 57 | 58 | #undef MIN32 59 | #define MIN32(a,b) _lmin(a,b) 60 | 61 | #undef VSHR32 62 | #define VSHR32(a, shift) _lshl(a,-(shift)) 63 | 64 | #undef MULT16_16_Q15 65 | #define MULT16_16_Q15(a,b) (_smpy(a,b)) 66 | 67 | #define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len))) 68 | #define OVERRIDE_CELT_MAXABS16 69 | 70 | #endif /* FIXED_C6X_H */ 71 | -------------------------------------------------------------------------------- /celt/meson.build: -------------------------------------------------------------------------------- 1 | celt_sources = sources['CELT_SOURCES'] 2 | 3 | celt_sse_sources = sources['CELT_SOURCES_SSE'] 4 | 5 | celt_sse2_sources = sources['CELT_SOURCES_SSE2'] 6 | 7 | celt_sse4_1_sources = sources['CELT_SOURCES_SSE4_1'] 8 | 9 | celt_avx2_sources = sources['CELT_SOURCES_AVX2'] 10 | 11 | celt_neon_intr_sources = sources['CELT_SOURCES_ARM_NEON_INTR'] 12 | 13 | celt_static_libs = [] 14 | 15 | if host_cpu_family in ['x86', 'x86_64'] and opus_conf.has('OPUS_HAVE_RTCD') 16 | celt_sources += sources['CELT_SOURCES_X86_RTCD'] 17 | endif 18 | 19 | foreach intr_name : ['sse', 'sse2', 'sse4_1', 'avx2', 'neon_intr'] 20 | have_intr = get_variable('have_' + intr_name) 21 | if not have_intr 22 | continue 23 | endif 24 | 25 | intr_sources = get_variable('celt_@0@_sources'.format(intr_name)) 26 | intr_args = get_variable('opus_@0@_args'.format(intr_name), []) 27 | celt_static_libs += static_library('celt_' + intr_name, intr_sources, 28 | c_args: intr_args, 29 | include_directories: opus_includes, 30 | install: false) 31 | endforeach 32 | 33 | have_arm_intrinsics_or_asm = have_arm_ne10 34 | if (intrinsics_support.length() + asm_optimization.length() + inline_optimization.length()) > 0 35 | have_arm_intrinsics_or_asm = true 36 | endif 37 | 38 | if host_cpu_family in ['arm', 'aarch64'] and have_arm_intrinsics_or_asm 39 | if opus_conf.has('OPUS_HAVE_RTCD') 40 | celt_sources += sources['CELT_SOURCES_ARM_RTCD'] 41 | endif 42 | if have_arm_ne10 43 | celt_sources += sources['CELT_SOURCES_ARM_NE10'] 44 | endif 45 | if opus_arm_external_asm 46 | subdir('arm') 47 | celt_static_libs += static_library('celt-armasm', 48 | celt_arm_armopts_s, celt_sources_arm_asm, 49 | install: false) 50 | endif 51 | endif 52 | 53 | celt_c_args = [] 54 | if host_system == 'windows' 55 | celt_c_args += ['-DDLL_EXPORT'] 56 | endif 57 | 58 | celt_lib = static_library('opus-celt', 59 | celt_sources, 60 | c_args: celt_c_args, 61 | include_directories: opus_includes, 62 | link_whole: celt_static_libs, 63 | dependencies: libm, 64 | install: false) 65 | -------------------------------------------------------------------------------- /celt/mfrngcod.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2001-2008 Timothy B. Terriberry 2 | Copyright (c) 2008-2009 Xiph.Org Foundation */ 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 COPYRIGHT OWNER 19 | OR 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 | #if !defined(_mfrngcode_H) 29 | # define _mfrngcode_H (1) 30 | # include "entcode.h" 31 | 32 | /*Constants used by the entropy encoder/decoder.*/ 33 | 34 | /*The number of bits to output at a time.*/ 35 | # define EC_SYM_BITS (8) 36 | /*The total number of bits in each of the state registers.*/ 37 | # define EC_CODE_BITS (32) 38 | /*The maximum symbol value.*/ 39 | # define EC_SYM_MAX ((1U<>EC_SYM_BITS) 46 | /*The number of bits available for the last, partial symbol in the code field.*/ 47 | # define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1) 48 | #endif 49 | -------------------------------------------------------------------------------- /celt/tests/meson.build: -------------------------------------------------------------------------------- 1 | tests = [ 2 | 'test_unit_types', 3 | 'test_unit_mathops', 4 | 'test_unit_entropy', 5 | 'test_unit_laplace', 6 | 'test_unit_dft', 7 | 'test_unit_mdct', 8 | 'test_unit_rotation', 9 | 'test_unit_cwrs32', 10 | ] 11 | 12 | foreach test_name : tests 13 | exe = executable(test_name, '@0@.c'.format(test_name), 14 | include_directories : opus_includes, 15 | link_with : [celt_lib, celt_static_libs], 16 | dependencies : libm, 17 | install : false) 18 | test(test_name, exe) 19 | endforeach 20 | -------------------------------------------------------------------------------- /celt/tests/test_unit_types.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008-2011 Xiph.Org Foundation 2 | Written by Jean-Marc Valin */ 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 COPYRIGHT OWNER 19 | OR 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "opus_types.h" 33 | #include 34 | 35 | int main(void) 36 | { 37 | opus_int16 i = 1; 38 | i <<= 14; 39 | if (i>>14 != 1) 40 | { 41 | fprintf(stderr, "opus_int16 isn't 16 bits\n"); 42 | return 1; 43 | } 44 | if (sizeof(opus_int16)*2 != sizeof(opus_int32)) 45 | { 46 | fprintf(stderr, "16*2 != 32\n"); 47 | return 1; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /celt/x86/vq_sse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Jean-Marc Valin */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef VQ_SSE_H 28 | #define VQ_SSE_H 29 | 30 | #if defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT) 31 | 32 | opus_val16 op_pvq_search_sse2(celt_norm *_X, int *iy, int K, int N, int arch); 33 | 34 | #if defined(OPUS_X86_PRESUME_SSE2) 35 | 36 | #define OVERRIDE_OP_PVQ_SEARCH 37 | #define op_pvq_search(x, iy, K, N, arch) \ 38 | (op_pvq_search_sse2(x, iy, K, N, arch)) 39 | 40 | #elif defined(OPUS_HAVE_RTCD) 41 | 42 | #define OVERRIDE_OP_PVQ_SEARCH 43 | extern opus_val16 (*const OP_PVQ_SEARCH_IMPL[OPUS_ARCHMASK + 1])( 44 | celt_norm *_X, int *iy, int K, int N, int arch); 45 | 46 | # define op_pvq_search(X, iy, K, N, arch) \ 47 | ((*OP_PVQ_SEARCH_IMPL[(arch) & OPUS_ARCHMASK])(X, iy, K, N, arch)) 48 | 49 | #endif 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /celt/x86/x86_arch_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023 Amazon */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifdef _MSC_VER 28 | 29 | # ifdef OPUS_X86_MAY_HAVE_SSE 30 | # ifndef __SSE__ 31 | # define __SSE__ 32 | # endif 33 | # endif 34 | 35 | # ifdef OPUS_X86_MAY_HAVE_SSE2 36 | # ifndef __SSE2__ 37 | # define __SSE2__ 38 | # endif 39 | # endif 40 | 41 | # ifdef OPUS_X86_MAY_HAVE_SSE4_1 42 | # ifndef __SSE4_1__ 43 | # define __SSE4_1__ 44 | # endif 45 | # endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /celt_headers.mk: -------------------------------------------------------------------------------- 1 | CELT_HEAD = \ 2 | celt/arch.h \ 3 | celt/bands.h \ 4 | celt/celt.h \ 5 | celt/cpu_support.h \ 6 | include/opus_types.h \ 7 | include/opus_defines.h \ 8 | include/opus_custom.h \ 9 | celt/cwrs.h \ 10 | celt/ecintrin.h \ 11 | celt/entcode.h \ 12 | celt/entdec.h \ 13 | celt/entenc.h \ 14 | celt/fixed_debug.h \ 15 | celt/fixed_generic.h \ 16 | celt/float_cast.h \ 17 | celt/_kiss_fft_guts.h \ 18 | celt/kiss_fft.h \ 19 | celt/laplace.h \ 20 | celt/mathops.h \ 21 | celt/mdct.h \ 22 | celt/mfrngcod.h \ 23 | celt/modes.h \ 24 | celt/os_support.h \ 25 | celt/pitch.h \ 26 | celt/celt_lpc.h \ 27 | celt/x86/celt_lpc_sse.h \ 28 | celt/quant_bands.h \ 29 | celt/rate.h \ 30 | celt/stack_alloc.h \ 31 | celt/vq.h \ 32 | celt/static_modes_float.h \ 33 | celt/static_modes_fixed.h \ 34 | celt/static_modes_float_arm_ne10.h \ 35 | celt/static_modes_fixed_arm_ne10.h \ 36 | celt/arm/armcpu.h \ 37 | celt/arm/fixed_armv4.h \ 38 | celt/arm/fixed_armv5e.h \ 39 | celt/arm/fixed_arm64.h \ 40 | celt/arm/kiss_fft_armv4.h \ 41 | celt/arm/kiss_fft_armv5e.h \ 42 | celt/arm/mathops_arm.h \ 43 | celt/arm/pitch_arm.h \ 44 | celt/arm/fft_arm.h \ 45 | celt/arm/mdct_arm.h \ 46 | celt/mips/celt_mipsr1.h \ 47 | celt/mips/fixed_generic_mipsr1.h \ 48 | celt/mips/kiss_fft_mipsr1.h \ 49 | celt/mips/mdct_mipsr1.h \ 50 | celt/mips/pitch_mipsr1.h \ 51 | celt/mips/vq_mipsr1.h \ 52 | celt/x86/pitch_sse.h \ 53 | celt/x86/vq_sse.h \ 54 | celt/x86/x86_arch_macros.h \ 55 | celt/x86/x86cpu.h 56 | -------------------------------------------------------------------------------- /celt_sources.mk: -------------------------------------------------------------------------------- 1 | CELT_SOURCES = \ 2 | celt/bands.c \ 3 | celt/celt.c \ 4 | celt/celt_encoder.c \ 5 | celt/celt_decoder.c \ 6 | celt/cwrs.c \ 7 | celt/entcode.c \ 8 | celt/entdec.c \ 9 | celt/entenc.c \ 10 | celt/kiss_fft.c \ 11 | celt/laplace.c \ 12 | celt/mathops.c \ 13 | celt/mdct.c \ 14 | celt/modes.c \ 15 | celt/pitch.c \ 16 | celt/celt_lpc.c \ 17 | celt/quant_bands.c \ 18 | celt/rate.c \ 19 | celt/vq.c 20 | 21 | CELT_SOURCES_X86_RTCD = \ 22 | celt/x86/x86cpu.c \ 23 | celt/x86/x86_celt_map.c 24 | 25 | CELT_SOURCES_SSE = \ 26 | celt/x86/pitch_sse.c 27 | 28 | CELT_SOURCES_SSE2 = \ 29 | celt/x86/pitch_sse2.c \ 30 | celt/x86/vq_sse2.c 31 | 32 | CELT_SOURCES_SSE4_1 = \ 33 | celt/x86/celt_lpc_sse4_1.c \ 34 | celt/x86/pitch_sse4_1.c 35 | 36 | CELT_SOURCES_AVX2 = \ 37 | celt/x86/pitch_avx.c 38 | 39 | CELT_SOURCES_ARM_RTCD = \ 40 | celt/arm/armcpu.c \ 41 | celt/arm/arm_celt_map.c 42 | 43 | CELT_SOURCES_ARM_ASM = \ 44 | celt/arm/celt_pitch_xcorr_arm.s 45 | 46 | CELT_AM_SOURCES_ARM_ASM = \ 47 | celt/arm/armopts.s.in 48 | 49 | CELT_SOURCES_ARM_NEON_INTR = \ 50 | celt/arm/celt_neon_intr.c \ 51 | celt/arm/pitch_neon_intr.c 52 | 53 | CELT_SOURCES_ARM_NE10 = \ 54 | celt/arm/celt_fft_ne10.c \ 55 | celt/arm/celt_mdct_ne10.c 56 | -------------------------------------------------------------------------------- /cmake/CFeatureCheck.cmake: -------------------------------------------------------------------------------- 1 | # - Compile and run code to check for C features 2 | # 3 | # This functions compiles a source file under the `cmake` folder 4 | # and adds the corresponding `HAVE_[FILENAME]` flag to the CMake 5 | # environment 6 | # 7 | # c_feature_check( []) 8 | # 9 | # - Example 10 | # 11 | # include(CFeatureCheck) 12 | # c_feature_check(VLA) 13 | 14 | if(__c_feature_check) 15 | return() 16 | endif() 17 | set(__c_feature_check INCLUDED) 18 | 19 | function(c_feature_check FILE) 20 | string(TOLOWER ${FILE} FILE) 21 | string(TOUPPER ${FILE} VAR) 22 | string(TOUPPER "${VAR}_SUPPORTED" FEATURE) 23 | if (DEFINED ${VAR}_SUPPORTED) 24 | set(${VAR}_SUPPORTED 1 PARENT_SCOPE) 25 | return() 26 | endif() 27 | 28 | if (NOT DEFINED COMPILE_${FEATURE}) 29 | message(STATUS "Performing Test ${FEATURE}") 30 | try_compile(COMPILE_${FEATURE} ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/${FILE}.c) 31 | endif() 32 | 33 | if(COMPILE_${FEATURE}) 34 | message(STATUS "Performing Test ${FEATURE} -- success") 35 | set(${VAR}_SUPPORTED 1 PARENT_SCOPE) 36 | else() 37 | message(STATUS "Performing Test ${FEATURE} -- failed to compile") 38 | endif() 39 | endfunction() 40 | -------------------------------------------------------------------------------- /cmake/OpusBuildtype.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | if(__opus_buildtype) 3 | return() 4 | endif() 5 | set(__opus_buildtype INCLUDED) 6 | 7 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 8 | if(CMAKE_C_FLAGS) 9 | message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) 10 | else() 11 | set(default_build_type "Release") 12 | message( 13 | STATUS 14 | "Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported." 15 | ) 16 | set(CMAKE_BUILD_TYPE "${default_build_type}" 17 | CACHE STRING "Choose the type of build." 18 | FORCE) 19 | # Set the possible values of build type for cmake-gui 20 | set_property(CACHE CMAKE_BUILD_TYPE 21 | PROPERTY STRINGS 22 | "Debug" 23 | "Release" 24 | "MinSizeRel" 25 | "RelWithDebInfo") 26 | endif() 27 | endif() 28 | -------------------------------------------------------------------------------- /cmake/OpusConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(OPUS_VERSION @PROJECT_VERSION@) 2 | set(OPUS_VERSION_STRING @PROJECT_VERSION@) 3 | set(OPUS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@) 4 | set(OPUS_VERSION_MINOR @PROJECT_VERSION_MINOR@) 5 | set(OPUS_VERSION_PATCH @PROJECT_VERSION_PATCH@) 6 | 7 | @PACKAGE_INIT@ 8 | 9 | set_and_check(OPUS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 10 | set(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR};${OPUS_INCLUDE_DIR}/opus) 11 | set(OPUS_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@;@PACKAGE_INCLUDE_INSTALL_DIR@/opus") 12 | 13 | include(${CMAKE_CURRENT_LIST_DIR}/OpusTargets.cmake) 14 | 15 | set(OPUS_LIBRARY Opus::opus) 16 | set(OPUS_LIBRARIES Opus::opus) 17 | 18 | check_required_components(Opus) 19 | 20 | set(OPUS_FOUND 1) 21 | -------------------------------------------------------------------------------- /cmake/config.h.cmake.in: -------------------------------------------------------------------------------- 1 | #cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" -------------------------------------------------------------------------------- /cmake/cpu_info_by_asm.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | unsigned int CPUInfo0; 4 | unsigned int CPUInfo1; 5 | unsigned int CPUInfo2; 6 | unsigned int CPUInfo3; 7 | unsigned int InfoType; 8 | #if defined(__i386__) && defined(__PIC__) 9 | /* %ebx is PIC register in 32-bit, so mustn't clobber it. */ 10 | __asm__ __volatile__ ( 11 | "xchg %%ebx, %1\n" 12 | "cpuid\n" 13 | "xchg %%ebx, %1\n": 14 | "=a" (CPUInfo0), 15 | "=r" (CPUInfo1), 16 | "=c" (CPUInfo2), 17 | "=d" (CPUInfo3) : 18 | "0" (InfoType), "2" (0) 19 | ); 20 | #else 21 | __asm__ __volatile__ ( 22 | "cpuid": 23 | "=a" (CPUInfo0), 24 | "=b" (CPUInfo1), 25 | "=c" (CPUInfo2), 26 | "=d" (CPUInfo3) : 27 | "0" (InfoType), "2" (0) 28 | ); 29 | #endif 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /cmake/cpu_info_by_c.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | unsigned int CPUInfo0; 4 | unsigned int CPUInfo1; 5 | unsigned int CPUInfo2; 6 | unsigned int CPUInfo3; 7 | unsigned int InfoType; 8 | return __get_cpuid_count(InfoType, 0, &CPUInfo0, &CPUInfo1, &CPUInfo2, &CPUInfo3); 9 | } 10 | -------------------------------------------------------------------------------- /cmake/vla.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | static int x; 3 | char a[++x]; 4 | a[sizeof a - 1] = 0; 5 | int N; 6 | return a[0]; 7 | } -------------------------------------------------------------------------------- /dnn/LPCNet.yml: -------------------------------------------------------------------------------- 1 | # 2 | # install 3 | # conda env create -f=LPCNet.yml 4 | # 5 | # update 6 | # conda env update -f=LPCNet.yml 7 | # 8 | # activate 9 | # conda activate LPCNet 10 | # 11 | # remove 12 | # conda remove --name LPCNet --all 13 | # 14 | name: LPCNet 15 | channels: 16 | - anaconda 17 | - conda-forge 18 | dependencies: 19 | - keras==2.2.4 20 | - python>=3.6 21 | - tensorflow-gpu==1.12.0 22 | - cudatoolkit 23 | - h5py 24 | - numpy 25 | -------------------------------------------------------------------------------- /dnn/README: -------------------------------------------------------------------------------- 1 | See README.md 2 | -------------------------------------------------------------------------------- /dnn/arm/nnet_dotprod.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018-2019 Mozilla 2 | 2023 Amazon */ 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #ifndef __ARM_FEATURE_DOTPROD 33 | #error nnet_dotprod.c is being compiled without DOTPROD enabled 34 | #endif 35 | 36 | #define RTCD_ARCH dotprod 37 | 38 | #include "nnet_arch.h" 39 | -------------------------------------------------------------------------------- /dnn/arm/nnet_neon.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018-2019 Mozilla 2 | 2023 Amazon */ 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #if !(defined(__ARM_NEON__) || defined(__ARM_NEON)) 33 | #error nnet_neon.c is being compiled without Neon enabled 34 | #endif 35 | 36 | #define RTCD_ARCH neon 37 | 38 | #include "nnet_arch.h" 39 | -------------------------------------------------------------------------------- /dnn/common.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef COMMON_H 4 | #define COMMON_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include "opus_defines.h" 10 | 11 | #define LOG256 5.5451774445f 12 | static OPUS_INLINE float log2_approx(float x) 13 | { 14 | int integer; 15 | float frac; 16 | union { 17 | float f; 18 | int i; 19 | } in; 20 | in.f = x; 21 | integer = (in.i>>23)-127; 22 | in.i -= integer<<23; 23 | frac = in.f - 1.5f; 24 | frac = -0.41445418f + frac*(0.95909232f 25 | + frac*(-0.33951290f + frac*0.16541097f)); 26 | return 1+integer+frac; 27 | } 28 | 29 | #define log_approx(x) (0.69315f*log2_approx(x)) 30 | 31 | static OPUS_INLINE float ulaw2lin(float u) 32 | { 33 | float s; 34 | float scale_1 = 32768.f/255.f; 35 | u = u - 128.f; 36 | s = u >= 0.f ? 1.f : -1.f; 37 | u = fabs(u); 38 | return s*scale_1*(exp(u/128.*LOG256)-1); 39 | } 40 | 41 | static OPUS_INLINE int lin2ulaw(float x) 42 | { 43 | float u; 44 | float scale = 255.f/32768.f; 45 | int s = x >= 0 ? 1 : -1; 46 | x = fabs(x); 47 | u = (s*(128*log_approx(1+scale*x)/LOG256)); 48 | u = 128 + u; 49 | if (u < 0) u = 0; 50 | if (u > 255) u = 255; 51 | return (int)floor(.5 + u); 52 | } 53 | 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /dnn/download_model.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set model=opus_data-%1.tar.gz 3 | 4 | if not exist %model% ( 5 | echo Downloading latest model 6 | powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://media.xiph.org/opus/models/%model%', '%model%')" 7 | ) 8 | 9 | tar -xvzf %model% 10 | -------------------------------------------------------------------------------- /dnn/download_model.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | model=opus_data-$1.tar.gz 5 | 6 | if [ ! -f $model ]; then 7 | echo "Downloading latest model" 8 | wget https://media.xiph.org/opus/models/$model 9 | fi 10 | 11 | if command -v sha256sum 12 | then 13 | echo "Validating checksum" 14 | checksum="$1" 15 | checksum2=$(sha256sum $model | awk '{print $1}') 16 | if [ "$checksum" != "$checksum2" ] 17 | then 18 | echo "Aborting due to mismatching checksums. This could be caused by a corrupted download of $model." 19 | echo "Consider deleting local copy of $model and running this script again." 20 | exit 1 21 | else 22 | echo "checksums match" 23 | fi 24 | else 25 | echo "Could not find sha256 sum; skipping verification. Please verify manually that sha256 hash of ${model} matches ${1}." 26 | fi 27 | 28 | 29 | 30 | tar xvomf $model 31 | -------------------------------------------------------------------------------- /dnn/dred_coding.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jean-Marc Valin */ 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 COPYRIGHT OWNER 19 | OR 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include 33 | 34 | #include "celt/entenc.h" 35 | #include "os_support.h" 36 | #include "dred_config.h" 37 | #include "dred_coding.h" 38 | 39 | int compute_quantizer(int q0, int dQ, int qmax, int i) { 40 | int quant; 41 | static const int dQ_table[8] = {0, 2, 3, 4, 6, 8, 12, 16}; 42 | quant = q0 + (dQ_table[dQ]*i + 8)/16; 43 | return quant > qmax ? qmax : quant; 44 | } 45 | -------------------------------------------------------------------------------- /dnn/dred_coding.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 DRED_CODING_H 29 | #define DRED_CODING_H 30 | 31 | #include "opus_types.h" 32 | #include "entcode.h" 33 | 34 | int compute_quantizer(int q0, int dQ, int qmax, int i); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /dnn/dred_config.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 DRED_CONFIG_H 29 | #define DRED_CONFIG_H 30 | 31 | /* Change this once DRED gets an extension number assigned. */ 32 | #define DRED_EXTENSION_ID 126 33 | 34 | /* Remove these two completely once DRED gets an extension number assigned. */ 35 | #define DRED_EXPERIMENTAL_VERSION 10 36 | #define DRED_EXPERIMENTAL_BYTES 2 37 | 38 | 39 | #define DRED_MIN_BYTES 8 40 | 41 | /* these are inpart duplicates to the values defined in dred_rdovae_constants.h */ 42 | #define DRED_SILK_ENCODER_DELAY (79+12-80) 43 | #define DRED_FRAME_SIZE 160 44 | #define DRED_DFRAME_SIZE (2 * (DRED_FRAME_SIZE)) 45 | #define DRED_MAX_DATA_SIZE 1000 46 | #define DRED_ENC_Q0 6 47 | #define DRED_ENC_Q1 15 48 | 49 | /* Covers 1.04 second so we can cover one second, after the lookahead. */ 50 | #define DRED_MAX_LATENTS 26 51 | #define DRED_NUM_REDUNDANCY_FRAMES (2*DRED_MAX_LATENTS) 52 | #define DRED_MAX_FRAMES (4*DRED_MAX_LATENTS) 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /dnn/dred_decoder.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 DRED_DECODER_H 29 | #define DRED_DECODER_H 30 | 31 | #include "opus.h" 32 | #include "dred_config.h" 33 | #include "dred_rdovae.h" 34 | #include "entcode.h" 35 | #include "dred_rdovae_constants.h" 36 | 37 | struct OpusDRED { 38 | float fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES]; 39 | float state[DRED_STATE_DIM]; 40 | float latents[(DRED_NUM_REDUNDANCY_FRAMES/2)*DRED_LATENT_DIM]; 41 | int nb_latents; 42 | int process_stage; 43 | int dred_offset; 44 | }; 45 | 46 | 47 | int dred_ec_decode(OpusDRED *dec, const opus_uint8 *bytes, int num_bytes, int min_feature_frames, int dred_frame_offset); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /dnn/dred_rdovae.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 DRED_RDOVAE_H 29 | #define DRED_RDOVAE_H 30 | 31 | #include 32 | 33 | #include "opus_types.h" 34 | 35 | typedef struct RDOVAEDec RDOVAEDec; 36 | typedef struct RDOVAEEnc RDOVAEEnc; 37 | typedef struct RDOVAEDecStruct RDOVAEDecState; 38 | typedef struct RDOVAEEncStruct RDOVAEEncState; 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /dnn/dred_rdovae_enc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 DRED_RDOVAE_ENC_H 29 | #define DRED_RDOVAE_ENC_H 30 | 31 | #include "dred_rdovae.h" 32 | 33 | #include "dred_rdovae_enc_data.h" 34 | 35 | struct RDOVAEEncStruct { 36 | int initialized; 37 | float gru1_state[ENC_GRU1_STATE_SIZE]; 38 | float gru2_state[ENC_GRU2_STATE_SIZE]; 39 | float gru3_state[ENC_GRU3_STATE_SIZE]; 40 | float gru4_state[ENC_GRU4_STATE_SIZE]; 41 | float gru5_state[ENC_GRU5_STATE_SIZE]; 42 | float conv1_state[ENC_CONV1_STATE_SIZE]; 43 | float conv2_state[2*ENC_CONV2_STATE_SIZE]; 44 | float conv3_state[2*ENC_CONV3_STATE_SIZE]; 45 | float conv4_state[2*ENC_CONV4_STATE_SIZE]; 46 | float conv5_state[2*ENC_CONV5_STATE_SIZE]; 47 | }; 48 | 49 | void dred_rdovae_encode_dframe(RDOVAEEncState *enc_state, const RDOVAEEnc *model, float *latents, float *initial_state, const float *input, int arch); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /dnn/kiss99.h: -------------------------------------------------------------------------------- 1 | /*Daala video codec 2 | Copyright (c) 2012 Daala project contributors. All rights reserved. 3 | Author: Timothy B. Terriberry 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | - Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ 25 | 26 | #if !defined(_kiss99_H) 27 | # define _kiss99_H (1) 28 | # include 29 | 30 | /*KISS PRNG from George Marsaglia (1999 version). 31 | See https://en.wikipedia.org/wiki/KISS_(algorithm) for details. 32 | This is suitable for simulations, but not for use in crytographic contexts.*/ 33 | 34 | typedef struct kiss99_ctx kiss99_ctx; 35 | 36 | struct kiss99_ctx{ 37 | uint32_t z; 38 | uint32_t w; 39 | uint32_t jsr; 40 | uint32_t jcong; 41 | }; 42 | 43 | void kiss99_srand(kiss99_ctx *_this,const unsigned char *_data,int _ndata); 44 | uint32_t kiss99_rand(kiss99_ctx *_this); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /dnn/lossgen.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023 Amazon */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LOSSGEN_H 28 | #define LOSSGEN_H 29 | 30 | 31 | #include "lossgen_data.h" 32 | 33 | #define PITCH_MIN_PERIOD 32 34 | #define PITCH_MAX_PERIOD 256 35 | 36 | #define NB_XCORR_FEATURES (PITCH_MAX_PERIOD-PITCH_MIN_PERIOD) 37 | 38 | 39 | typedef struct { 40 | LossGen model; 41 | float gru1_state[LOSSGEN_GRU1_STATE_SIZE]; 42 | float gru2_state[LOSSGEN_GRU2_STATE_SIZE]; 43 | int last_loss; 44 | int used; 45 | } LossGenState; 46 | 47 | 48 | void lossgen_init(LossGenState *st); 49 | int lossgen_load_model(LossGenState *st, const void *data, int len); 50 | 51 | int sample_loss( 52 | LossGenState *st, 53 | float percent_loss); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /dnn/lossgen_demo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lossgen.h" 4 | int main(int argc, char **argv) 5 | { 6 | LossGenState st; 7 | long num_packets; 8 | long i; 9 | float percent; 10 | if (argc != 3) { 11 | fprintf(stderr, "usage: %s \n", argv[0]); 12 | return 1; 13 | } 14 | lossgen_init(&st); 15 | percent = atof(argv[1]); 16 | num_packets = atol(argv[2]); 17 | /*printf("loss: %f %d\n", percent, num_packets);*/ 18 | for (i=0;iij', ar[:,:,L-i-1:-1], R[:,:,:i]) 33 | for i in range(L, N): 34 | R[:,:,i] = - torch.sum(ar[:,:,:-1] * R[:,:,i-L+1:i], axis=-1) 35 | #R[:,:,i] = - torch.einsum('ijk,ijk->ij', ar[:,:,:-1], R[:,:,i-L+1:i]) 36 | return R 37 | 38 | if __name__ == '__main__': 39 | #a = torch.tensor([ [[1, -.9, 0.02], [1, -.8, .01]], [[1, .9, 0], [1, .8, 0]]]) 40 | a = torch.tensor([ [[1, -.9, 0.02], [1, -.8, .01]]]) 41 | A = toeplitz_from_filter(a) 42 | #print(A) 43 | R = filter_iir_response(a, 5) 44 | 45 | RA = toeplitz_from_filter(R) 46 | print(RA) 47 | -------------------------------------------------------------------------------- /dnn/torch/fargan/rc.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | 5 | def rc2lpc(rc): 6 | order = rc.shape[-1] 7 | lpc=rc[...,0:1] 8 | for i in range(1, order): 9 | lpc = torch.cat([lpc + rc[...,i:i+1]*torch.flip(lpc,dims=(-1,)), rc[...,i:i+1]], -1) 10 | #print("to:", lpc) 11 | return lpc 12 | 13 | def lpc2rc(lpc): 14 | order = lpc.shape[-1] 15 | rc = lpc[...,-1:] 16 | for i in range(order-1, 0, -1): 17 | ki = lpc[...,-1:] 18 | lpc = lpc[...,:-1] 19 | lpc = (lpc - ki*torch.flip(lpc,dims=(-1,)))/(1 - ki*ki) 20 | rc = torch.cat([lpc[...,-1:] , rc], -1) 21 | return rc 22 | 23 | if __name__ == "__main__": 24 | rc = torch.tensor([[.5, -.5, .6, -.6]]) 25 | print(rc) 26 | lpc = rc2lpc(rc) 27 | print(lpc) 28 | rc2 = lpc2rc(lpc) 29 | print(rc2) 30 | -------------------------------------------------------------------------------- /dnn/torch/fwgan/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .fwgan400 import FWGAN400ContLarge 2 | from .fwgan500 import FWGAN500Cont 3 | 4 | model_dict = { 5 | 'fwgan400': FWGAN400ContLarge, 6 | 'fwgan500': FWGAN500Cont 7 | } -------------------------------------------------------------------------------- /dnn/torch/lossgen/README.md: -------------------------------------------------------------------------------- 1 | #Packet loss simulator 2 | 3 | This code is an attempt at simulating better packet loss scenarios. The most common way of simulating 4 | packet loss is to use a random sequence where each packet loss event is uncorrelated with previous events. 5 | That is a simplistic model since we know that losses often occur in bursts. This model uses real data 6 | to build a generative model for packet loss. 7 | 8 | We use the training data provided for the Audio Deep Packet Loss Concealment Challenge, which is available at: 9 | 10 | http://plcchallenge2022pub.blob.core.windows.net/plcchallengearchive/test_train.tar.gz 11 | 12 | To create the training data, run: 13 | 14 | `./process_data.sh //test_train/train/lossy_signals/` 15 | 16 | That will create an ascii loss\_sorted.txt file with all loss data sorted in increasing packet loss 17 | percentage. Then just run: 18 | 19 | `python ./train_lossgen.py` 20 | 21 | to train a model 22 | 23 | To generate a sequence, run 24 | 25 | `python3 ./test_lossgen.py output.txt --length 10000` 26 | 27 | where is the .pth model file and is the amount of loss (e.g. 0.2 for 20% loss). 28 | -------------------------------------------------------------------------------- /dnn/torch/lossgen/lossgen.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | import torch.nn.functional as F 4 | 5 | class LossGen(nn.Module): 6 | def __init__(self, gru1_size=16, gru2_size=16): 7 | super(LossGen, self).__init__() 8 | 9 | self.gru1_size = gru1_size 10 | self.gru2_size = gru2_size 11 | self.dense_in = nn.Linear(2, 8) 12 | self.gru1 = nn.GRU(8, self.gru1_size, batch_first=True) 13 | self.gru2 = nn.GRU(self.gru1_size, self.gru2_size, batch_first=True) 14 | self.dense_out = nn.Linear(self.gru2_size, 1) 15 | 16 | def forward(self, loss, perc, states=None): 17 | #print(states) 18 | device = loss.device 19 | batch_size = loss.size(0) 20 | if states is None: 21 | gru1_state = torch.zeros((1, batch_size, self.gru1_size), device=device) 22 | gru2_state = torch.zeros((1, batch_size, self.gru2_size), device=device) 23 | else: 24 | gru1_state = states[0] 25 | gru2_state = states[1] 26 | x = torch.tanh(self.dense_in(torch.cat([loss, perc], dim=-1))) 27 | gru1_out, gru1_state = self.gru1(x, gru1_state) 28 | gru2_out, gru2_state = self.gru2(gru1_out, gru2_state) 29 | return self.dense_out(gru2_out), [gru1_state, gru2_state] 30 | -------------------------------------------------------------------------------- /dnn/torch/lossgen/process_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #directory containing the loss files 4 | datadir=$1 5 | 6 | for i in $datadir/*_is_lost.txt 7 | do 8 | perc=`cat $i | awk '{a+=$1}END{print a/NR}'` 9 | echo $perc $i 10 | done > percentage_list.txt 11 | 12 | sort -n percentage_list.txt | awk '{print $2}' > percentage_sorted.txt 13 | 14 | for i in `cat percentage_sorted.txt` 15 | do 16 | cat $i 17 | done > loss_sorted.txt 18 | -------------------------------------------------------------------------------- /dnn/torch/lossgen/test_lossgen.py: -------------------------------------------------------------------------------- 1 | import lossgen 2 | import os 3 | import argparse 4 | import torch 5 | import numpy as np 6 | 7 | 8 | parser = argparse.ArgumentParser() 9 | 10 | parser.add_argument('model', type=str, help='CELPNet model') 11 | parser.add_argument('percentage', type=float, help='percentage loss') 12 | parser.add_argument('output', type=str, help='path to output file (ascii)') 13 | 14 | parser.add_argument('--length', type=int, help="length of sequence to generate", default=500) 15 | 16 | args = parser.parse_args() 17 | 18 | 19 | 20 | checkpoint = torch.load(args.model, map_location='cpu') 21 | model = lossgen.LossGen(*checkpoint['model_args'], **checkpoint['model_kwargs']) 22 | model.load_state_dict(checkpoint['state_dict'], strict=False) 23 | 24 | states=None 25 | last = torch.zeros((1,1,1)) 26 | perc = torch.tensor((args.percentage,))[None,None,:] 27 | seq = torch.zeros((0,1,1)) 28 | 29 | one = torch.ones((1,1,1)) 30 | zero = torch.zeros((1,1,1)) 31 | 32 | if __name__ == '__main__': 33 | for i in range(args.length): 34 | prob, states = model(last, perc, states=states) 35 | prob = torch.sigmoid(prob) 36 | states[0] = states[0].detach() 37 | states[1] = states[1].detach() 38 | loss = one if np.random.rand() < prob else zero 39 | last = loss 40 | seq = torch.cat([seq, loss]) 41 | 42 | np.savetxt(args.output, seq[:,:,0].numpy().astype('int'), fmt='%d') 43 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/README.md: -------------------------------------------------------------------------------- 1 | # LPCNet 2 | 3 | Incomplete pytorch implementation of LPCNet 4 | 5 | ## Data preparation 6 | For data preparation use dump_data in github.com/xiph/LPCNet. To turn this into 7 | a training dataset, copy data and feature file to a folder and run 8 | 9 | python add_dataset_config.py my_dataset_folder 10 | 11 | 12 | ## Training 13 | To train a model, create and adjust a setup file, e.g. with 14 | 15 | python make_default_setup.py my_setup.yml --path2dataset my_dataset_folder 16 | 17 | Then simply run 18 | 19 | python train_lpcnet.py my_setup.yml my_output 20 | 21 | ## Inference 22 | Create feature file with dump_data from github.com/xiph/LPCNet. Then run e.g. 23 | 24 | python test_lpcnet.py features.f32 my_output/checkpoints/checkpoint_ep_10.pth out.wav 25 | 26 | Inference runs on CPU and takes usually between 3 and 20 seconds per generated second of audio, 27 | depending on the CPU. 28 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .lpcnet_dataset import LPCNetDataset -------------------------------------------------------------------------------- /dnn/torch/lpcnet/make_default_setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import argparse 31 | 32 | import yaml 33 | 34 | from utils.templates import setup_dict 35 | 36 | parser = argparse.ArgumentParser() 37 | 38 | parser.add_argument('name', type=str, help='name of default setup file') 39 | parser.add_argument('--model', choices=['lpcnet', 'multi_rate'], help='LPCNet model name', default='lpcnet') 40 | parser.add_argument('--path2dataset', type=str, help='dataset path', default=None) 41 | 42 | args = parser.parse_args() 43 | 44 | setup = setup_dict[args.model] 45 | 46 | # update dataset if given 47 | if type(args.path2dataset) != type(None): 48 | setup['dataset'] = args.path2dataset 49 | 50 | name = args.name 51 | if not name.endswith('.yml'): 52 | name += '.yml' 53 | 54 | if __name__ == '__main__': 55 | with open(name, 'w') as f: 56 | f.write(yaml.dump(setup)) 57 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .lpcnet import LPCNet 2 | from .multi_rate_lpcnet import MultiRateLPCNet 3 | 4 | 5 | model_dict = { 6 | 'lpcnet' : LPCNet, 7 | 'multi_rate' : MultiRateLPCNet 8 | } -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/loop_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | case $# in 5 | 9) SETUP=$1; OUTDIR=$2; NAME=$3; DEVICE=$4; ROUNDS=$5; LPCNEXT=$6; LPCNET=$7; TESTSUITE=$8; TESTITEMS=$9;; 6 | *) echo "loop_run.sh setup outdir name device rounds lpcnext_repo lpcnet_repo testsuite_repo testitems"; exit;; 7 | esac 8 | 9 | 10 | PYTHON="/home/ubuntu/opt/miniconda3/envs/torch/bin/python" 11 | TESTFEATURES=${LPCNEXT}/testitems/features/all_0_orig_features.f32 12 | WARPQREFERENCE=${LPCNEXT}/testitems/wav/all_0_orig.wav 13 | METRICS="warpq,pesq,pitch_error,voicing_error" 14 | LPCNETDEMO=${LPCNET}/lpcnet_demo 15 | 16 | for ((round = 1; round <= $ROUNDS; round++)) 17 | do 18 | echo 19 | echo round $round 20 | 21 | UUID=$(uuidgen) 22 | TRAINOUT=${OUTDIR}/${UUID}/training 23 | TESTOUT=${OUTDIR}/${UUID}/testing 24 | CHECKPOINT=${TRAINOUT}/checkpoints/checkpoint_last.pth 25 | FINALCHECKPOINT=${TRAINOUT}/checkpoints/checkpoint_finalize_last.pth 26 | 27 | # run training 28 | echo "starting training..." 29 | $PYTHON $LPCNEXT/train_lpcnet.py $SETUP $TRAINOUT --device $DEVICE --test-features $TESTFEATURES --warpq-reference $WARPQREFERENCE 30 | 31 | # run finalization 32 | echo "starting finalization..." 33 | $PYTHON $LPCNEXT/train_lpcnet.py $SETUP $TRAINOUT \ 34 | --device $DEVICE --test-features $TESTFEATURES \ 35 | --warpq-reference $WARPQREFERENCE \ 36 | --finalize --initial-checkpoint $CHECKPOINT 37 | 38 | # create test configs 39 | $PYTHON $LPCNEXT/make_test_config.py ${OUTDIR}/${UUID}/testconfig.yml "$NAME $UUID" $CHECKPOINT --lpcnet-demo $LPCNETDEMO 40 | $PYTHON $LPCNEXT/make_test_config.py ${OUTDIR}/${UUID}/testconfig_finalize.yml "$NAME $UUID finalized" $FINALCHECKPOINT --lpcnet-demo $LPCNETDEMO 41 | 42 | # run tests 43 | echo "starting test 1 (no finalization)..." 44 | $PYTHON $TESTSUITE/run_test.py ${OUTDIR}/${UUID}/testconfig.yml \ 45 | $TESTITEMS ${TESTOUT}/prefinal --num-workers 8 \ 46 | --num-testitems 400 --metrics $METRICS 47 | 48 | echo "starting test 2 (after finalization)..." 49 | $PYTHON $TESTSUITE/run_test.py ${OUTDIR}/${UUID}/testconfig_finalize.yml \ 50 | $TESTITEMS ${TESTOUT}/final --num-workers 8 \ 51 | --num-testitems 400 --metrics $METRICS 52 | done 53 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/modify_dataset_target.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | import numpy as np 4 | 5 | 6 | parser = argparse.ArgumentParser(description="sets s_t to augmented_s_t") 7 | 8 | parser.add_argument('datafile', type=str, help='data.s16 file path') 9 | 10 | args = parser.parse_args() 11 | 12 | data = np.memmap(args.datafile, dtype='int16', mode='readwrite') 13 | 14 | # signal is in data[1::2] 15 | # last augmented signal is in data[0::2] 16 | 17 | data[1 : - 1 : 2] = data[2 : : 2] 18 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/multi_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | case $# in 4 | 9) SETUP=$1; OUTDIR=$2; NAME=$3; NUMDEVICES=$4; ROUNDS=$5; LPCNEXT=$6; LPCNET=$7; TESTSUITE=$8; TESTITEMS=$9;; 5 | *) echo "multi_run.sh setup outdir name num_devices rounds_per_device lpcnext_repo lpcnet_repo testsuite_repo testitems"; exit;; 6 | esac 7 | 8 | 9 | LOOPRUN=${LPCNEXT}/loop_run.sh 10 | 11 | mkdir -p $OUTDIR 12 | 13 | for ((i = 0; i < $NUMDEVICES; i++)) 14 | do 15 | echo "launching job queue for device $i" 16 | nohup bash $LOOPRUN $SETUP $OUTDIR "$NAME" "cuda:$i" $ROUNDS $LPCNEXT $LPCNET $TESTSUITE $TESTITEMS > $OUTDIR/job_${i}_out.txt & 17 | done 18 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/run_inference_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | case $# in 5 | 3) FEATURES=$1; FOLDER=$2; PYTHON=$3;; 6 | *) echo "run_inference_test.sh "; exit;; 7 | esac 8 | 9 | 10 | SCRIPTFOLDER=$(dirname "$0") 11 | 12 | mkdir -p $FOLDER/inference_test 13 | 14 | # update checkpoints 15 | for fn in $(find $FOLDER -type f -name "checkpoint*.pth") 16 | do 17 | tmp=$(basename $fn) 18 | tmp=${tmp%.pth} 19 | epoch=${tmp#checkpoint_epoch_} 20 | echo "running inference with checkpoint $fn..." 21 | $PYTHON $SCRIPTFOLDER/../test_lpcnet.py $FEATURES $fn $FOLDER/inference_test/output_epoch_${epoch}.wav 22 | done 23 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/update_checkpoints.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | """ script for updating checkpoints with new setup entries 31 | 32 | Use this script to update older outputs with newly introduced 33 | parameters. (Saves us the trouble of backward compatibility) 34 | """ 35 | 36 | 37 | import argparse 38 | 39 | import torch 40 | 41 | parser = argparse.ArgumentParser() 42 | 43 | parser.add_argument('checkpoint_file', type=str, help='checkpoint to be updated') 44 | parser.add_argument('--model', type=str, help='model update', default=None) 45 | 46 | args = parser.parse_args() 47 | 48 | checkpoint = torch.load(args.checkpoint_file, map_location='cpu') 49 | 50 | # update model entry 51 | if type(args.model) != type(None): 52 | checkpoint['setup']['lpcnet']['model'] = args.model 53 | 54 | torch.save(checkpoint, args.checkpoint_file) -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/update_output_folder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | case $# in 5 | 3) FOLDER=$1; MODEL=$2; PYTHON=$3;; 6 | *) echo "update_output_folder.sh folder model python"; exit;; 7 | esac 8 | 9 | 10 | SCRIPTFOLDER=$(dirname "$0") 11 | 12 | 13 | # update setup 14 | echo "updating $FOLDER/setup.py..." 15 | $PYTHON $SCRIPTFOLDER/update_setups.py $FOLDER/setup.yml --model $MODEL 16 | 17 | # update checkpoints 18 | for fn in $(find $FOLDER -type f -name "checkpoint*.pth") 19 | do 20 | echo "updating $fn..." 21 | $PYTHON $SCRIPTFOLDER/update_checkpoints.py $fn --model $MODEL 22 | done -------------------------------------------------------------------------------- /dnn/torch/lpcnet/scripts/update_setups.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | """ script for updating setup files with new setup entries 31 | 32 | Use this script to update older outputs with newly introduced 33 | parameters. (Saves us the trouble of backward compatibility) 34 | """ 35 | 36 | import argparse 37 | 38 | import yaml 39 | 40 | parser = argparse.ArgumentParser() 41 | 42 | parser.add_argument('setup_file', type=str, help='setup to be updated') 43 | parser.add_argument('--model', type=str, help='model update', default=None) 44 | 45 | args = parser.parse_args() 46 | 47 | # load setup 48 | with open(args.setup_file, 'r') as f: 49 | setup = yaml.load(f.read(), yaml.FullLoader) 50 | 51 | # update model entry 52 | if type(args.model) != type(None): 53 | setup['lpcnet']['model'] = args.model 54 | 55 | # dump result 56 | with open(args.setup_file, 'w') as f: 57 | yaml.dump(setup, f) 58 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from . import sparsification 2 | from . import data 3 | from . import pcm 4 | from . import sample -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/layers/__init__.py: -------------------------------------------------------------------------------- 1 | from .dual_fc import DualFC 2 | from .subconditioner import AdditiveSubconditioner, ModulativeSubconditioner, ConcatenativeSubconditioner 3 | from .pcm_embeddings import PCMEmbedding, DifferentiablePCMEmbedding -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/layers/dual_fc.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import torch 31 | from torch import nn 32 | 33 | class DualFC(nn.Module): 34 | def __init__(self, input_dim, output_dim): 35 | super(DualFC, self).__init__() 36 | 37 | self.dense1 = nn.Linear(input_dim, output_dim) 38 | self.dense2 = nn.Linear(input_dim, output_dim) 39 | 40 | self.alpha = nn.Parameter(torch.tensor([0.5]), requires_grad=True) 41 | self.beta = nn.Parameter(torch.tensor([0.5]), requires_grad=True) 42 | 43 | def forward(self, x): 44 | return self.alpha * torch.tanh(self.dense1(x)) + self.beta * torch.tanh(self.dense2(x)) 45 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/misc.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import torch 31 | 32 | 33 | def find(a, v): 34 | try: 35 | idx = a.index(v) 36 | except: 37 | idx = -1 38 | return idx 39 | 40 | def interleave_tensors(tensors, dim=-2): 41 | """ interleave list of tensors along sequence dimension """ 42 | 43 | x = torch.cat([x.unsqueeze(dim) for x in tensors], dim=dim) 44 | x = torch.flatten(x, dim - 1, dim) 45 | 46 | return x 47 | 48 | def _interleave(x, pcm_levels=256): 49 | 50 | repeats = pcm_levels // (2*x.size(-1)) 51 | x = x.unsqueeze(-1) 52 | p = torch.flatten(torch.repeat_interleave(torch.cat((x, 1 - x), dim=-1), repeats, dim=-1), -2) 53 | 54 | return p 55 | 56 | def get_pdf_from_tree(x): 57 | pcm_levels = x.size(-1) 58 | 59 | p = _interleave(x[..., 1:2]) 60 | n = 4 61 | while n <= pcm_levels: 62 | p = p * _interleave(x[..., n//2:n]) 63 | n *= 2 64 | 65 | return p -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/pcm.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | 31 | def clip_to_int16(x): 32 | int_min = -2**15 33 | int_max = 2**15 - 1 34 | x_clipped = max(int_min, min(x, int_max)) 35 | return x_clipped 36 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/sample.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import torch 31 | 32 | 33 | def sample_excitation(probs, pitch_corr): 34 | 35 | norm = lambda x : x / (x.sum() + 1e-18) 36 | 37 | # lowering the temperature 38 | probs = norm(probs ** (1 + max(0, 1.5 * pitch_corr - 0.5))) 39 | # cut-off tails 40 | probs = norm(torch.maximum(probs - 0.002 , torch.FloatTensor([0]))) 41 | # sample 42 | exc = torch.multinomial(probs.squeeze(), 1) 43 | 44 | return exc 45 | -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/sparsification/__init__.py: -------------------------------------------------------------------------------- 1 | from .gru_sparsifier import GRUSparsifier 2 | from .common import sparsify_matrix, calculate_gru_flops_per_step -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/ulaw.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import math as m 31 | 32 | import torch 33 | 34 | 35 | 36 | def ulaw2lin(u): 37 | scale_1 = 32768.0 / 255.0 38 | u = u - 128 39 | s = torch.sign(u) 40 | u = torch.abs(u) 41 | return s * scale_1 * (torch.exp(u / 128. * m.log(256)) - 1) 42 | 43 | 44 | def lin2ulawq(x): 45 | scale = 255.0 / 32768.0 46 | s = torch.sign(x) 47 | x = torch.abs(x) 48 | u = s * (128 * torch.log(1 + scale * x) / m.log(256)) 49 | u = torch.clip(128 + torch.round(u), 0, 255) 50 | return u 51 | 52 | def lin2ulaw(x): 53 | scale = 255.0 / 32768.0 54 | s = torch.sign(x) 55 | x = torch.abs(x) 56 | u = s * (128 * torch.log(1 + scale * x) / torch.log(256)) 57 | u = torch.clip(128 + u, 0, 255) 58 | return u -------------------------------------------------------------------------------- /dnn/torch/lpcnet/utils/wav.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import wave 31 | 32 | def wavwrite16(filename, x, fs): 33 | """ writes x as int16 to file with name filename 34 | 35 | If x.dtype is int16 x is written as is. Otherwise, 36 | it is scaled by 2**15 - 1 and converted to int16. 37 | """ 38 | if x.dtype != 'int16': 39 | x = ((2**15 - 1) * x).astype('int16') 40 | 41 | with wave.open(filename, 'wb') as f: 42 | f.setparams((1, 2, fs, len(x), 'NONE', "")) 43 | f.writeframes(x.tobytes()) -------------------------------------------------------------------------------- /dnn/torch/neural-pitch/README.md: -------------------------------------------------------------------------------- 1 | ## Neural Pitch Estimation 2 | 3 | - Dataset Installation 4 | 1. Download and unzip PTDB Dataset: 5 | wget https://www2.spsc.tugraz.at/databases/PTDB-TUG/SPEECH_DATA_ZIPPED.zip 6 | unzip SPEECH_DATA_ZIPPED.zip 7 | 8 | 2. Inside "SPEECH DATA" above, run ptdb_process.sh to combine male/female 9 | 10 | 3. To Download and combine demand, simply run download_demand.sh 11 | 12 | - LPCNet preparation 13 | 1. To extract xcorr, add lpcnet_extractor.c and add relevant functions to lpcnet_enc.c, add source for headers/c files and Makefile.am, and compile to generate ./lpcnet_xcorr_extractor object 14 | 15 | - Dataset Augmentation and training (check out arguments to each of the following) 16 | 1. Run data_augmentation.py 17 | 2. Run training.py using augmented data 18 | 3. Run experiments.py 19 | -------------------------------------------------------------------------------- /dnn/torch/neural-pitch/download_demand.sh: -------------------------------------------------------------------------------- 1 | wget https://zenodo.org/record/1227121/files/DKITCHEN_16k.zip 2 | 3 | wget https://zenodo.org/record/1227121/files/DLIVING_16k.zip 4 | 5 | wget https://zenodo.org/record/1227121/files/DWASHING_16k.zip 6 | 7 | wget https://zenodo.org/record/1227121/files/NFIELD_16k.zip 8 | 9 | wget https://zenodo.org/record/1227121/files/NPARK_16k.zip 10 | 11 | wget https://zenodo.org/record/1227121/files/NRIVER_16k.zip 12 | 13 | wget https://zenodo.org/record/1227121/files/OHALLWAY_16k.zip 14 | 15 | wget https://zenodo.org/record/1227121/files/OMEETING_16k.zip 16 | 17 | wget https://zenodo.org/record/1227121/files/OOFFICE_16k.zip 18 | 19 | wget https://zenodo.org/record/1227121/files/PCAFETER_16k.zip 20 | 21 | wget https://zenodo.org/record/1227121/files/PRESTO_16k.zip 22 | 23 | wget https://zenodo.org/record/1227121/files/PSTATION_16k.zip 24 | 25 | wget https://zenodo.org/record/1227121/files/TMETRO_16k.zip 26 | 27 | wget https://zenodo.org/record/1227121/files/TCAR_16k.zip 28 | 29 | wget https://zenodo.org/record/1227121/files/TBUS_16k.zip 30 | 31 | wget https://zenodo.org/record/1227121/files/STRAFFIC_16k.zip 32 | 33 | wget https://zenodo.org/record/1227121/files/SPSQUARE_16k.zip 34 | 35 | unzip '*.zip' 36 | 37 | mkdir -p ./combined_demand_channels/ 38 | for file in */*.wav; do 39 | parentdir="$(dirname "$file")" 40 | echo $parentdir 41 | fname="$(basename "$file")" 42 | cp $file ./combined_demand_channels/$parentdir+$fname 43 | done 44 | -------------------------------------------------------------------------------- /dnn/torch/neural-pitch/experiments.py: -------------------------------------------------------------------------------- 1 | """ 2 | Running the experiments; 3 | 1. RCA vs SNR for our models, CREPE, LPCNet 4 | """ 5 | 6 | import argparse 7 | parser = argparse.ArgumentParser() 8 | 9 | parser.add_argument('ptdb_root', type=str, help='Root Directory for PTDB generated by running ptdb_process.sh ') 10 | parser.add_argument('output', type=str, help='Output dump file name') 11 | parser.add_argument('method', type=str, help='Output Directory to save experiment dumps',choices=['model','lpcnet','crepe']) 12 | parser.add_argument('--noise_dataset', type=str, help='Location of the Demand Datset',default = './',required=False) 13 | parser.add_argument('--noise_type', type=str, help='Type of additive noise',default = 'synthetic',choices=['synthetic','demand'],required=False) 14 | parser.add_argument('--pth_file', type=str, help='.pth file to analyze',default = './',required = False) 15 | parser.add_argument('--fraction_files_analyze', type=float, help='Fraction of PTDB dataset to test on',default = 1,required = False) 16 | parser.add_argument('--threshold_rca', type=float, help='Cent threshold when computing RCA',default = 50,required = False) 17 | parser.add_argument('--gpu_index', type=int, help='GPU index to use if multiple GPUs',default = 0,required = False) 18 | 19 | args = parser.parse_args() 20 | 21 | import os 22 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 23 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu_index) 24 | 25 | import json 26 | from evaluation import cycle_eval 27 | 28 | if args.method == 'model': 29 | dict_store = cycle_eval([args.pth_file], noise_type = args.noise_type, noise_dataset = args.noise_dataset, list_snr = [-20,-15,-10,-5,0,5,10,15,20], ptdb_dataset_path = args.ptdb_root,fraction = args.fraction_files_analyze,thresh = args.threshold_rca) 30 | else: 31 | dict_store = cycle_eval([args.method], noise_type = args.noise_type, noise_dataset = args.noise_dataset, list_snr = [-20,-15,-10,-5,0,5,10,15,20], ptdb_dataset_path = args.ptdb_root,fraction = args.fraction_files_analyze,thresh = args.threshold_rca) 32 | 33 | dict_store["method"] = args.method 34 | if args.method == 'model': 35 | dict_store['pth'] = args.pth_file 36 | 37 | with open(args.output, 'w') as fp: 38 | json.dump(dict_store, fp) 39 | -------------------------------------------------------------------------------- /dnn/torch/neural-pitch/ptdb_process.sh: -------------------------------------------------------------------------------- 1 | # Copy into PTDB root directory and run to combine all the male/female raw audio/references into below directories 2 | 3 | # Make folder for combined audio 4 | mkdir -p './combined_mic_16k/' 5 | # Make folder for combined pitch reference 6 | mkdir -p './combined_reference_f0/' 7 | 8 | # Resample Male Audio 9 | for i in ./MALE/MIC/**/*.wav; do 10 | j="$(basename "$i" .wav)" 11 | echo $j 12 | sox -r 48000 -b 16 -e signed-integer "$i" -r 16000 -b 16 -e signed-integer ./combined_mic_16k/$j.raw 13 | done 14 | 15 | # Resample Female Audio 16 | for i in ./FEMALE/MIC/**/*.wav; do 17 | j="$(basename "$i" .wav)" 18 | echo $j 19 | sox -r 48000 -b 16 -e signed-integer "$i" -r 16000 -b 16 -e signed-integer ./combined_mic_16k/$j.raw 20 | done 21 | 22 | # Shift Male reference pitch files 23 | for i in ./MALE/REF/**/*.f0; do 24 | j="$(basename "$i" .wav)" 25 | echo $j 26 | cp "$i" ./combined_reference_f0/ 27 | done 28 | 29 | # Shift Female reference pitch files 30 | for i in ./FEMALE/REF/**/*.f0; do 31 | j="$(basename "$i" .wav)" 32 | echo $j 33 | cp "$i" ./combined_reference_f0/ 34 | done -------------------------------------------------------------------------------- /dnn/torch/osce/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .silk_enhancement_set import SilkEnhancementSet 2 | from .lpcnet_vocoding_dataset import LPCNetVocodingDataset -------------------------------------------------------------------------------- /dnn/torch/osce/losses/td_lowpass.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import scipy.signal 3 | 4 | 5 | from utils.layers.fir import FIR 6 | 7 | class TDLowpass(torch.nn.Module): 8 | def __init__(self, numtaps, cutoff, power=2): 9 | super().__init__() 10 | 11 | self.b = scipy.signal.firwin(numtaps, cutoff) 12 | self.weight = torch.from_numpy(self.b).float().view(1, 1, -1) 13 | self.power = power 14 | 15 | def forward(self, y_true, y_pred): 16 | 17 | assert len(y_true.shape) == 3 and len(y_pred.shape) == 3 18 | 19 | diff = y_true - y_pred 20 | diff_lp = torch.nn.functional.conv1d(diff, self.weight) 21 | 22 | loss = torch.mean(torch.abs(diff_lp ** self.power)) 23 | 24 | return loss, diff_lp 25 | 26 | def get_freqz(self): 27 | freq, response = scipy.signal.freqz(self.b) 28 | 29 | return freq, response 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /dnn/torch/osce/models/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | from .lace import LACE 31 | from .no_lace import NoLACE 32 | from .lavoce import LaVoce 33 | from .lavoce_400 import LaVoce400 34 | from .fd_discriminator import TFDMultiResolutionDiscriminator as FDMResDisc 35 | 36 | model_dict = { 37 | 'lace': LACE, 38 | 'nolace': NoLACE, 39 | 'lavoce': LaVoce, 40 | 'lavoce400': LaVoce400, 41 | 'fdmresdisc': FDMResDisc, 42 | } 43 | -------------------------------------------------------------------------------- /dnn/torch/osce/requirements.txt: -------------------------------------------------------------------------------- 1 | pyyaml==6.0.1 2 | torch==2.0.1 3 | numpy==1.25.2 4 | scipy==1.11.2 5 | pesq==0.0.4 6 | gitpython==3.1.41 7 | matplotlib==3.7.3 8 | torchaudio==2.0.2 9 | tqdm==4.66.1 10 | -------------------------------------------------------------------------------- /dnn/torch/osce/silk_16_to_48.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from scipy.io import wavfile 4 | import torch 5 | import numpy as np 6 | 7 | from utils.layers.silk_upsampler import SilkUpsampler 8 | 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument("input", type=str, help="input wave file") 11 | parser.add_argument("output", type=str, help="output wave file") 12 | 13 | if __name__ == "__main__": 14 | args = parser.parse_args() 15 | 16 | fs, x = wavfile.read(args.input) 17 | 18 | # being lazy for now 19 | assert fs == 16000 and x.dtype == np.int16 20 | 21 | x = torch.from_numpy(x.astype(np.float32)).view(1, 1, -1) 22 | 23 | upsampler = SilkUpsampler() 24 | y = upsampler(x) 25 | 26 | y = y.squeeze().numpy().astype(np.int16) 27 | 28 | wavfile.write(args.output, 48000, y[13:]) -------------------------------------------------------------------------------- /dnn/torch/osce/stndrd/evaluation/create_input_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | INPUT="dataset/LibriSpeech" 5 | OUTPUT="testdata" 6 | OPUSDEMO="/local/experiments/ietf_enhancement_studies/bin/opus_demo_patched" 7 | BITRATES=( 6000 7500 ) # 9000 12000 15000 18000 24000 32000 ) 8 | 9 | 10 | mkdir -p $OUTPUT 11 | 12 | for fn in $(find $INPUT -name "*.wav") 13 | do 14 | name=$(basename ${fn%*.wav}) 15 | sox $fn -r 16000 -b 16 -e signed-integer ${OUTPUT}/tmp.raw 16 | for br in ${BITRATES[@]} 17 | do 18 | folder=${OUTPUT}/"${name}_${br}.se" 19 | echo "creating ${folder}..." 20 | mkdir -p $folder 21 | cp ${OUTPUT}/tmp.raw ${folder}/clean.s16 22 | (cd ${folder} && $OPUSDEMO voip 16000 1 $br clean.s16 noisy.s16) 23 | done 24 | rm -f ${OUTPUT}/tmp.raw 25 | done 26 | -------------------------------------------------------------------------------- /dnn/torch/osce/stndrd/evaluation/env.rc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PYTHON=/home/ubuntu/opt/miniconda3/envs/torch/bin/python 4 | export LACE="/local/experiments/ietf_enhancement_studies/checkpoints/lace_checkpoint.pth" 5 | export NOLACE="/local/experiments/ietf_enhancement_studies/checkpoints/nolace_checkpoint.pth" 6 | export TESTMODEL="/local/experiments/ietf_enhancement_studies/opus/dnn/torch/osce/test_model.py" 7 | export OPUSDEMO="/local/experiments/ietf_enhancement_studies/bin/opus_demo_patched" -------------------------------------------------------------------------------- /dnn/torch/osce/stndrd/presentation/playback.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | import matplotlib.pyplot as plt 3 | import matplotlib.animation 4 | 5 | def make_playback_animation(savepath, spec, duration_ms, vmin=20, vmax=90): 6 | fig, axs = plt.subplots() 7 | axs.set_axis_off() 8 | fig.set_size_inches((duration_ms / 1000 * 5, 5)) 9 | frames = [] 10 | frame_duration=20 11 | num_frames = int(duration_ms / frame_duration + .99) 12 | 13 | spec_height, spec_width = spec.shape 14 | for i in range(num_frames): 15 | xpos = (i - 1) / (num_frames - 3) * (spec_width - 1) 16 | new_frame = axs.imshow(spec, cmap='inferno', origin='lower', aspect='auto', vmin=vmin, vmax=vmax) 17 | if i in {0, num_frames - 1}: 18 | frames.append([new_frame]) 19 | else: 20 | line = axs.plot([xpos, xpos], [0, spec_height-1], color='white', alpha=0.8)[0] 21 | frames.append([new_frame, line]) 22 | 23 | 24 | ani = matplotlib.animation.ArtistAnimation(fig, frames, blit=True, interval=frame_duration) 25 | ani.save(savepath, dpi=720) -------------------------------------------------------------------------------- /dnn/torch/osce/utils/complexity.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def _conv1d_flop_count(layer, rate): 4 | return 2 * ((layer.in_channels + 1) * layer.out_channels * rate / layer.stride[0] ) * layer.kernel_size[0] 5 | 6 | 7 | def _dense_flop_count(layer, rate): 8 | return 2 * ((layer.in_features + 1) * layer.out_features * rate ) -------------------------------------------------------------------------------- /dnn/torch/osce/utils/layers/fir.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.signal 3 | import torch 4 | from torch import nn 5 | import torch.nn.functional as F 6 | 7 | 8 | class FIR(nn.Module): 9 | def __init__(self, numtaps, bands, desired, fs=2): 10 | super().__init__() 11 | 12 | if numtaps % 2 == 0: 13 | print(f"warning: numtaps must be odd, increasing numtaps to {numtaps + 1}") 14 | numtaps += 1 15 | 16 | a = scipy.signal.firls(numtaps, bands, desired, fs=fs) 17 | 18 | self.weight = torch.from_numpy(a.astype(np.float32)) 19 | 20 | def forward(self, x): 21 | num_channels = x.size(1) 22 | 23 | weight = torch.repeat_interleave(self.weight.view(1, 1, -1), num_channels, 0) 24 | 25 | y = F.conv1d(x, weight, groups=num_channels) 26 | 27 | return y -------------------------------------------------------------------------------- /dnn/torch/rdovae/README.md: -------------------------------------------------------------------------------- 1 | # Deep REDundancy (DRED) with RDO-VAE 2 | 3 | This is a rate-distortion-optimized variational autoencoder (RDO-VAE) designed 4 | to coding redundancy information. Pre-trained models are provided as C code 5 | in the dnn/ directory with the corresponding model in dnn/models/ directory 6 | (name starts with rdovae_). If you don't want to train a new DRED model, you can 7 | skip straight to the Inference section. 8 | 9 | ## Data preparation 10 | 11 | First, fetch all the data from the datasets.txt file using: 12 | ``` 13 | ./download_datasets.sh 14 | ``` 15 | 16 | Then concatenate and resample the data into a single 16-kHz file: 17 | ``` 18 | ./process_speech.sh 19 | ``` 20 | The script will produce an all_speech.pcm speech file in raw 16-bit PCM format. 21 | 22 | 23 | For data preparation you need to build Opus as detailed in the top-level README. 24 | You will need to use the --enable-dred configure option. 25 | The build will produce an executable named "dump_data". 26 | To prepare the training data, run: 27 | ``` 28 | ./dump_data -train all_speech.pcm all_features.f32 /dev/null 29 | ``` 30 | 31 | ## Training 32 | 33 | To perform training, run the following command: 34 | ``` 35 | python ./train_rdovae.py --sequence-length 400 --split-mode random_split --state-dim 80 --batch-size 512 --epochs 400 --lambda-max 0.04 --lr 0.003 --lr-decay-factor 0.0001 all_features.f32 output_dir 36 | ``` 37 | The final model will be in output_dir/checkpoints/chechpoint_400.pth. 38 | 39 | The model can be converted to C using: 40 | ``` 41 | python export_rdovae_weights.py output_dir/checkpoints/chechpoint_400.pth dred_c_dir 42 | ``` 43 | which will create a number of C source and header files in the fargan_c_dir directory. 44 | Copy these files to the opus/dnn/ directory (replacing the existing ones) and recompile Opus. 45 | 46 | ## Inference 47 | 48 | DRED is integrated within the Opus codec and can be evaluated using the opus_demo 49 | executable. For example: 50 | ``` 51 | ./opus_demo voip 16000 1 64000 -loss 50 -dred 100 -sim_loss 50 input.pcm output.pcm 52 | ``` 53 | Will tell the encoder to encode a 16 kHz raw audio file at 64 kb/s using up to 1 second 54 | of redundancy (units are based on 10-ms) and then simulate 50% loss. Refer to `opus_demo --help` 55 | for more details. 56 | -------------------------------------------------------------------------------- /dnn/torch/rdovae/download_datasets.sh: -------------------------------------------------------------------------------- 1 | mkdir datasets 2 | cd datasets 3 | for i in `grep https ../../../datasets.txt` 4 | do 5 | wget $i 6 | done 7 | -------------------------------------------------------------------------------- /dnn/torch/rdovae/packets/__init__.py: -------------------------------------------------------------------------------- 1 | from .fec_packets import write_fec_packets, read_fec_packets -------------------------------------------------------------------------------- /dnn/torch/rdovae/packets/fec_packets.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 _FEC_PACKETS_H 29 | #define _FEC_PACKETS_H 30 | 31 | int get_fec_frame(const char * const filename, float *features, int packet_index, int subframe_index); 32 | int get_fec_rate(const char * const filename, int packet_index); 33 | 34 | #endif -------------------------------------------------------------------------------- /dnn/torch/rdovae/process_speech.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd datasets 4 | 5 | #parallel -j +2 'unzip -n {}' ::: *.zip 6 | 7 | find . -name "*.wav" | parallel -k -j 20 'sox --no-dither {} -t sw -r 16000 -c 1 -' > ../all_speech.sw 8 | -------------------------------------------------------------------------------- /dnn/torch/rdovae/rdovae/__init__.py: -------------------------------------------------------------------------------- 1 | from .rdovae import RDOVAE, distortion_loss, hard_rate_estimate, soft_rate_estimate 2 | from .dataset import RDOVAEDataset 3 | -------------------------------------------------------------------------------- /dnn/torch/rdovae/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | torch 4 | tqdm -------------------------------------------------------------------------------- /dnn/torch/testsuite/README.md: -------------------------------------------------------------------------------- 1 | # lpcnet-testsuite 2 | 3 | ## setup 4 | The test script is written for Linux only. It requires sox to be installed and available. 5 | 6 | Setup is done as usual via 7 | 8 | ``` 9 | pip install -r requirements.txt 10 | ``` 11 | 12 | The test scrip run_warpq_test.py requires a setup file in yaml format, which specifies how 13 | to generate a wave file OUTPUT from a wave file INPUT sampled resampled to the specified 14 | sampling rate as a list of shell commands. This makes it easy to test other neural vocoders 15 | with it as well. Two examples are given in examples. INPUT and OUTPUT will be replaced by using 16 | the string.format(INPUT=input,OUTPUT=output) method. 17 | 18 | Here is one example: 19 | 20 | ``` 21 | test: "LPCNet reference test" 22 | processing: 23 | - "sox {INPUT} {INPUT}.raw" 24 | - "/local/code/LPCNet/lpcnet_demo -features {INPUT}.raw {INPUT}.features.f32" 25 | - "/local/code/LPCNet/lpcnet_demo -synthesis {INPUT}.features.f32 {INPUT}.decoded.raw" 26 | - "sox -r 16000 -L -e signed-integer -b 16 -c 1 {INPUT}.decoded.raw {OUTPUT}" 27 | ``` 28 | 29 | The structure of the output folder is as follows: 30 | 31 | ``` 32 | output_folder 33 | +-- html 34 | +-- index.html 35 | +-- items 36 | +-- processing 37 | +-- setup.yml 38 | +-- stats.txt 39 | +-- scores.txt 40 | ``` 41 | 42 | scores.txt contains the WARP-Q scores in descending order (best to worse) 43 | stats.txt contains mean values over all, the 10 best and the 10 worst items 44 | setup.yml contains all information to repeat the run 45 | htms contains a self-contained website displaying the 10 best and 10 worst items 46 | processing contains processing output -------------------------------------------------------------------------------- /dnn/torch/testsuite/examples/lpcnet_c_example.yml: -------------------------------------------------------------------------------- 1 | test: "LPCNet reference test" 2 | processing: 3 | - "sox {INPUT} {INPUT}.raw" 4 | - "/local/code/LPCNet/lpcnet_demo -features {INPUT}.raw {INPUT}.features.f32" 5 | - "/local/code/LPCNet/lpcnet_demo -synthesis {INPUT}.features.f32 {INPUT}.decoded.raw" 6 | - "sox -r 16000 -L -e signed-integer -b 16 -c 1 {INPUT}.decoded.raw {OUTPUT} trim 0.015" -------------------------------------------------------------------------------- /dnn/torch/testsuite/examples/lpcnet_c_plc_example.yml: -------------------------------------------------------------------------------- 1 | test: "LPCNet reference test" 2 | processing: 3 | - "sox {INPUT} {INPUT}.raw" 4 | - "/local/code/LPCNet/lpcnet_demo -plc_file causal {PLCFILE} {INPUT}.raw {INPUT}.decoded.raw" 5 | - "sox -r 16000 -L -e signed-integer -b 16 -c 1 {INPUT}.decoded.raw {OUTPUT}" -------------------------------------------------------------------------------- /dnn/torch/testsuite/examples/lpcnet_torch_example.yml: -------------------------------------------------------------------------------- 1 | test: "no noise test" 2 | processing: 3 | - "sox {INPUT} {INPUT}.raw" 4 | - "/home/ubuntu/bin/lpcnet_dump_data_v2 -test {INPUT}.raw {INPUT}.features.f32" 5 | - "/home/ubuntu/opt/miniconda3/envs/torch/bin/python /local/code/lpcnext/test_lpcnet.py {INPUT}.features.f32 /local/experiments/noise_augmentation/output/lpcnet_384_2/checkpoints/checkpoint_epoch_20.pth {OUTPUT}" -------------------------------------------------------------------------------- /dnn/torch/testsuite/requirements.txt: -------------------------------------------------------------------------------- 1 | scipy 2 | librosa 3 | numpy 4 | scikit-image 5 | pyvad 6 | speechpy 7 | soundfile 8 | pyyaml 9 | pesq 10 | AMFM_decompy 11 | matplotlib 12 | multiprocess -------------------------------------------------------------------------------- /dnn/torch/testsuite/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiph/opus/2941f08a616290f291579df9c8dbc0801d8d3f18/dnn/torch/testsuite/utils/__init__.py -------------------------------------------------------------------------------- /dnn/torch/testsuite/utils/files.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import os 31 | 32 | 33 | def get_wave_file_list(parent_folder, extensions=[".wav", ".flac"], check_for_features=False): 34 | """ traverses subfolders of parent_folder in search for files that match the given extension """ 35 | 36 | file_list = [] 37 | 38 | for root, dirs, files in os.walk(parent_folder, topdown=True): 39 | 40 | for file in files: 41 | 42 | stem, ext = os.path.splitext(file) 43 | 44 | #check for extension 45 | if not ext in extensions: 46 | continue 47 | 48 | # check if feature file exists 49 | if check_for_features and not os.path.isfile(os.path.join(root, stem + "_features.f32")): 50 | continue 51 | 52 | file_list.append(os.path.join(root, file)) 53 | 54 | return file_list -------------------------------------------------------------------------------- /dnn/torch/testsuite/utils/pesq.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | import pesq 31 | import librosa 32 | 33 | def compute_PESQ(ref, test, fs=16000): 34 | 35 | if not ref.endswith('.wav') or not test.endswith('.wav'): 36 | raise ValueError('error: expecting .wav as file extension') 37 | 38 | ref_item, _ = librosa.load(ref, sr=fs) 39 | test_item, _ = librosa.load(test, sr=fs) 40 | 41 | score = pesq.pesq(fs, ref_item, test_item) 42 | 43 | return score -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/README.md: -------------------------------------------------------------------------------- 1 | # weight-exchange 2 | 3 | 4 | 5 | ## Weight Exchange 6 | Repo wor exchanging weights betweeen torch an tensorflow.keras modules, using an intermediate numpy format. 7 | 8 | Routines for loading/dumping torch weights are located in exchange/torch and can be loaded with 9 | ``` 10 | import exchange.torch 11 | ``` 12 | and routines for loading/dumping tensorflow weights are located in exchange/tf and can be loaded with 13 | ``` 14 | import exchange.tf 15 | ``` 16 | 17 | Note that `exchange.torch` requires torch to be installed and `exchange.tf` requires tensorflow. To avoid the necessity of installing both torch and tensorflow in the working environment, none of these submodules is imported when calling `import exchange`. Similarly, the requirements listed in `requirements.txt` do include neither Tensorflow or Pytorch. 18 | 19 | 20 | ## C export 21 | The module `exchange.c_export` contains routines to export weights to C files. On the long run it will be possible to call all `dump_...` functions with either a path string or a `CWriter` instance based on which the export format is chosen. This is currently only implemented for `torch.nn.GRU`, `torch.nn.Linear` and `torch.nn.Conv1d`. -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | #!/usr/bin/env/python 31 | import os 32 | from setuptools import setup 33 | 34 | lib_folder = os.path.dirname(os.path.realpath(__file__)) 35 | 36 | with open(os.path.join(lib_folder, 'requirements.txt'), 'r') as f: 37 | install_requires = list(f.read().splitlines()) 38 | 39 | print(install_requires) 40 | 41 | setup(name='wexchange', 42 | version='1.6', 43 | author='Jan Buethe', 44 | author_email='jbuethe@amazon.de', 45 | description='Weight-exchange library between Pytorch and Tensorflow', 46 | packages=['wexchange', 'wexchange.tf', 'wexchange.torch', 'wexchange.c_export'], 47 | install_requires=install_requires 48 | ) 49 | -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/wexchange/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | from . import c_export -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/wexchange/c_export/__init__.py: -------------------------------------------------------------------------------- 1 | from .c_writer import CWriter 2 | """ 3 | /* Copyright (c) 2023 Amazon 4 | Written by Jan Buethe */ 5 | /* 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | """ 30 | 31 | from .common import print_gru_layer, print_dense_layer, print_conv1d_layer, print_tconv1d_layer, print_conv2d_layer, print_vector -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/wexchange/tf/__init__.py: -------------------------------------------------------------------------------- 1 | from .tf import dump_tf_conv1d_weights, load_tf_conv1d_weights 2 | from .tf import dump_tf_dense_weights, load_tf_dense_weights 3 | from .tf import dump_tf_embedding_weights, load_tf_embedding_weights 4 | from .tf import dump_tf_gru_weights, load_tf_gru_weights 5 | from .tf import dump_tf_weights, load_tf_weights -------------------------------------------------------------------------------- /dnn/torch/weight-exchange/wexchange/torch/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | /* Copyright (c) 2023 Amazon 3 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 20 | OR 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 | 30 | from .torch import dump_torch_conv1d_weights, load_torch_conv1d_weights 31 | from .torch import dump_torch_conv2d_weights, load_torch_conv2d_weights 32 | from .torch import dump_torch_dense_weights, load_torch_dense_weights 33 | from .torch import dump_torch_gru_weights, load_torch_gru_weights 34 | from .torch import dump_torch_grucell_weights 35 | from .torch import dump_torch_embedding_weights, load_torch_embedding_weights 36 | from .torch import dump_torch_weights, load_torch_weights 37 | from .torch import dump_torch_adaptive_conv1d_weights -------------------------------------------------------------------------------- /dnn/training_tf2/dataloader.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from tensorflow.keras.utils import Sequence 3 | from ulaw import lin2ulaw 4 | 5 | def lpc2rc(lpc): 6 | #print("shape is = ", lpc.shape) 7 | order = lpc.shape[-1] 8 | rc = 0*lpc 9 | for i in range(order, 0, -1): 10 | rc[:,:,i-1] = lpc[:,:,-1] 11 | ki = rc[:,:,i-1:i].repeat(i-1, axis=2) 12 | lpc = (lpc[:,:,:-1] - ki*lpc[:,:,-2::-1])/(1-ki*ki) 13 | return rc 14 | 15 | class LPCNetLoader(Sequence): 16 | def __init__(self, data, features, periods, batch_size, e2e=False, lookahead=2): 17 | self.batch_size = batch_size 18 | self.nb_batches = np.minimum(np.minimum(data.shape[0], features.shape[0]), periods.shape[0])//self.batch_size 19 | self.data = data[:self.nb_batches*self.batch_size, :] 20 | self.features = features[:self.nb_batches*self.batch_size, :] 21 | self.periods = periods[:self.nb_batches*self.batch_size, :] 22 | self.e2e = e2e 23 | self.lookahead = lookahead 24 | self.on_epoch_end() 25 | 26 | def on_epoch_end(self): 27 | self.indices = np.arange(self.nb_batches*self.batch_size) 28 | np.random.shuffle(self.indices) 29 | 30 | def __getitem__(self, index): 31 | data = self.data[self.indices[index*self.batch_size:(index+1)*self.batch_size], :, :] 32 | in_data = data[: , :, :1] 33 | out_data = data[: , :, 1:] 34 | features = self.features[self.indices[index*self.batch_size:(index+1)*self.batch_size], :, :-16] 35 | periods = self.periods[self.indices[index*self.batch_size:(index+1)*self.batch_size], :, :] 36 | outputs = [out_data] 37 | inputs = [in_data, features, periods] 38 | if self.lookahead > 0: 39 | lpc = self.features[self.indices[index*self.batch_size:(index+1)*self.batch_size], 4-self.lookahead:-self.lookahead, -16:] 40 | else: 41 | lpc = self.features[self.indices[index*self.batch_size:(index+1)*self.batch_size], 4:, -16:] 42 | if self.e2e: 43 | outputs.append(lpc2rc(lpc)) 44 | else: 45 | inputs.append(lpc) 46 | return (inputs, outputs) 47 | 48 | def __len__(self): 49 | return self.nb_batches 50 | -------------------------------------------------------------------------------- /dnn/training_tf2/diffembed.py: -------------------------------------------------------------------------------- 1 | """ 2 | Modification of Tensorflow's Embedding Layer: 3 | 1. Not restricted to be the first layer of a model 4 | 2. Differentiable (allows non-integer lookups) 5 | - For non integer lookup, this layer linearly interpolates between the adjacent embeddings in the following way to preserver gradient flow 6 | - E = (1 - frac(x))*embed(floor(x)) + frac(x)*embed(ceil(x)) 7 | """ 8 | 9 | import tensorflow as tf 10 | from tensorflow.keras.layers import Layer 11 | 12 | class diff_Embed(Layer): 13 | """ 14 | Parameters: 15 | - units: int 16 | Dimension of the Embedding 17 | - dict_size: int 18 | Number of Embeddings to lookup 19 | - pcm_init: boolean 20 | Initialized for the embedding matrix 21 | """ 22 | def __init__(self, units=128, dict_size = 256, pcm_init = True, initializer = None, **kwargs): 23 | super(diff_Embed, self).__init__(**kwargs) 24 | self.units = units 25 | self.dict_size = dict_size 26 | self.pcm_init = pcm_init 27 | self.initializer = initializer 28 | 29 | def build(self, input_shape): 30 | w_init = tf.random_normal_initializer() 31 | if self.pcm_init: 32 | w_init = self.initializer 33 | self.w = tf.Variable(initial_value=w_init(shape=(self.dict_size, self.units),dtype='float32'),trainable=True) 34 | 35 | def call(self, inputs): 36 | alpha = inputs - tf.math.floor(inputs) 37 | alpha = tf.expand_dims(alpha,axis = -1) 38 | alpha = tf.tile(alpha,[1,1,1,self.units]) 39 | inputs = tf.cast(inputs,'int32') 40 | M = (1 - alpha)*tf.gather(self.w,inputs) + alpha*tf.gather(self.w,tf.clip_by_value(inputs + 1, 0, 255)) 41 | return M 42 | 43 | def get_config(self): 44 | config = super(diff_Embed, self).get_config() 45 | config.update({"units": self.units}) 46 | config.update({"dict_size" : self.dict_size}) 47 | config.update({"pcm_init" : self.pcm_init}) 48 | config.update({"initializer" : self.initializer}) 49 | return config -------------------------------------------------------------------------------- /dnn/training_tf2/fec_packets.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 Amazon 2 | Written by Jan Buethe */ 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 COPYRIGHT OWNER 19 | OR 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 FEC_PACKETS_H 29 | #define FEC_PACKETS_H 30 | 31 | int get_fec_frame(const char * const filename, float *features, int packet_index, int subframe_index); 32 | int get_fec_rate(const char * const filename, int packet_index); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /dnn/training_tf2/parameters.py: -------------------------------------------------------------------------------- 1 | """ module for handling extra model parameters for tf.keras models """ 2 | 3 | import tensorflow as tf 4 | 5 | 6 | def set_parameter(model, parameter_name, parameter_value, dtype='float32'): 7 | """ stores parameter_value as non-trainable weight with name parameter_name:0 """ 8 | 9 | weights = [weight for weight in model.weights if weight.name == (parameter_name + ":0")] 10 | 11 | if len(weights) == 0: 12 | model.add_weight(parameter_name, trainable=False, initializer=tf.keras.initializers.Constant(parameter_value), dtype=dtype) 13 | elif len(weights) == 1: 14 | weights[0].assign(parameter_value) 15 | else: 16 | raise ValueError(f"more than one weight starting with {parameter_name}:0 in model") 17 | 18 | 19 | def get_parameter(model, parameter_name, default=None): 20 | """ returns parameter value if parameter is present in model and otherwise default """ 21 | 22 | weights = [weight for weight in model.weights if weight.name == (parameter_name + ":0")] 23 | 24 | if len(weights) == 0: 25 | return default 26 | elif len(weights) > 1: 27 | raise ValueError(f"more than one weight starting with {parameter_name}:0 in model") 28 | else: 29 | return weights[0].numpy().item() 30 | -------------------------------------------------------------------------------- /dnn/training_tf2/ulaw.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import math 4 | 5 | scale = 255.0/32768.0 6 | scale_1 = 32768.0/255.0 7 | def ulaw2lin(u): 8 | u = u - 128 9 | s = np.sign(u) 10 | u = np.abs(u) 11 | return s*scale_1*(np.exp(u/128.*math.log(256))-1) 12 | 13 | 14 | def lin2ulaw(x): 15 | s = np.sign(x) 16 | x = np.abs(x) 17 | u = (s*(128*np.log(1+scale*x)/math.log(256))) 18 | u = np.clip(128 + np.round(u), 0, 255) 19 | return u.astype('int16') 20 | -------------------------------------------------------------------------------- /dnn/x86/nnet_avx2.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018-2019 Mozilla 2 | 2023 Amazon */ 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "x86/x86_arch_macros.h" 33 | 34 | #ifndef __AVX2__ 35 | #error nnet_avx2.c is being compiled without AVX2 enabled 36 | #endif 37 | 38 | #define RTCD_ARCH avx2 39 | 40 | #include "nnet_arch.h" 41 | -------------------------------------------------------------------------------- /dnn/x86/nnet_sse2.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018-2019 Mozilla 2 | 2023 Amazon */ 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "x86/x86_arch_macros.h" 33 | 34 | #ifndef __SSE2__ 35 | #error nnet_sse2.c is being compiled without SSE2 enabled 36 | #endif 37 | 38 | #define RTCD_ARCH sse2 39 | 40 | #include "nnet_arch.h" 41 | -------------------------------------------------------------------------------- /dnn/x86/nnet_sse4_1.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018-2019 Mozilla 2 | 2023 Amazon */ 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 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "x86/x86_arch_macros.h" 33 | 34 | #ifndef __SSE4_1__ 35 | #error nnet_sse4_1.c is being compiled without SSE4.1 enabled 36 | #endif 37 | 38 | #define RTCD_ARCH sse4_1 39 | 40 | #include "nnet_arch.h" 41 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | DOCINPUTS = $(top_srcdir)/include/opus.h \ 4 | $(top_srcdir)/include/opus_multistream.h \ 5 | $(top_srcdir)/include/opus_defines.h \ 6 | $(top_srcdir)/include/opus_types.h \ 7 | $(top_srcdir)/include/opus_custom.h \ 8 | $(top_srcdir)/doc/header.html \ 9 | $(top_srcdir)/doc/footer.html \ 10 | $(top_srcdir)/doc/customdoxygen.css 11 | 12 | EXTRA_DIST = customdoxygen.css Doxyfile.in footer.html header.html \ 13 | opus_logo.svg trivial_example.c 14 | 15 | 16 | if HAVE_DOXYGEN 17 | 18 | all-local: doxygen-build.stamp 19 | 20 | doxygen-build.stamp: Doxyfile $(DOCINPUTS) 21 | doxygen 22 | touch $@ 23 | 24 | install-data-local: 25 | $(INSTALL) -d $(DESTDIR)$(docdir)/html/search 26 | for f in `find html -type f \! -name "installdox"`; do \ 27 | $(INSTALL_DATA) $$f $(DESTDIR)$(docdir)/$$f; \ 28 | done 29 | 30 | $(INSTALL) -d $(DESTDIR)$(mandir)/man3 31 | cd man && find man3 -type f -name opus_*.3 \ 32 | -exec $(INSTALL_DATA) \{} $(DESTDIR)$(mandir)/man3 \; 33 | 34 | clean-local: 35 | $(RM) -r html 36 | $(RM) -r latex 37 | $(RM) -r man 38 | $(RM) doxygen-build.stamp 39 | $(RM) doxygen_sqlite3.db 40 | 41 | uninstall-local: 42 | $(RM) -r $(DESTDIR)$(docdir)/html 43 | $(RM) $(DESTDIR)$(mandir)/man3/opus_*.3 $(DESTDIR)$(mandir)/man3/opus.h.3 44 | 45 | endif 46 | -------------------------------------------------------------------------------- /doc/build_isobmff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2014 Xiph.Org Foundation and Mozilla Foundation 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 COPYRIGHT OWNER 20 | # OR 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 | #Stop on errors 29 | set -e 30 | #Set the CWD to the location of this script 31 | [ -n "${0%/*}" ] && cd "${0%/*}" 32 | 33 | HTML=opus_in_isobmff.html 34 | 35 | echo downloading updates... 36 | CSS=${HTML%%.html}.css 37 | wget -q http://vfrmaniac.fushizen.eu/contents/${HTML} -O ${HTML} 38 | wget -q http://vfrmaniac.fushizen.eu/style.css -O ${CSS} 39 | 40 | echo updating links... 41 | cat ${HTML} | sed -e "s/\\.\\.\\/style.css/${CSS}/" > ${HTML}+ && mv ${HTML}+ ${HTML} 42 | 43 | echo stripping... 44 | cat ${HTML} | sed -e 's///g' > ${HTML}+ && mv ${HTML}+ ${HTML} 45 | cat ${HTML} | sed -e 's/ *$//g' > ${HTML}+ && mv ${HTML}+ ${HTML} 46 | cat ${CSS} | sed -e 's/ *$//g' > ${CSS}+ && mv ${CSS}+ ${CSS} 47 | 48 | 49 | VERSION=$(grep -F Version ${HTML} | sed 's/.*Version \([0-9]\.[0-9]\.[0-9]\).*/\1/') 50 | echo Now at version ${VERSION} 51 | -------------------------------------------------------------------------------- /doc/build_oggdraft.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2012 Xiph.Org Foundation and Mozilla Corporation 4 | # 5 | # This file is extracted from RFC6716. Please see that RFC for additional 6 | # information. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # - Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # - Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # 19 | # - Neither the name of Internet Society, IETF or IETF Trust, nor the 20 | # names of specific contributors, may be used to endorse or promote 21 | # products derived from this software without specific prior written 22 | # permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 28 | # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | #Stop on errors 37 | set -e 38 | #Set the CWD to the location of this script 39 | [ -n "${0%/*}" ] && cd "${0%/*}" 40 | 41 | if test -z `which xml2rfc 2> /dev/null`; then 42 | echo "Error: couldn't find xml2rfc." 43 | echo 44 | echo "Please install xml2rfc version 2 or later." 45 | echo "E.g. 'pip install xml2rfc' or follow the instructions" 46 | echo "on http://pypi.python.org/pypi/xml2rfc/ or tools.ietf.org." 47 | exit 1 48 | fi 49 | 50 | echo running xml2rfc 51 | # version 2 syntax 52 | xml2rfc draft-ietf-codec-oggopus.xml --text --html 53 | -------------------------------------------------------------------------------- /doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 27 | 28 | 29 |
18 | For more information visit the Opus Website. 19 | 21 | 26 |
30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $projectname: $title 10 | $title 11 | 12 | 13 | 14 | $treeview 15 | $search 16 | $mathjax 17 | 18 | $extrastylesheet 19 | 20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
33 |
Opus
34 |
36 | 39 | 41 |
37 |
$projectbrief
38 |
$projectnumber 40 |
42 |
47 |
$projectbrief
48 |
$searchbox
59 |
60 | 61 | 62 | -------------------------------------------------------------------------------- /doc/meson.build: -------------------------------------------------------------------------------- 1 | have_dot = find_program('dot', required: false).found() 2 | 3 | doxyfile_conf = configuration_data() 4 | doxyfile_conf.set('VERSION', opus_version) 5 | doxyfile_conf.set('HAVE_DOT', have_dot) 6 | doxyfile_conf.set('top_srcdir', top_srcdir) 7 | doxyfile_conf.set('top_builddir', top_builddir) 8 | 9 | doxyfile = configure_file(input: 'Doxyfile.in', 10 | output: 'Doxyfile', 11 | configuration: doxyfile_conf, 12 | install: false) 13 | 14 | docdir = join_paths(get_option('datadir'), get_option('docdir')) 15 | 16 | doc_inputs = [ 17 | 'customdoxygen.css', 18 | 'footer.html', 19 | 'header.html', 20 | 'opus_logo.svg', 21 | top_srcdir + '/include/opus.h', 22 | top_srcdir + '/include/opus_multistream.h', 23 | top_srcdir + '/include/opus_defines.h', 24 | top_srcdir + '/include/opus_types.h', 25 | top_srcdir + '/include/opus_custom.h', 26 | ] 27 | 28 | custom_target('doc', 29 | input: [ doxyfile ] + doc_inputs, 30 | output: [ 'html' ], 31 | command: [ doxygen, doxyfile ], 32 | install_dir: docdir, 33 | install: true) 34 | -------------------------------------------------------------------------------- /doc/opus_in_isobmff.css: -------------------------------------------------------------------------------- 1 | /* Normal links */ 2 | .normal_link a:link 3 | { 4 | color : yellow; 5 | } 6 | .normal_link a:visited 7 | { 8 | color : green; 9 | } 10 | 11 | /* Boxes */ 12 | .pre 13 | { 14 | white-space: pre; /* CSS 2.0 */ 15 | white-space: pre-wrap; /* CSS 2.1 */ 16 | white-space: -pre-wrap; /* Opera 4-6 */ 17 | white-space: -o-pre-wrap; /* Opera 7 */ 18 | white-space: -moz-pre-wrap; /* Mozilla */ 19 | white-space: -hp-pre-wrap; /* HP Printers */ 20 | word-wrap : break-word; /* IE 5+ */ 21 | } 22 | 23 | .title_box 24 | { 25 | width : 470px; 26 | height : 70px; 27 | margin : 2px 50px 2px 2px; 28 | padding : 10px; 29 | border : 1px solid black; 30 | background-color : #666666; 31 | white-space : pre; 32 | float : left; 33 | text-align : center; 34 | color : #C0C0C0; 35 | font-size : 50pt; 36 | font-style : italic; 37 | } 38 | 39 | .subindex_box 40 | { 41 | margin : 5px; 42 | padding : 14px 22px; 43 | border : 1px solid black; 44 | background-color : #778877; 45 | float : left; 46 | text-align : center; 47 | color : #115555; 48 | font-size : 32pt; 49 | } 50 | 51 | .frame_box 52 | { 53 | margin : 10px; 54 | padding : 10px; 55 | border : 0px; 56 | background-color : #084040; 57 | text-align : left; 58 | color : #C0C0C0; 59 | font-family : monospace; 60 | } 61 | -------------------------------------------------------------------------------- /doc/release.txt: -------------------------------------------------------------------------------- 1 | = Release checklist = 2 | 3 | == Source release == 4 | 5 | - Check for uncommitted changes to master. 6 | - Update OPUS_LT_* API versioning in configure.ac. 7 | - Tag the release commit with 'git tag -s vN.M'. 8 | - Include release notes in the tag annotation. 9 | - Verify 'make distcheck' produces a tarball with 10 | the desired name. 11 | - Push tag to public repo. 12 | - Upload source package 'opus-${version}.tar.gz' 13 | - Add to https://svn.xiph.org/releases/opus/ 14 | - Update checksum files 15 | - svn commit 16 | - Copy to archive.mozilla.org/pub/opus/ 17 | - Update checksum files there as well. 18 | - Add release notes to https://gitlab.xiph.org/xiph/opus-website.git 19 | - Update links and checksums on the downloads page. 20 | - Add a copy of the documentation to 21 | and update the links. 22 | - Update /topic in #opus IRC channel. 23 | 24 | Releases are committed to https://svn.xiph.org/releases/opus/ 25 | which propagates to downloads.xiph.org, and copied manually 26 | to https://archive.mozilla.org/pub/opus/ 27 | 28 | Website updates are committed to https://gitlab.xiph.org/xiph/opus-website.git 29 | which propagates to https://opus-codec.org/ 30 | 31 | == Binary release == 32 | 33 | We usually build opus-tools binaries for MacOS and Windows. 34 | 35 | Binary releases are copied manually to 36 | https://archive.mozilla.org/pub/opus/win32/ 37 | 38 | For Mac, submit a pull request to homebrew. 39 | 40 | == Website updates == 41 | 42 | For major releases, recreate the files on https://opus-codec.org/examples/ 43 | with the next encoder. 44 | -------------------------------------------------------------------------------- /include/meson.build: -------------------------------------------------------------------------------- 1 | opus_headers = [ 2 | 'opus.h', 3 | 'opus_multistream.h', 4 | 'opus_projection.h', 5 | 'opus_types.h', 6 | 'opus_defines.h', 7 | ] 8 | 9 | if opt_custom_modes 10 | opus_headers += ['opus_custom.h'] 11 | endif 12 | 13 | install_headers(opus_headers, subdir: 'opus') 14 | -------------------------------------------------------------------------------- /lpcnet_headers.mk: -------------------------------------------------------------------------------- 1 | DEEP_PLC_HEAD = \ 2 | dnn/lpcnet.h \ 3 | dnn/burg.h \ 4 | dnn/common.h \ 5 | dnn/freq.h \ 6 | dnn/fargan.h \ 7 | dnn/fargan_data.h \ 8 | dnn/lpcnet_private.h \ 9 | dnn/nnet.h \ 10 | dnn/plc_data.h \ 11 | dnn/vec.h \ 12 | dnn/vec_avx.h \ 13 | dnn/vec_neon.h \ 14 | dnn/pitchdnn.h \ 15 | dnn/pitchdnn_data.h \ 16 | dnn/x86/dnn_x86.h \ 17 | dnn/nnet_arch.h \ 18 | dnn/arm/dnn_arm.h 19 | 20 | DRED_HEAD = \ 21 | dnn/dred_coding.h \ 22 | dnn/dred_config.h \ 23 | dnn/dred_decoder.h \ 24 | dnn/dred_encoder.h \ 25 | dnn/dred_rdovae.h \ 26 | dnn/dred_rdovae_constants.h \ 27 | dnn/dred_rdovae_enc.h \ 28 | dnn/dred_rdovae_enc_data.h \ 29 | dnn/dred_rdovae_dec.h \ 30 | dnn/dred_rdovae_dec_data.h \ 31 | dnn/dred_rdovae_stats_data.h 32 | 33 | OSCE_HEAD= \ 34 | dnn/osce.h \ 35 | dnn/osce_config.h \ 36 | dnn/osce_structs.h \ 37 | dnn/osce_features.h \ 38 | dnn/nndsp.h \ 39 | dnn/lace_data.h \ 40 | dnn/nolace_data.h 41 | 42 | LOSSGEN_HEAD = \ 43 | dnn/lossgen.h \ 44 | dnn/lossgen_data.h 45 | -------------------------------------------------------------------------------- /lpcnet_sources.mk: -------------------------------------------------------------------------------- 1 | DEEP_PLC_SOURCES = \ 2 | dnn/burg.c \ 3 | dnn/freq.c \ 4 | dnn/fargan.c \ 5 | dnn/fargan_data.c \ 6 | dnn/lpcnet_enc.c \ 7 | dnn/lpcnet_plc.c \ 8 | dnn/lpcnet_tables.c \ 9 | dnn/nnet.c \ 10 | dnn/nnet_default.c \ 11 | dnn/plc_data.c \ 12 | dnn/parse_lpcnet_weights.c \ 13 | dnn/pitchdnn.c \ 14 | dnn/pitchdnn_data.c 15 | 16 | DRED_SOURCES = \ 17 | dnn/dred_rdovae_enc.c \ 18 | dnn/dred_rdovae_enc_data.c \ 19 | dnn/dred_rdovae_dec.c \ 20 | dnn/dred_rdovae_dec_data.c \ 21 | dnn/dred_rdovae_stats_data.c \ 22 | dnn/dred_encoder.c \ 23 | dnn/dred_coding.c \ 24 | dnn/dred_decoder.c 25 | 26 | OSCE_SOURCES = \ 27 | dnn/osce.c \ 28 | dnn/osce_features.c \ 29 | dnn/nndsp.c \ 30 | dnn/lace_data.c \ 31 | dnn/nolace_data.c 32 | 33 | LOSSGEN_SOURCES = \ 34 | dnn/lossgen.c \ 35 | dnn/lossgen_data.c 36 | 37 | DNN_SOURCES_X86_RTCD = dnn/x86/x86_dnn_map.c 38 | DNN_SOURCES_AVX2 = dnn/x86/nnet_avx2.c 39 | DNN_SOURCES_SSE4_1 = dnn/x86/nnet_sse4_1.c 40 | DNN_SOURCES_SSE2 = dnn/x86/nnet_sse2.c 41 | 42 | DNN_SOURCES_ARM_RTCD = dnn/arm/arm_dnn_map.c 43 | DNN_SOURCES_DOTPROD = dnn/arm/nnet_dotprod.c 44 | DNN_SOURCES_NEON = dnn/arm/nnet_neon.c 45 | -------------------------------------------------------------------------------- /m4/ax_add_fortify_source.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # Modified from https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_ADD_FORTIFY_SOURCE 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether -D_FORTIFY_SOURCE=2 can be added to CFLAGS without macro 12 | # redefinition warnings. Some distributions (such as Gentoo Linux) enable 13 | # _FORTIFY_SOURCE globally in their compilers, leading to unnecessary 14 | # warnings in the form of 15 | # 16 | # :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] 17 | # : note: this is the location of the previous definition 18 | # 19 | # which is a problem if -Werror is enabled. This macro checks whether 20 | # _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2 21 | # to CFLAGS. 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2017 David Seifert 26 | # 27 | # Copying and distribution of this file, with or without modification, are 28 | # permitted in any medium without royalty provided the copyright notice 29 | # and this notice are preserved. This file is offered as-is, without any 30 | # warranty. 31 | 32 | #serial 1 33 | 34 | AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ 35 | AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CFLAGS]) 36 | AC_LINK_IFELSE([ 37 | AC_LANG_SOURCE( 38 | [[ 39 | int main() { 40 | #ifndef _FORTIFY_SOURCE 41 | return 0; 42 | #else 43 | this_is_an_error; 44 | #endif 45 | } 46 | ]] 47 | )], [ 48 | AC_MSG_RESULT([yes]) 49 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" 50 | ], [ 51 | AC_MSG_RESULT([no]) 52 | ]) 53 | ]) 54 | -------------------------------------------------------------------------------- /m4/opus-intrinsics.m4: -------------------------------------------------------------------------------- 1 | dnl opus-intrinsics.m4 2 | dnl macro for testing for support for compiler intrinsics, either by default or with a compiler flag 3 | 4 | dnl OPUS_CHECK_INTRINSICS(NAME-OF-INTRINSICS, COMPILER-FLAG-FOR-INTRINSICS, VAR-IF-PRESENT, VAR-IF-DEFAULT, TEST-PROGRAM-HEADER, TEST-PROGRAM-BODY) 5 | AC_DEFUN([OPUS_CHECK_INTRINSICS], 6 | [ 7 | AC_MSG_CHECKING([if compiler supports $1 intrinsics]) 8 | AC_LINK_IFELSE( 9 | [AC_LANG_PROGRAM($5, $6)], 10 | [ 11 | $3=1 12 | $4=1 13 | AC_MSG_RESULT([yes]) 14 | ],[ 15 | $4=0 16 | AC_MSG_RESULT([no]) 17 | AC_MSG_CHECKING([if compiler supports $1 intrinsics with $2]) 18 | save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $2" 19 | AC_LINK_IFELSE([AC_LANG_PROGRAM($5, $6)], 20 | [ 21 | AC_MSG_RESULT([yes]) 22 | $3=1 23 | ],[ 24 | AC_MSG_RESULT([no]) 25 | $3=0 26 | ]) 27 | CFLAGS="$save_CFLAGS" 28 | ]) 29 | ]) 30 | -------------------------------------------------------------------------------- /meson/read-sources-list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # opus/read-sources-list.py 4 | # 5 | # Parses .mk files and extracts list of source files. 6 | # Prints one line per source file list, with filenames space-separated. 7 | 8 | import sys 9 | 10 | if len(sys.argv) < 2: 11 | sys.exit('Usage: {} sources_foo.mk [sources_bar.mk...]'.format(sys.argv[0])) 12 | 13 | for input_fn in sys.argv[1:]: 14 | with open(input_fn, 'r', encoding='utf8') as f: 15 | text = f.read() 16 | text = text.replace('\\\n', '') 17 | 18 | # Remove empty lines 19 | lines = [line for line in text.split('\n') if line.strip()] 20 | 21 | # Print SOURCES_XYZ = file1.c file2.c 22 | for line in lines: 23 | values = line.strip().split('=', maxsplit=2) 24 | if len(values) != 2: 25 | raise RuntimeError('Unable to parse line "{}" from file "{}"'.format(line, input_fn)) 26 | var, files = values 27 | sources_list = [f for f in files.split(' ') if f] 28 | print(var.strip(), '=', ' '.join(sources_list)) 29 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | # Optimizations 2 | option('fixed-point', type : 'boolean', value : false, description : 'Compile without floating point (for machines without a fast enough FPU') 3 | option('fixed-point-debug', type : 'boolean', value : false, description : 'Debug fixed-point implementation') 4 | option('float-api', type : 'boolean', value : true, description : 'Compile with or without the floating point API (for machines with no float library') 5 | option('float-approx', type : 'boolean', value : false, description : 'Enable fast approximations for floating point (not supported on all platforms)') 6 | option('rtcd', type : 'feature', value : 'auto', description : 'Run-time CPU capabilities detection') 7 | option('asm', type : 'feature', value : 'auto', description : 'Assembly optimizations for ARM (fixed-point)') 8 | option('intrinsics', type : 'feature', value : 'auto', description : 'Intrinsics optimizations for ARM NEON or x86') 9 | 10 | option('deep-plc', type : 'feature', value : 'disabled', description : 'Enable Deep Packet Loss Concealment (PLC)') 11 | option('dred', type : 'feature', value : 'disabled', description : 'Enable Deep Redundancy (DRED)') 12 | option('osce', type : 'feature', value : 'disabled', description : 'Enable Opus Speech Coding Enhancement (OSCE)') 13 | option('dnn-debug-float', type : 'feature', value : 'disabled', description : 'Compute DNN using float weights') 14 | 15 | option('custom-modes', type : 'boolean', value : false, description : 'Enable non-Opus modes, e.g. 44.1 kHz & 2^n frames') 16 | option('extra-programs', type : 'feature', value : 'auto', description : 'Extra programs (demo and tests)') 17 | option('assertions', type : 'boolean', value : false, description : 'Additional software error checking') 18 | option('hardening', type : 'boolean', value : true, description : 'Run-time checks that are cheap and safe for use in production') 19 | option('fuzzing', type : 'boolean', value : false, description : 'Causes the encoder to make random decisions') 20 | option('check-asm', type : 'boolean', value : false, description : 'Run bit-exactness checks between optimized and c implementations') 21 | 22 | # common feature options 23 | option('tests', type : 'feature', value : 'auto', description : 'Build tests') 24 | option('docs', type: 'feature', value: 'auto', description: 'Build API documentation') 25 | 26 | # other options 27 | option('docdir', type: 'string', value: 'doc/opus', description: 'Directory to install documentation into (default: DATADIR/doc/opus') 28 | -------------------------------------------------------------------------------- /opus-uninstalled.pc.in: -------------------------------------------------------------------------------- 1 | # Opus codec reference implementation uninstalled pkg-config file 2 | 3 | libdir=${pcfiledir}/.libs 4 | includedir=${pcfiledir} 5 | 6 | Name: opus uninstalled 7 | Description: Opus IETF audio codec (not installed, @PC_BUILD@) 8 | Version: @VERSION@ 9 | Requires: 10 | Conflicts: 11 | Libs: ${libdir}/libopus.la @LIBM@ 12 | Cflags: -I${pcfiledir}/@top_srcdir@/include 13 | -------------------------------------------------------------------------------- /opus.pc.in: -------------------------------------------------------------------------------- 1 | # Opus codec reference implementation pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: Opus 9 | Description: Opus IETF audio codec (@PC_BUILD@ build) 10 | URL: https://opus-codec.org/ 11 | Version: @VERSION@ 12 | Requires: 13 | Conflicts: 14 | Libs: -L${libdir} -lopus 15 | Libs.private: @LIBM@ 16 | Cflags: -I${includedir}/opus 17 | -------------------------------------------------------------------------------- /opus_headers.mk: -------------------------------------------------------------------------------- 1 | OPUS_HEAD = \ 2 | include/opus.h \ 3 | include/opus_multistream.h \ 4 | include/opus_projection.h \ 5 | src/opus_private.h \ 6 | src/analysis.h \ 7 | src/mapping_matrix.h \ 8 | src/mlp.h 9 | -------------------------------------------------------------------------------- /opus_sources.mk: -------------------------------------------------------------------------------- 1 | OPUS_SOURCES = \ 2 | src/opus.c \ 3 | src/opus_decoder.c \ 4 | src/opus_encoder.c \ 5 | src/extensions.c \ 6 | src/opus_multistream.c \ 7 | src/opus_multistream_encoder.c \ 8 | src/opus_multistream_decoder.c \ 9 | src/repacketizer.c \ 10 | src/opus_projection_encoder.c \ 11 | src/opus_projection_decoder.c \ 12 | src/mapping_matrix.c 13 | 14 | OPUS_SOURCES_FLOAT = \ 15 | src/analysis.c \ 16 | src/mlp.c \ 17 | src/mlp_data.c 18 | -------------------------------------------------------------------------------- /scripts/dump_rnn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | from keras.models import Sequential 6 | from keras.layers import Dense 7 | from keras.layers import LSTM 8 | from keras.layers import GRU 9 | from keras.models import load_model 10 | from keras import backend as K 11 | 12 | import numpy as np 13 | 14 | def printVector(f, vector, name): 15 | v = np.reshape(vector, (-1)); 16 | #print('static const float ', name, '[', len(v), '] = \n', file=f) 17 | f.write('static const opus_int16 {}[{}] = {{\n '.format(name, len(v))) 18 | for i in range(0, len(v)): 19 | f.write('{}'.format(int(round(8192*v[i])))) 20 | if (i!=len(v)-1): 21 | f.write(',') 22 | else: 23 | break; 24 | if (i%8==7): 25 | f.write("\n ") 26 | else: 27 | f.write(" ") 28 | #print(v, file=f) 29 | f.write('\n};\n\n') 30 | return; 31 | 32 | def binary_crossentrop2(y_true, y_pred): 33 | return K.mean(2*K.abs(y_true-0.5) * K.binary_crossentropy(y_pred, y_true), axis=-1) 34 | 35 | 36 | model = load_model("weights.hdf5", custom_objects={'binary_crossentrop2': binary_crossentrop2}) 37 | 38 | weights = model.get_weights() 39 | 40 | f = open('rnn_weights.c', 'w') 41 | 42 | f.write('/*This file is automatically generated from a Keras model*/\n\n') 43 | f.write('#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif\n\n#include "mlp.h"\n\n') 44 | 45 | printVector(f, weights[0], 'layer0_weights') 46 | printVector(f, weights[1], 'layer0_bias') 47 | printVector(f, weights[2], 'layer1_weights') 48 | printVector(f, weights[3], 'layer1_recur_weights') 49 | printVector(f, weights[4], 'layer1_bias') 50 | printVector(f, weights[5], 'layer2_weights') 51 | printVector(f, weights[6], 'layer2_bias') 52 | 53 | f.write('const DenseLayer layer0 = {\n layer0_bias,\n layer0_weights,\n 25, 16, 0\n};\n\n') 54 | f.write('const GRULayer layer1 = {\n layer1_bias,\n layer1_weights,\n layer1_recur_weights,\n 16, 12\n};\n\n') 55 | f.write('const DenseLayer layer2 = {\n layer2_bias,\n layer2_weights,\n 12, 2, 1\n};\n\n') 56 | 57 | f.close() 58 | -------------------------------------------------------------------------------- /scripts/rnn_train.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | from keras.models import Sequential 6 | from keras.models import Model 7 | from keras.layers import Input 8 | from keras.layers import Dense 9 | from keras.layers import LSTM 10 | from keras.layers import GRU 11 | from keras.layers import SimpleRNN 12 | from keras.layers import Dropout 13 | from keras import losses 14 | import h5py 15 | 16 | from keras import backend as K 17 | import numpy as np 18 | 19 | def binary_crossentrop2(y_true, y_pred): 20 | return K.mean(2*K.abs(y_true-0.5) * K.binary_crossentropy(y_pred, y_true), axis=-1) 21 | 22 | print('Build model...') 23 | #model = Sequential() 24 | #model.add(Dense(16, activation='tanh', input_shape=(None, 25))) 25 | #model.add(GRU(12, dropout=0.0, recurrent_dropout=0.0, activation='tanh', recurrent_activation='sigmoid', return_sequences=True)) 26 | #model.add(Dense(2, activation='sigmoid')) 27 | 28 | main_input = Input(shape=(None, 25), name='main_input') 29 | x = Dense(16, activation='tanh')(main_input) 30 | x = GRU(12, dropout=0.1, recurrent_dropout=0.1, activation='tanh', recurrent_activation='sigmoid', return_sequences=True)(x) 31 | x = Dense(2, activation='sigmoid')(x) 32 | model = Model(inputs=main_input, outputs=x) 33 | 34 | batch_size = 64 35 | 36 | print('Loading data...') 37 | with h5py.File('features.h5', 'r') as hf: 38 | all_data = hf['features'][:] 39 | print('done.') 40 | 41 | window_size = 1500 42 | 43 | nb_sequences = len(all_data)/window_size 44 | print(nb_sequences, ' sequences') 45 | x_train = all_data[:nb_sequences*window_size, :-2] 46 | x_train = np.reshape(x_train, (nb_sequences, window_size, 25)) 47 | 48 | y_train = np.copy(all_data[:nb_sequences*window_size, -2:]) 49 | y_train = np.reshape(y_train, (nb_sequences, window_size, 2)) 50 | 51 | all_data = 0; 52 | x_train = x_train.astype('float32') 53 | y_train = y_train.astype('float32') 54 | 55 | print(len(x_train), 'train sequences. x shape =', x_train.shape, 'y shape = ', y_train.shape) 56 | 57 | # try using different optimizers and different optimizer configs 58 | model.compile(loss=binary_crossentrop2, 59 | optimizer='adam', 60 | metrics=['binary_accuracy']) 61 | 62 | print('Train...') 63 | model.fit(x_train, y_train, 64 | batch_size=batch_size, 65 | epochs=200, 66 | validation_data=(x_train, y_train)) 67 | model.save("newweights.hdf5") 68 | -------------------------------------------------------------------------------- /scripts/shrink_model.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in fargan_data.c pitchdnn_data.c dred_rdovae_dec_data.c dred_rdovae_enc_data.c plc_data.c lace_data.c nolace_data.c 4 | do 5 | cat dnn/$i | perl -ne 'if (/DEBUG/ || /#else/) {$skip=1} if (!$skip && !/ifdef DOT_PROD/) {s/^ *//; s/, /,/g; print $_} elsif (/endif/) {$skip=0}' > tmp_data.c 6 | mv tmp_data.c dnn/$i 7 | done 8 | -------------------------------------------------------------------------------- /silk/arm/SigProc_FIX_armv4.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (C) 2013 Xiph.Org Foundation and contributors 3 | Copyright (c) 2013 Parrot 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 | - Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | - Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 13 | names of specific contributors, may be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | ***********************************************************************/ 28 | 29 | #ifndef SILK_SIGPROC_FIX_ARMv4_H 30 | #define SILK_SIGPROC_FIX_ARMv4_H 31 | 32 | #undef silk_MLA 33 | static OPUS_INLINE opus_int32 silk_MLA_armv4(opus_int32 a, opus_int32 b, 34 | opus_int32 c) 35 | { 36 | opus_int32 res; 37 | __asm__( 38 | "#silk_MLA\n\t" 39 | "mla %0, %1, %2, %3\n\t" 40 | : "=&r"(res) 41 | : "r"(b), "r"(c), "r"(a) 42 | ); 43 | return res; 44 | } 45 | #define silk_MLA(a, b, c) (silk_MLA_armv4(a, b, c)) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /silk/arm/macros_arm64.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (C) 2015 Vidyo 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SILK_MACROS_ARM64_H 29 | #define SILK_MACROS_ARM64_H 30 | 31 | #include 32 | 33 | #undef silk_ADD_SAT32 34 | #define silk_ADD_SAT32(a, b) (vqadds_s32((a), (b))) 35 | 36 | #undef silk_SUB_SAT32 37 | #define silk_SUB_SAT32(a, b) (vqsubs_s32((a), (b))) 38 | 39 | #endif /* SILK_MACROS_ARM64_H */ 40 | -------------------------------------------------------------------------------- /silk/float/scale_vector_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* multiply a vector by a constant */ 35 | void silk_scale_vector_FLP( 36 | silk_float *data1, 37 | silk_float gain, 38 | opus_int dataSize 39 | ) 40 | { 41 | opus_int i, dataSize4; 42 | 43 | /* 4x unrolled loop */ 44 | dataSize4 = dataSize & 0xFFFC; 45 | for( i = 0; i < dataSize4; i += 4 ) { 46 | data1[ i + 0 ] *= gain; 47 | data1[ i + 1 ] *= gain; 48 | data1[ i + 2 ] *= gain; 49 | data1[ i + 3 ] *= gain; 50 | } 51 | 52 | /* any remaining elements */ 53 | for( ; i < dataSize; i++ ) { 54 | data1[ i ] *= gain; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /silk/lin2log.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FIX.h" 33 | /* Approximation of 128 * log2() (very close inverse of silk_log2lin()) */ 34 | /* Convert input to a log scale */ 35 | opus_int32 silk_lin2log( 36 | const opus_int32 inLin /* I input in linear scale */ 37 | ) 38 | { 39 | opus_int32 lz, frac_Q7; 40 | 41 | silk_CLZ_FRAC( inLin, &lz, &frac_Q7 ); 42 | 43 | /* Piece-wise parabolic approximation */ 44 | return silk_ADD_LSHIFT32( silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 ), 31 - lz, 7 ); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /silk/meson.build: -------------------------------------------------------------------------------- 1 | silk_sources = sources['SILK_SOURCES'] 2 | 3 | silk_sources_sse4_1 = sources['SILK_SOURCES_SSE4_1'] 4 | 5 | silk_sources_avx2 = sources['SILK_SOURCES_AVX2'] 6 | 7 | silk_sources_neon_intr = sources['SILK_SOURCES_ARM_NEON_INTR'] 8 | 9 | silk_sources_fixed_neon_intr = sources['SILK_SOURCES_FIXED_ARM_NEON_INTR'] 10 | 11 | silk_sources_fixed = sources['SILK_SOURCES_FIXED'] 12 | 13 | silk_sources_fixed_sse4_1 = sources['SILK_SOURCES_FIXED_SSE4_1'] 14 | 15 | silk_sources_float_sse4_1 = [] 16 | silk_sources_float_neon_intr = [] 17 | silk_sources_float_avx2 = sources['SILK_SOURCES_FLOAT_AVX2'] 18 | 19 | silk_sources_float = sources['SILK_SOURCES_FLOAT'] 20 | 21 | if opt_fixed_point 22 | silk_sources += silk_sources_fixed 23 | else 24 | silk_sources += silk_sources_float 25 | endif 26 | 27 | silk_includes = [opus_includes, include_directories('float', 'fixed')] 28 | silk_static_libs = [] 29 | 30 | if host_cpu_family in ['x86', 'x86_64'] and opus_conf.has('OPUS_HAVE_RTCD') 31 | silk_sources += sources['SILK_SOURCES_X86_RTCD'] 32 | endif 33 | 34 | if host_cpu_family in ['arm', 'aarch64'] and have_arm_intrinsics_or_asm 35 | if opus_conf.has('OPUS_HAVE_RTCD') 36 | silk_sources += sources['SILK_SOURCES_ARM_RTCD'] 37 | endif 38 | endif 39 | 40 | foreach intr_name : ['sse4_1', 'avx2', 'neon_intr'] 41 | have_intr = get_variable('have_' + intr_name) 42 | if not have_intr 43 | continue 44 | endif 45 | 46 | intr_sources = get_variable('silk_sources_' + intr_name) 47 | if not opt_fixed_point 48 | intr_sources += get_variable('silk_sources_float_' + intr_name) 49 | endif 50 | 51 | intr_args = get_variable('opus_@0@_args'.format(intr_name), []) 52 | silk_static_libs += static_library('silk_' + intr_name, intr_sources, 53 | c_args: intr_args, 54 | include_directories: silk_includes, 55 | install: false) 56 | endforeach 57 | 58 | silk_c_args = [] 59 | if host_machine.system() == 'windows' 60 | silk_c_args += ['-DDLL_EXPORT'] 61 | endif 62 | 63 | silk_lib = static_library('opus-silk', 64 | silk_sources, 65 | c_args: silk_c_args, 66 | include_directories: silk_includes, 67 | link_whole: [silk_static_libs], 68 | dependencies: libm, 69 | install: false) 70 | -------------------------------------------------------------------------------- /silk/mips/sigproc_fix_mipsr1.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SILK_SIGPROC_FIX_MIPSR1_H 29 | #define SILK_SIGPROC_FIX_MIPSR1_H 30 | 31 | #undef silk_SAT16 32 | static inline short int silk_SAT16(int a) 33 | { 34 | int c; 35 | c = __builtin_mips_shll_s_w(a, 16); 36 | c = c>>16; 37 | 38 | return c; 39 | } 40 | 41 | #undef silk_LSHIFT_SAT32 42 | static inline int silk_LSHIFT_SAT32(int a, int shift) 43 | { 44 | int r; 45 | 46 | r = __builtin_mips_shll_s_w(a, shift); 47 | 48 | return r; 49 | } 50 | 51 | #undef silk_RSHIFT_ROUND 52 | static inline int silk_RSHIFT_ROUND(int a, int shift) 53 | { 54 | int r; 55 | 56 | r = __builtin_mips_shra_r_w(a, shift); 57 | return r; 58 | } 59 | 60 | #endif /* SILK_SIGPROC_FIX_MIPSR1_H */ 61 | -------------------------------------------------------------------------------- /silk/tests/meson.build: -------------------------------------------------------------------------------- 1 | exe = executable('test_unit_LPC_inv_pred_gain', 2 | 'test_unit_LPC_inv_pred_gain.c', '../LPC_inv_pred_gain.c', 3 | include_directories: opus_includes, 4 | link_with: [celt_lib, celt_static_libs, silk_lib, silk_static_libs], 5 | dependencies: libm, 6 | install: false) 7 | 8 | test(test_name, exe) 9 | -------------------------------------------------------------------------------- /silk/xtensa/SigProc_FIX_lx7.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (C) 2025 Xiph.Org Foundation and contributors. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SILK_SIGPROC_FIX_LX7_H 29 | #define SILK_SIGPROC_FIX_LX7_H 30 | 31 | #undef silk_SAT16 32 | static inline short int silk_SAT16_lx7(opus_int32 a) 33 | { 34 | opus_int32 res; 35 | __asm__( 36 | "clamps %0, %1, 15\n\t" 37 | : "=r"(res) 38 | : "r"(a) 39 | ); 40 | return res; 41 | } 42 | #define silk_SAT16(a) (silk_SAT16_lx7(a)) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /silk_headers.mk: -------------------------------------------------------------------------------- 1 | SILK_HEAD = \ 2 | silk/debug.h \ 3 | silk/control.h \ 4 | silk/errors.h \ 5 | silk/API.h \ 6 | silk/typedef.h \ 7 | silk/define.h \ 8 | silk/main.h \ 9 | silk/x86/main_sse.h \ 10 | silk/PLC.h \ 11 | silk/structs.h \ 12 | silk/tables.h \ 13 | silk/tuning_parameters.h \ 14 | silk/Inlines.h \ 15 | silk/MacroCount.h \ 16 | silk/MacroDebug.h \ 17 | silk/macros.h \ 18 | silk/NSQ.h \ 19 | silk/pitch_est_defines.h \ 20 | silk/resampler_private.h \ 21 | silk/resampler_rom.h \ 22 | silk/resampler_structs.h \ 23 | silk/SigProc_FIX.h \ 24 | silk/x86/SigProc_FIX_sse.h \ 25 | silk/arm/biquad_alt_arm.h \ 26 | silk/arm/LPC_inv_pred_gain_arm.h \ 27 | silk/arm/macros_armv4.h \ 28 | silk/arm/macros_armv5e.h \ 29 | silk/arm/macros_arm64.h \ 30 | silk/arm/SigProc_FIX_armv4.h \ 31 | silk/arm/SigProc_FIX_armv5e.h \ 32 | silk/arm/NSQ_del_dec_arm.h \ 33 | silk/arm/NSQ_neon.h \ 34 | silk/fixed/main_FIX.h \ 35 | silk/fixed/structs_FIX.h \ 36 | silk/fixed/arm/warped_autocorrelation_FIX_arm.h \ 37 | silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h \ 38 | silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h \ 39 | silk/float/main_FLP.h \ 40 | silk/float/structs_FLP.h \ 41 | silk/float/SigProc_FLP.h \ 42 | silk/mips/macros_mipsr1.h \ 43 | silk/mips/NSQ_del_dec_mipsr1.h \ 44 | silk/mips/sigproc_fix_mipsr1.h 45 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | opus_sources = sources['OPUS_SOURCES'] 2 | 3 | opus_sources_float = sources['OPUS_SOURCES_FLOAT'] 4 | 5 | if not disable_float_api 6 | opus_sources += opus_sources_float 7 | endif 8 | 9 | opus_lib_c_args = [] 10 | if host_machine.system() == 'windows' 11 | opus_lib_c_args += ['-DDLL_EXPORT'] 12 | endif 13 | 14 | opus_lib = library('opus', 15 | opus_sources, 16 | version: libversion, 17 | darwin_versions: macosversion, 18 | c_args: opus_lib_c_args, 19 | include_directories: opus_includes, 20 | link_whole: [celt_lib, silk_lib, dnn_lib], 21 | dependencies: libm, 22 | install: true) 23 | 24 | opus_dep = declare_dependency(link_with: opus_lib, 25 | include_directories: opus_public_includes) 26 | 27 | # Extra uninstalled Opus programs 28 | if not extra_programs.disabled() 29 | foreach prog : ['opus_compare', 'opus_demo', 'repacketizer_demo'] 30 | executable(prog, '@0@.c'.format(prog), 31 | include_directories: opus_includes, 32 | link_with: opus_lib, 33 | dependencies: libm, 34 | install: false) 35 | endforeach 36 | 37 | if opt_custom_modes 38 | executable('opus_custom_demo', '../celt/opus_custom_demo.c', 39 | include_directories: opus_includes, 40 | link_with: opus_lib, 41 | dependencies: libm, 42 | install: false) 43 | endif 44 | 45 | endif 46 | -------------------------------------------------------------------------------- /src/mlp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Jean-Marc Valin */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef MLP_H_ 28 | #define MLP_H_ 29 | 30 | #include "opus_types.h" 31 | 32 | #define WEIGHTS_SCALE (1.f/128) 33 | 34 | #define MAX_NEURONS 32 35 | 36 | typedef struct { 37 | const opus_int8 *bias; 38 | const opus_int8 *input_weights; 39 | int nb_inputs; 40 | int nb_neurons; 41 | int sigmoid; 42 | } AnalysisDenseLayer; 43 | 44 | typedef struct { 45 | const opus_int8 *bias; 46 | const opus_int8 *input_weights; 47 | const opus_int8 *recurrent_weights; 48 | int nb_inputs; 49 | int nb_neurons; 50 | } AnalysisGRULayer; 51 | 52 | extern const AnalysisDenseLayer layer0; 53 | extern const AnalysisGRULayer layer1; 54 | extern const AnalysisDenseLayer layer2; 55 | 56 | void analysis_compute_dense(const AnalysisDenseLayer *layer, float *output, const float *input); 57 | 58 | void analysis_compute_gru(const AnalysisGRULayer *gru, float *state, const float *input); 59 | 60 | #endif /* MLP_H_ */ 61 | -------------------------------------------------------------------------------- /src/tansig_table.h: -------------------------------------------------------------------------------- 1 | /* This file is auto-generated by gen_tables */ 2 | 3 | static const float tansig_table[201] = { 4 | 0.000000f, 0.039979f, 0.079830f, 0.119427f, 0.158649f, 5 | 0.197375f, 0.235496f, 0.272905f, 0.309507f, 0.345214f, 6 | 0.379949f, 0.413644f, 0.446244f, 0.477700f, 0.507977f, 7 | 0.537050f, 0.564900f, 0.591519f, 0.616909f, 0.641077f, 8 | 0.664037f, 0.685809f, 0.706419f, 0.725897f, 0.744277f, 9 | 0.761594f, 0.777888f, 0.793199f, 0.807569f, 0.821040f, 10 | 0.833655f, 0.845456f, 0.856485f, 0.866784f, 0.876393f, 11 | 0.885352f, 0.893698f, 0.901468f, 0.908698f, 0.915420f, 12 | 0.921669f, 0.927473f, 0.932862f, 0.937863f, 0.942503f, 13 | 0.946806f, 0.950795f, 0.954492f, 0.957917f, 0.961090f, 14 | 0.964028f, 0.966747f, 0.969265f, 0.971594f, 0.973749f, 15 | 0.975743f, 0.977587f, 0.979293f, 0.980869f, 0.982327f, 16 | 0.983675f, 0.984921f, 0.986072f, 0.987136f, 0.988119f, 17 | 0.989027f, 0.989867f, 0.990642f, 0.991359f, 0.992020f, 18 | 0.992631f, 0.993196f, 0.993718f, 0.994199f, 0.994644f, 19 | 0.995055f, 0.995434f, 0.995784f, 0.996108f, 0.996407f, 20 | 0.996682f, 0.996937f, 0.997172f, 0.997389f, 0.997590f, 21 | 0.997775f, 0.997946f, 0.998104f, 0.998249f, 0.998384f, 22 | 0.998508f, 0.998623f, 0.998728f, 0.998826f, 0.998916f, 23 | 0.999000f, 0.999076f, 0.999147f, 0.999213f, 0.999273f, 24 | 0.999329f, 0.999381f, 0.999428f, 0.999472f, 0.999513f, 25 | 0.999550f, 0.999585f, 0.999617f, 0.999646f, 0.999673f, 26 | 0.999699f, 0.999722f, 0.999743f, 0.999763f, 0.999781f, 27 | 0.999798f, 0.999813f, 0.999828f, 0.999841f, 0.999853f, 28 | 0.999865f, 0.999875f, 0.999885f, 0.999893f, 0.999902f, 29 | 0.999909f, 0.999916f, 0.999923f, 0.999929f, 0.999934f, 30 | 0.999939f, 0.999944f, 0.999948f, 0.999952f, 0.999956f, 31 | 0.999959f, 0.999962f, 0.999965f, 0.999968f, 0.999970f, 32 | 0.999973f, 0.999975f, 0.999977f, 0.999978f, 0.999980f, 33 | 0.999982f, 0.999983f, 0.999984f, 0.999986f, 0.999987f, 34 | 0.999988f, 0.999989f, 0.999990f, 0.999990f, 0.999991f, 35 | 0.999992f, 0.999992f, 0.999993f, 0.999994f, 0.999994f, 36 | 0.999994f, 0.999995f, 0.999995f, 0.999996f, 0.999996f, 37 | 0.999996f, 0.999997f, 0.999997f, 0.999997f, 0.999997f, 38 | 0.999997f, 0.999998f, 0.999998f, 0.999998f, 0.999998f, 39 | 0.999998f, 0.999998f, 0.999999f, 0.999999f, 0.999999f, 40 | 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, 41 | 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, 42 | 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 43 | 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 44 | 1.000000f, 45 | }; 46 | -------------------------------------------------------------------------------- /tar_list.txt: -------------------------------------------------------------------------------- 1 | dnn/models/lace_v2.pth 2 | dnn/models/nolace_v2.pth 3 | dnn/models/nolace_192_v2.pth 4 | dnn/models/nolace_160_v2.pth 5 | dnn/models/fargan_sq1Ab_adv_50.pth 6 | dnn/models/rdovae_sparse5m_32.pth 7 | dnn/models/plc4ar_16.pth 8 | dnn/models/pitch_vsmallconv1.pth 9 | dnn/models/lossgen3_2000.pth 10 | dnn/lace_data.c 11 | dnn/lace_data.h 12 | dnn/nolace_data.c 13 | dnn/nolace_data.h 14 | dnn/fargan_data.c 15 | dnn/fargan_data.h 16 | dnn/pitchdnn_data.c 17 | dnn/pitchdnn_data.h 18 | dnn/plc_data.c 19 | dnn/plc_data.h 20 | dnn/dred_rdovae_constants.h 21 | dnn/dred_rdovae_stats_data.h 22 | dnn/dred_rdovae_enc_data.h 23 | dnn/dred_rdovae_stats_data.c 24 | dnn/dred_rdovae_dec_data.h 25 | dnn/dred_rdovae_enc_data.c 26 | dnn/dred_rdovae_dec_data.c 27 | dnn/lossgen_data.c 28 | dnn/lossgen_data.h 29 | -------------------------------------------------------------------------------- /tests/meson.build: -------------------------------------------------------------------------------- 1 | # Tests that link to libopus 2 | opus_tests = [ 3 | ['test_opus_api'], 4 | ['test_opus_decode', [], 120], 5 | ['test_opus_encode', 'opus_encode_regressions.c', 240], 6 | ['test_opus_extensions', [], 120], 7 | ['test_opus_padding'], 8 | ['test_opus_projection'], 9 | ] 10 | 11 | if opt_dred.enabled() 12 | opus_tests += [['test_opus_dred', [], 60 * 20]] 13 | endif 14 | 15 | foreach t : opus_tests 16 | test_name = t.get(0) 17 | extra_srcs = t.get(1, []) 18 | 19 | test_kwargs = {} 20 | if t.length() > 2 21 | test_kwargs += {'timeout': t[2]} 22 | endif 23 | 24 | exe_kwargs = {} 25 | # This test uses private symbols 26 | if test_name == 'test_opus_projection' or test_name == 'test_opus_extensions' 27 | exe_kwargs = { 28 | 'link_with': [celt_lib, silk_lib, dnn_lib], 29 | 'objects': opus_lib.extract_all_objects(), 30 | } 31 | endif 32 | 33 | exe = executable(test_name, '@0@.c'.format(test_name), extra_srcs, 34 | include_directories: opus_includes, 35 | dependencies: [libm, opus_dep], 36 | install: false, 37 | kwargs: exe_kwargs) 38 | test(test_name, exe, kwargs: test_kwargs) 39 | endforeach 40 | -------------------------------------------------------------------------------- /tests/opus_build_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | tarball=`realpath "$1"` 4 | nb_tests="$2" 5 | oldvectors=`realpath "$3"` 6 | newvectors=`realpath "$4"` 7 | base=`basename "$tarball" .tar.gz` 8 | 9 | tar xvf "$tarball" > /dev/null 2>&1 10 | cd "$base" 11 | 12 | if [ $? -ne 0 ] 13 | then 14 | echo cannot go to "$base" 15 | exit 1 16 | fi 17 | 18 | mkdir build_tests 19 | 20 | configure_dir=`pwd` 21 | seq -w "$nb_tests" | parallel --halt now,fail=10 -j +2 -q ../random_config.sh "build_tests/run_{}" "$configure_dir" "$oldvectors" "$newvectors" 22 | 23 | if [ $? -ne 0 ] 24 | then 25 | echo Check found errors 26 | exit 1 27 | else 28 | echo No error found 29 | fi 30 | -------------------------------------------------------------------------------- /tests/opus_decode_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | max_len = 1000000 3 | -------------------------------------------------------------------------------- /training/txt2hdf5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | import numpy as np 6 | import h5py 7 | import sys 8 | 9 | data = np.loadtxt(sys.argv[1], dtype='float32') 10 | h5f = h5py.File(sys.argv[2], 'w'); 11 | h5f.create_dataset('data', data=data) 12 | h5f.close() 13 | --------------------------------------------------------------------------------