shithub: opus

Download patch

ref: f92fdda4f9b75ecb5f0f38b86c991195585579ea
parent: 931a37caf2a4af703d61f4c2cb52a7811e4939b8
author: Jan Buethe <jan.buethe@gmx.net>
date: Wed Jul 23 13:03:38 EDT 2025

added dec_fs option to run_osce_test.py

--- a/dnn/torch/osce/stndrd/evaluation/run_osce_test.py
+++ b/dnn/torch/osce/stndrd/evaluation/run_osce_test.py
@@ -18,6 +18,7 @@
 parser.add_argument('--encoder_options', type=str, default="", help='encoder options (e.g. -complexity 5)')
 parser.add_argument('--test_opus_demo', type=str, default='./opus_demo', help='opus_demo binary under test')
 parser.add_argument('--test_opus_demo_options', type=str, default='-dec_complexity 7', help='options for test opus_demo (e.g. "-dec_complexity 7")')
+parser.add_argument('--dec_fs', type=int, default=16000, help='decoder sampling frequency (default: 16000)')
 parser.add_argument('--verbose', type=int, default=0, help='verbosity level: 0 for quiet (default), 1 for reporting individual test results, 2 for reporting per-item scores in failed tests')
 
 def run_opus_encoder(opus_demo_path, input_pcm_path, bitstream_path, application, fs, num_channels, bitrate, options=[], verbose=False):
@@ -95,7 +96,7 @@
     except:
         return 1
 
-def process_clip_factory(ref_opus_demo, test_opus_demo, enc_options, test_options):
+def process_clip_factory(ref_opus_demo, test_opus_demo, enc_options, test_options, dec_fs=16000):
     def process_clip(clip_path, processdir, bitrate):
         # derive paths
         clipname = os.path.splitext(os.path.split(clip_path)[1])[0]
@@ -111,18 +112,29 @@
         run_opus_encoder(ref_opus_demo, pcm_path, bitstream_path, "voip", 16000, 1, bitrate, enc_options)
 
         # run decoder
-        run_opus_decoder(ref_opus_demo, bitstream_path, ref_path, 16000, 1)
-        run_opus_decoder(test_opus_demo, bitstream_path, test_path, 16000, 1, options=test_options)
+        run_opus_decoder(ref_opus_demo, bitstream_path, ref_path, dec_fs, 1)
+        run_opus_decoder(test_opus_demo, bitstream_path, test_path, dec_fs, 1, options=test_options)
 
-        d_ref  = compute_moc_score(pcm_path, ref_path)
-        d_test = compute_moc_score(pcm_path, test_path)
+        # resample if dec_fs != 16000
+        if dec_fs != 16000:
+            ref_path_resamp = os.path.join(processdir, clipname + "_ref_resampled.raw")
+            test_path_resamp = os.path.join(processdir, clipname + "_test_resampled.raw")
 
+            sox("-r", str(dec_fs), "-e", "signed-integer", "-b", "16", ref_path, "-r", "16000", ref_path_resamp)
+            sox("-r", str(dec_fs), "-e", "signed-integer", "-b", "16", test_path, "-r", "16000", test_path_resamp)
+        else:
+            ref_path_resamp = ref_path
+            test_path_resamp = test_path
+
+        d_ref  = compute_moc_score(pcm_path, ref_path_resamp)
+        d_test = compute_moc_score(pcm_path, test_path_resamp)
+
         return d_ref, d_test
 
 
     return process_clip
 
-def main(inputdir, outputdir, bitrate, reference_opus_demo, test_opus_demo, enc_option_string, test_option_string, verbose):
+def main(inputdir, outputdir, bitrate, reference_opus_demo, test_opus_demo, enc_option_string, test_option_string, dec_fs, verbose):
 
     # load clips list
     with open(os.path.join(inputdir, 'clips.yml'), "r") as f:
@@ -132,7 +144,7 @@
     enc_options = enc_option_string.split()
     test_options = test_option_string.split()
 
-    process_clip = process_clip_factory(reference_opus_demo, test_opus_demo, enc_options, test_options)
+    process_clip = process_clip_factory(reference_opus_demo, test_opus_demo, enc_options, test_options, dec_fs=dec_fs)
 
     os.makedirs(outputdir, exist_ok=True)
     processdir = os.path.join(outputdir, 'process')
@@ -193,4 +205,5 @@
          args.test_opus_demo,
          args.encoder_options,
          args.test_opus_demo_options,
+         args.dec_fs,
          args.verbose)
--