Skip to content

[FEATURE] add envelope, start_ir, time_shift and other editing utilities - #96

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-dsp_edit
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-dsp_edit

Conversation

@aguirreSL

Copy link
Copy Markdown

Adds to pytta.functions nine editing utilities that the ITA-Toolbox has (ita_envelope, ita_start_IR, ita_time_shift, ita_append, ita_normalize_dat, ita_normalize_spk, ita_amplify_to, ita_zerophase, ita_randomize_phase and ita_quantize):

  1. envelope(signal): the magnitude of the analytic signal, computed on twice the signal length, as ita_envelope.
  2. start_ir(signal, threshold=20): the 0-based start sample of each channel of an impulse response, by ISO 3382-1:2009, A.3. It is the last sample before the peak that lies 20 dB below it, moved back to the last such sample before an earlier one 6 dB above that level (an oscillating onset), as ita_start_IR.
  3. time_shift(signal, shift=None, unit='time'): a cyclic shift in seconds or samples, one for all channels or one per channel. A fraction of a sample is applied as a linear phase. With no shift, the earliest start of the response moves to the first sample.
  4. append(signal1, signal2): concatenation in time.
  5. normalize(signal, domain='time', per_channel=False): the signal scaled so that its largest magnitude, in time or in the spectrum, is 1, with the gain removed.
  6. amplify_to(signal, level): the signal scaled so that the mean RMS of its channels is level dB, re 20 µPa for channels in Pa.
  7. zero_phase(signal) and randomize_phase(signal, seed=None): the magnitude spectrum with zero or random phase.
  8. quantize(signal, bits=24): rounding to 2^(bits - 1) + 1 intervals across the peak, halves away from zero, as ita_quantize.

The ITA code was read for its semantics only and nothing was copied. Indices are 0-based.

The tests in tests/test_dsp_edit.py print the measured differences:

  1. start_ir gives the starts of ita_start_IR on three decaying responses with a weak lead-in, on golden data from tests/golden/make_dsp_edit_ita.m (MATLAB R2026b).
  2. The envelope of an AM tone follows 1 + m cos(2π fm t) away from the ends (3.9e-3) and the envelope of ita_envelope for the same samples (1.2e-7).
  3. An integer shift is a roll, two shifts of half a sample make one (3.6e-8), and the automatic shift brings the start of the response to sample 0.
  4. normalize brings the peak to 1 and returns it, per channel too, and amplify_to sets the level of a signal in Pa to 70 dB.
  5. zero_phase and randomize_phase keep the magnitude spectrum, and the zero-phase signal is even.
  6. append concatenates and rejects different sampling rates, and quantize gives the samples of ita_quantize exactly.

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of development (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

Adds to pytta.functions nine editing utilities that the ITA-Toolbox has:
envelope (ita_envelope, the magnitude of the analytic signal), start_ir
(ita_start_IR, the start of an impulse response by ISO 3382-1, A.3),
time_shift (ita_time_shift, cyclic, fractional shifts as a linear phase,
or the start of the response to the first sample), append (ita_append),
normalize (ita_normalize_dat and ita_normalize_spk), amplify_to
(ita_amplify_to, to a mean RMS level), zero_phase, randomize_phase and
quantize (ita_zerophase, ita_randomize_phase, ita_quantize).

Tests check start_ir and quantize against the ITA-Toolbox on golden data
from tests/golden/make_dsp_edit_ita.m (identical), the envelope of an AM
tone against its formula and against ITA (1.2e-7), integer and
fractional shifts, the peak and level rules, and that the phase edits
keep the magnitude spectrum.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant