autoSound Sound_filter_stopHannBand (Sound me, double fmin, double fmax, double smooth) { try { autoSound thee = Data_copy (me); if (my ny == 1) { autoSpectrum spec = Sound_to_Spectrum (me, true); Spectrum_stopHannBand (spec.peek(), fmin, fmax, smooth); autoSound him = Spectrum_to_Sound (spec.peek()); NUMvector_copyElements (his z [1], thy z [1], 1, thy nx); } else { for (long ichan = 1; ichan <= my ny; ichan ++) { autoSound channel = Sound_extractChannel (me, ichan); autoSpectrum spec = Sound_to_Spectrum (channel.peek(), true); Spectrum_stopHannBand (spec.peek(), fmin, fmax, smooth); autoSound him = Spectrum_to_Sound (spec.peek()); NUMvector_copyElements (his z [1], thy z [ichan], 1, thy nx); } } return thee; } catch (MelderError) { Melder_throw (me, U": not filtered (stop Hann band)."); } }
static void menu_cb_stopBand (EDITOR_ARGS) { EDITOR_IAM (SpectrumEditor); EDITOR_FORM (L"Filter (stop Hann band)", 0) REAL (L"Band smoothing (Hz)", my default_bandSmoothing ()) EDITOR_OK SET_REAL (L"Band smoothing", my p_bandSmoothing) EDITOR_DO my pref_bandSmoothing () = my p_bandSmoothing = GET_REAL (L"Band smoothing"); if (my d_endSelection <= my d_startSelection) Melder_throw (L"To apply a band-stop filter, first make a selection."); Editor_save (me, L"Stop band"); Spectrum_stopHannBand ((Spectrum) my data, my d_startSelection, my d_endSelection, my p_bandSmoothing); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }
Sound Sound_deepenBandModulation (Sound me, double enhancement_dB, double flow, double fhigh, double slowModulation, double fastModulation, double bandSmoothing) { try { autoSound thee = Data_copy (me); double maximumFactor = pow (10, enhancement_dB / 20), alpha = sqrt (log (2.0)); double alphaslow = alpha / slowModulation, alphafast = alpha / fastModulation; for (long channel = 1; channel <= my ny; channel ++) { autoSound channelSound = Sound_extractChannel (me, channel); autoSpectrum orgspec = Sound_to_Spectrum (channelSound.peek(), true); /* * Keep the part of the sound that is outside the filter bank. */ autoSpectrum spec = Data_copy (orgspec.peek()); Spectrum_stopHannBand (spec.peek(), flow, fhigh, bandSmoothing); autoSound filtered = Spectrum_to_Sound (spec.peek()); long n = thy nx; double *amp = thy z [channel]; for (long i = 1; i <= n; i ++) amp [i] = filtered -> z [1] [i]; autoMelderProgress progress (U"Deepen band modulation..."); double fmin = flow; while (fmin < fhigh) { /* * Take a one-bark frequency band. */ double fmid_bark = NUMhertzToBark (fmin) + 0.5, ceiling; double fmax = NUMbarkToHertz (NUMhertzToBark (fmin) + 1); if (fmax > fhigh) fmax = fhigh; Melder_progress (fmin / fhigh, U"Band: ", Melder_fixed (fmin, 0), U" ... ", Melder_fixed (fmax, 0), U" Hz"); NUMmatrix_copyElements (orgspec -> z, spec -> z, 1, 2, 1, spec -> nx); Spectrum_passHannBand (spec.peek(), fmin, fmax, bandSmoothing); autoSound band = Spectrum_to_Sound (spec.peek()); /* * Compute a relative intensity contour. */ autoSound intensity = Data_copy (band.peek()); n = intensity -> nx; amp = intensity -> z [1]; for (long i = 1; i <= n; i ++) amp [i] = 10 * log10 (amp [i] * amp [i] + 1e-6); autoSpectrum intensityFilter = Sound_to_Spectrum (intensity.peek(), true); n = intensityFilter -> nx; for (long i = 1; i <= n; i ++) { double frequency = intensityFilter -> x1 + (i - 1) * intensityFilter -> dx; double slow = alphaslow * frequency, fast = alphafast * frequency; double factor = exp (- fast * fast) - exp (- slow * slow); intensityFilter -> z [1] [i] *= factor; intensityFilter -> z [2] [i] *= factor; } intensity.reset (Spectrum_to_Sound (intensityFilter.peek())); n = intensity -> nx; amp = intensity -> z [1]; for (long i = 1; i <= n; i ++) amp [i] = pow (10, amp [i] / 2); /* * Clip to maximum enhancement. */ ceiling = 1 + (maximumFactor - 1.0) * (0.5 - 0.5 * cos (NUMpi * fmid_bark / 13)); for (long i = 1; i <= n; i ++) amp [i] = 1 / (1 / amp [i] + 1 / ceiling); n = thy nx; amp = thy z [channel]; for (long i = 1; i <= n; i ++) amp [i] += band -> z [1] [i] * intensity -> z [1] [i]; fmin = fmax; } } Vector_scale (thee.peek(), 0.99); /* Truncate. */ thy xmin = my xmin; thy xmax = my xmax; thy nx = my nx; thy x1 = my x1; return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": band modulation not deepened."); } }