From af84d4ffa33721c21194080fade5465158415112 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:41:08 +0100 Subject: [PATCH] kotlin configuration file ok --- examples/generate_kotlin_config.py | 89 ++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/examples/generate_kotlin_config.py b/examples/generate_kotlin_config.py index 02e5bf9..22a6bd7 100644 --- a/examples/generate_kotlin_config.py +++ b/examples/generate_kotlin_config.py @@ -85,21 +85,13 @@ ) """ -f = FilterDesign(sample_rate=48000, first_frequency_band=50, - last_frequency_band=16000, window_samples=48000*0.125) - -f.down_sampling = f.G2 -f.band_division = 3 - -configuration = f.generate_configuration() - def write_array(fw, array_in): for li, val in enumerate(array_in): if li > 0: - fw.write(",%f" % val) + fw.write(",%s" % val) else: - fw.write("%f" % val) + fw.write("%s" % val) def dump_sos(fw, sos): @@ -117,27 +109,64 @@ def dump_sos(fw, sos): def main(): - with open("config_%d.kt" % f.sample_rate, "w") as fw: - fw.write("fun get%dHZ() {\n" % f.sample_rate) - fw.write( - " return SpectrumChannelConfiguration(\n bandpass=listOf(") - for bi, bandpass in enumerate(configuration["bandpass"]): - if bi > 0: - fw.write(",\n ") - else: - fw.write("\n ") - fw.write("Bandpass({center_frequency},{max_frequency}," - "{min_frequency},{nominal_frequency},{subsampling_depth}," - .format(**bandpass)) - dump_sos(fw, bandpass["sos"]) + with open("ConfigSpectrumChannel.kt", "w") as fw: + fw.write(class_source) + + for freq in [44100, 48000]: + f = FilterDesign(sample_rate=freq, first_frequency_band=50, + last_frequency_band=16000, + window_samples=freq * 0.125) + + f.down_sampling = f.G2 + f.band_division = 3 + + configuration = f.generate_configuration() + fw.write("\n\nfun get%dHZ() : SpectrumChannelConfiguration {\n" % f.sample_rate) fw.write( - ",subsamplingFilter=SubsamplingFilter({center_frequency}" - "{max_frequency},{min_frequency},{nominal_frequency},sos=" - .format(**bandpass["subsampling_filter"])) - dump_sos(fw, bandpass["subsampling_filter"]["sos"]) - fw.write("))") - fw.write(" ))\n") - fw.write("}\n") + " return SpectrumChannelConfiguration(\n bandpass=listOf(") + for bi, bandpass in enumerate(configuration["bandpass"]): + if bi > 0: + fw.write(",\n ") + else: + fw.write("\n ") + fw.write("Bandpass({center_frequency},{max_frequency}," + "{min_frequency},{nominal_frequency}," + "{subsampling_depth}," + .format(**bandpass)) + dump_sos(fw, bandpass["sos"]) + fw.write( + ",subsamplingFilter=SubsamplingFilter({center_frequency}," + "{max_frequency},{min_frequency},{nominal_frequency}" + ",sos=".format(**bandpass["subsampling_filter"])) + dump_sos(fw, bandpass["subsampling_filter"]["sos"]) + fw.write("))") + fw.write("),\n antiAliasing=") + fw.write("AntiAliasing(a1=doubleArrayOf(") + write_array(fw, configuration["anti_aliasing"]["a1"]) + fw.write("), a2=doubleArrayOf(") + write_array(fw, configuration["anti_aliasing"]["a2"]) + fw.write("), b0=doubleArrayOf(") + write_array(fw, configuration["anti_aliasing"]["b0"]) + fw.write("), b1=doubleArrayOf(") + write_array(fw, configuration["anti_aliasing"]["b1"]) + fw.write("), b2=doubleArrayOf(") + write_array(fw, configuration["anti_aliasing"]["b2"]) + fw.write("),sampleRatio=%d" % configuration["anti_aliasing"]["sample_ratio"]) + fw.write(")") + fw.write(",\n aWeighting=DigitalFilterConfiguration(filterDenominator=doubleArrayOf(") + write_array(fw, configuration["a_weighting"]["filter_denominator"]) + fw.write("), filterNumerator=doubleArrayOf(") + write_array(fw, configuration["a_weighting"]["filter_numerator"]) + fw.write("))") # end DigitalFilterConfiguration + fw.write(",\n cWeighting=DigitalFilterConfiguration(filterDenominator=doubleArrayOf(") + write_array(fw, configuration["c_weighting"]["filter_denominator"]) + fw.write("), filterNumerator=doubleArrayOf(") + write_array(fw, configuration["c_weighting"]["filter_numerator"]) + fw.write("))") # end DigitalFilterConfiguration + fw.write(",\n configuration=GeneralConfiguration(sampleRate=%d)" + % configuration["configuration"]["sample_rate"]) + fw.write(")\n") # end SpectrumChannel + fw.write("}\n") main()