Rafael Laboissière pushed to branch upstream at Debian Med / praat


Commits:
4189febd by Rafael Laboissière at 2021-09-11T12:33:03-03:00
New upstream version 6.1.53
- - - - -


3 changed files:

- dwtest/test_Sound_noiseReduction.praat
- dwtools/Sound_extensions.cpp
- sys/GraphicsScreen.cpp


Changes:

=====================================
dwtest/test_Sound_noiseReduction.praat
=====================================
@@ -1,20 +1,44 @@
 # test_Sound_noiseReduction.praat
-# djmw 20190326
+# djmw 20190326, 20210831
 
 appendInfoLine: "test_Sound_noiseReduction.praat"
-sound = Create Sound from formula: "test", 1, 0, 1, 44100, "0.0"
-Formula: "randomGauss(0,0.1) + if x < 0.5 then 0.5*sin(2*pi*377*x) else 0 fi"
-spectrum = To Spectrum: "no"
-bandEnergy = Get band energy: 1000, 9000
-for i to 10
-       db = -10 * (i - 1)
-       selectObject: sound
-       copy = Copy: string$ (db)
-       soundReduced = Reduce noise: 0.5, 1, 0.025, 80, 10000, 40, db, 
"spectral-subtraction"
-       spectrumReduced = To Spectrum: "no"
-       bandEnergyReduced = Get band energy: 1000, 9000
-       appendInfoLine: tab$, "db=", db, " ", 10* log10 
(bandEnergyReduced/4e-10), " ", 10* log10 (bandEnergyReduced / bandEnergy), " 
", bandEnergy / bandEnergyReduced
-       removeObject: spectrumReduced, soundReduced, copy
-endfor
-removeObject: spectrum, sound
+
+
+@ test_reduction
+@test_numberOfBands: 10
+
 appendInfoLine: "test_Sound_noiseReduction.praat OK"
+
+procedure test_reduction
+       appendInfoLine: tab$, "test_reduction"
+       .sound = Create Sound from formula: "test", 1, 0, 1, 44100, "0.0"
+       Formula: "randomGauss(0,0.1) + if x < 0.5 then 0.5*sin(2*pi*377*x) else 
0 fi"
+       .spectrum = To Spectrum: "no"
+       .bandEnergy = Get band energy: 1000, 9000
+       for .i to 10
+               .db = -10 * (.i - 1)
+               selectObject: .sound
+               .copy = Copy: string$ (.db)
+               .soundReduced = Reduce noise: 0.5, 1, 0.025, 80, 10000, 40, 
.db, "spectral-subtraction"
+               .spectrumReduced = To Spectrum: "no"
+               .bandEnergyReduced = Get band energy: 1000, 9000
+               appendInfoLine: tab$, tab$, "db=", .db, " ", 10* log10 
(.bandEnergyReduced/4e-10), " ", 
+               ... 10* log10 (.bandEnergyReduced / .bandEnergy), " ", 
.bandEnergy / .bandEnergyReduced
+               removeObject: .spectrumReduced, .soundReduced, .copy
+       endfor
+       removeObject: .spectrum, .sound
+       appendInfoLine: tab$, "test_reduction OK"
+endproc
+
+procedure test_numberOfBands: .numberOfTries
+       appendInfoLine: tab$, "test_numberOfBands"
+       for .i to .numberOfTries
+               .samplingFrequency = randomUniform(1000, 50000)
+               .sound = Create Sound from formula: "test", 1, 0, 1, 
.samplingFrequency, "0.0"
+               .windowLength = randomUniform (0.005,0.06)
+               .soundReduced = Reduce noise: 0.5, 1, .windowLength, 80, 10000, 
40, -20, "spectral-subtraction"
+               appendInfoLine: tab$, tab$, "Fmax = ", .samplingFrequency, " 
windowLength = ", .windowLength
+               removeObject: .sound, .soundReduced
+       endfor
+       appendInfoLine: tab$, "test_numberOfBands OK"
+endproc
\ No newline at end of file


=====================================
dwtools/Sound_extensions.cpp
=====================================
@@ -2586,20 +2586,33 @@ static autoSound 
Sound_reduceNoiseBySpectralSubtraction_mono (Sound me, Sound no
                Melder_require (noise -> ny == 1 && noise -> ny == 1,
                        U"The number of channels in the noise and the sound 
should equal 1.");
 
-               const double samplingFrequency = 1.0 / my dx;
+               const double samplingFrequency = 1.0 / my dx, nyquistFrequency 
= 0.5 / my dx;
                autoSound denoised = Sound_create (1, my xmin, my xmax, my nx, 
my dx, my x1);
                autoSound const analysisWindow = Sound_createSimple (1, 
windowLength, samplingFrequency);
                const integer windowSamples = analysisWindow -> nx;
+               const integer wantedNumberOfFrequencyBins = windowSamples / 2 + 
1;
                autoSound const noise_copy = Data_copy (noise);
                Sound_multiplyByWindow (noise_copy.get(), 
kSound_windowShape::HANNING);
-               const double bandwidth = samplingFrequency / windowSamples;
+               /*
+                       The number of bands in the noise Ltas and the number of 
frequencies in the 
+                       sound spectra preferably should to be equal.
+                       numberOfBands = Melder_iceiling (nyquistFrequency / 
bandwidth)
+                       wantedNumberOfFrequencyBins = windowSamples / 2 + 1;
+                       We can calculate the bandwidth to make numberOfBands == 
wantedNumberOfFrequencyBins by applying 
+                       the following two conditions
+                       (1) nyquistFrequency / b > wantedNumberOfFrequencyBins 
- 1 && (2) nyquistFrequency / b < wantedNumberOfFrequencyBins
+                       (1) gives b1 < nyquistFrequency / 
(wantedNumberOfFrequencyBins - 1)
+                       (2) gives b2 > nyquistFrequency / 
wantedNumberOfFrequencyBins
+                       Take b = (b1 + b2) / 2
+               */
+               double bandwidth = nyquistFrequency * 
(wantedNumberOfFrequencyBins - 0.5) / (wantedNumberOfFrequencyBins * 
(wantedNumberOfFrequencyBins - 1));
                autoLtas const noiseLtas = Sound_to_Ltas (noise_copy.get(), 
bandwidth);
+               Melder_assert (noiseLtas -> nx == wantedNumberOfFrequencyBins);
                autoVEC const noiseAmplitudes = raw_VEC (noiseLtas -> nx);
                for (integer iband = 1; iband <= noiseLtas -> nx; iband ++) {
                        const double powerDensity = 4e-10 * pow (10.0, 
noiseLtas -> z [1] [iband] / 10.0);
                        noiseAmplitudes [iband] = sqrt (0.5 * powerDensity);
                }
-               
                autoMelderProgress progress (U"Remove noise");
                
                const double noiseAmplitudeSubtractionScaleFactor = 1.0 - pow 
(10.0, noiseReduction_dB / 20.0);


=====================================
sys/GraphicsScreen.cpp
=====================================
@@ -604,6 +604,9 @@ autoGraphics Graphics_create_pdffile (MelderFile file, int 
resolution,
                        isdefined (y1inches) ? 1.0 : 0.0, isdefined (y1inches) 
? 12.0 : y2inches
                );
                cairo_scale (my d_cairoGraphicsContext, 72.0 / resolution, 72.0 
/ resolution);
+               cairo_translate (my d_cairoGraphicsContext,
+                       ( isdefined (x1inches) ? - x1inches : 0.0 ) * 
resolution,
+                       ( isdefined (y1inches) ? y2inches - 12.0 : 0.0 ) * 
resolution);
        #elif quartz
                CFURLRef url = CFURLCreateWithFileSystemPath (nullptr, 
(CFStringRef) Melder_peek32toCfstring (file -> path), kCFURLPOSIXPathStyle, 
false);
                CGRect rect = CGRectMake (0, 0,



View it on GitLab: 
https://salsa.debian.org/med-team/praat/-/commit/4189febd3f6e96b0bcfa34e0692cfcb0c0b009d2

-- 
View it on GitLab: 
https://salsa.debian.org/med-team/praat/-/commit/4189febd3f6e96b0bcfa34e0692cfcb0c0b009d2
You're receiving this email because of your account on salsa.debian.org.


_______________________________________________
debian-med-commit mailing list
[email protected]
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/debian-med-commit

Reply via email to