Skip to content

First simple demo implementation of Spectrogram Wavelet analysis - #9510

Merged
saintmatthieu merged 1 commit into
audacity:audacity3from
kgramhans:release-3.7.5-wavelet
Oct 13, 2025
Merged

saintmatthieu merged 1 commit into
audacity:audacity3from
kgramhans:release-3.7.5-wavelet

Conversation

@kgramhans

@kgramhans kgramhans commented Sep 30, 2025 •

Copy link
Copy Markdown
Contributor

Resolves: #9509

(short description of the changes and the motivation to make the changes)

  • I signed CLA
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

QA:

  • Autobot test cases have been run

@kgramhans

Copy link
Copy Markdown
Contributor Author

Purpose of this PR is mainly to share insight into extent of changes required to implement proposed functionality

@ianalarina ianalarina linked an issue Oct 6, 2025 that may be closed by this pull request
@saintmatthieu

Copy link
Copy Markdown
Contributor

Good morning @kgramhans, thank you so much for this beautiful contribution!

I am not sure that this is going to make it in Audacity 3, as it is being sunset, but we are interested in having it in Audacity 4.

Unfortunately, the spectrum view has not yet been ported to Au4, so I can't just ask you to redirect to redirect this PR to the master branch. It's a matter of months till we have, so one option would be to just let this sit for a while and reactivate it in due time.

We will discuss this in our daily today, but in the meantime I'll begin to review it, it won't be wasted time.

@saintmatthieu saintmatthieu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly okay. I see an opportunity to simplify by reusing existing code, as detailed in the comments. Also, we'll have to figure something out on how we present the settings for the wavelet, but for now let us try to finish this iteration.

Comment thread src/prefs/SpectrumPrefs.cpp Resolved
@saintmatthieu

Copy link
Copy Markdown
Contributor

Food for thoughts:
Reviewing this code has been the opportunity for me to (re)discover the implementation details of our spectrum display.
My observations:

  • The frequency-bins are decoupled from the pixel rows, and then a layer assigns the value of a row based on the closest frequency bin (hence the crude aspect when using a small window size without padding)
  • The hop size is coupled to the pixel columns. Consequences:
    • For large window (or wavelet) sizes this makes the computation inefficient, since the horizontal diff must be rather flat and interpolation could save tons of calculations.
    • The spectrum may not be invertible - for it to be, there are constraints on the hop size that are dependent on the analysis window (max hop size N for rectangular windows, N/2 for Hann, for example)

I would very much like to completely decouple the pixel grid from the spectrogram grid. It would allow us to make the spectrogram invertible, paving the way to spectral editing.

@saintmatthieu

saintmatthieu commented Oct 10, 2025 •

Copy link
Copy Markdown
Contributor

Hi @kgramhans, thanks for having addressed these comments, I think the integration is a bit better now.
I discussed your contribution with the rest of the team on a daily earlier this week.

We will want this feature for Audacity 4 (have you seen @Tantacrul 's video, btw?) but we haven't ported spectrograms yet. We don't want to merge it in Au3 either because it's now only in KTLO mode, and this feature would require advertisement and a little bit of design to give it the care it deserves in the spectrogram settings.

My proposal would be to put a macro around the wavelet entry of

const TranslatableStrings &SpectrogramSettings::GetAlgorithmNames()
{
   static const TranslatableStrings results{
      // Keep in correspondence with enum SpectrogramSettings::Algorithm:
      XO("Frequencies") ,
      /* i18n-hint: the Reassignment algorithm for spectrograms */
      XO("Reassignment") ,
      /* i18n-hint: EAC abbreviates "Enhanced Autocorrelation" */
      XO("Pitch (EAC)") ,
#ifdef WAVELET
      XO("Wavelet (1/6 Octave Hann)") ,
#endif
   };
   return results;
}

Then the feature would not be available to production builds but you could still showcase this with local builds and the implementation would still get built, ensuring that it doesn't go stale until it's ported to Au4.

Would you be okay with that?

@kgramhans

kgramhans commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor Author

@saintmatthieu Hi Matt,
I am just glad that you have embraced my proposal and of course fully respect your roadmap decisions. I will add the #define to effectively disable the wavelet stuff
I watched the video and enjoyed it. It expresses what I think are very mature thoughts on the topic of maintaining old software projects that will inevitably contain loads of technical dept (some claim that technical dept is just an acronym for code you have not written yourself). Very interesting and challenging. Seems like a lot of good decision making has been done
In case you have any topics related to signal processing or algorithms (design/review/coding/testing) I could offer assistance, just reach out

@saintmatthieu

Copy link
Copy Markdown
Contributor

Thanks for the offer, I'll keep it in mind. Right now I can't think of anything beside migrating more of the built-in effects from Au3 to Au4, and this is more standard software engineering, it does not involve real DSP. In the future other opportunities are likely to come forth, though.

I've approved, feel free to merge, but before, please check the last comment I've added. Thanks!

@saintmatthieu

Copy link
Copy Markdown
Contributor

(I'm not sure you can merge, actually, let me know if it doesn't wrok.)

@saintmatthieu

saintmatthieu commented Oct 12, 2025 •

Copy link
Copy Markdown
Contributor

@kgramhans another thing occurred to me that's of concern: the wavelet transform does not leverage FFT optimizations. AFAICS, this is the only algorithm of the four that doesn't. A quick test on my side also indeed shows that it's noticeably slower than the others. This could bother our Product guys (and me included, although I'm just an engineer), because we'd be exposing a feature that doesn't work smoothly. (I wonder if this might explain why this transform hasn't been implemented yet, maybe @SteveDaulton would know.) I expect the refresh rate during playback to be very, very slow (it's already slow for the spectrogram).

I'll raise this during our daily again on Monday. I suppose we could add a "slow" mention to the algorithm's name in the dropdown, and if we still end up deciding against it, reverting the commit would be trivial. (Please squash your commits before you do the merge, thanks.)

@kgramhans

Copy link
Copy Markdown
Contributor Author

@saintmatthieu so true that the Wavelet transform is a different beast when it comes to optimisations

As of now, the current implementation will calculate the inner product for each point of time with a number of wavelets that increase in length for lower frequencies. For example, with a sample frequency of 44kHz and analysis downto 20 Hz the a rough amount of calculations for each point in time on a linear frequency axis would be (Window length N, average wavelet length W)

Octave 1: 11..22kHz WN/2 operations
Octave 2: 5.5..11 kHz 2
WN/4 operations
Octave 3: 2.7..5.5kHz 4
W*N/8 operations (4x length, 1/4 number of frequencies)
etc

Totalling up to 5WN operations for 20-20kHz (10 octaves) audio range. The choice of window length, N, is selectable in current implementation (but naturally also limits lower frequency bound)
The standard choice of N=16384 and W=30 leads to 2.4M operations

There is a huge potential for optimisations here. In Practice, it would not be necessary to calculate more than a constant number of transform values in each octave in order to properly represent the signal
For the chosen wavelet, this number is roughly 12, leading to

Octave 1: W* max(N/2,12) operations
Octave 2: 2W max(N/4,12) operations
Octave 3: 4W max(N/8,12) operations
etc

Totalling up to 1024W12 = 0.4M operations plus the expense of a simple interpolation scheme

These considerations are highly linked to the way Spectrograms are designed into Audacity: A full transform is calculated at all frequencies irrespective of what is being displayed. And the choice of Y axis also does not reflect what is being calculated

This is in general a demanding design task. Adding also the complexity of real time behaviour does not make things simpler. With respect to the latter, it would be beneficial to implement wavelet analysis as a filter bank with downsampling a data for each octave being processed. The usage of causal filters could also prove useful. Such real time implementation and adequate interpolation schemes would according to my experience end up having twice the computational load of an FFT based algorithm like the conventional spectrogram

But underlying all this would be a proper design, first of all. And understanding the different use cases

The current proposal has not focussed on any optimisations. I think that would be premature

@saintmatthieu

Copy link
Copy Markdown
Contributor

Yes: at the moment, the implementation calculates a new value for each requested time/frequency coordinates, and these don't match the Wavelet transform,

Even for the regular spectrogram, the time resolution Audacity asks of one spectrum per pixel column is often unnecessarily high. Normally, for a typical hop size of 1024 samples at 48kHz, only 46 analyses per second would be required. At my current zoom level, I have 681 pixels per second... The transition to Au4 may be a good opportunity to rectify this.

Anyway, we've made good progress here for the Wavelet transform. Let's merge what we have. I probably should redirect your PR to the audacity3 branch. Thank you!

@saintmatthieu
saintmatthieu changed the base branch from release-3.7.5 to audacity3 October 13, 2025 01:11
@saintmatthieu
saintmatthieu merged commit ff3e195 into audacity:audacity3 Oct 13, 2025
@saintmatthieu

Copy link
Copy Markdown
Contributor

@kgramhans looks like I've messed up: I rebased and squashed your commits into one but somehow this got rid of the amendments you made (XO("Wavelet (1/6 Octave Hann)") , isn't in the #ifdef WAVELET, the comment still says // Do the convolution, etc.). Please don't erase your local changes :) and open a new PR with them. Sorry about that.

@kgramhans

kgramhans commented Oct 13, 2025 via email

Copy link
Copy Markdown
Contributor Author

@kgramhans

Copy link
Copy Markdown
Contributor Author

@saintmatthieu
Please have a look here : #9686

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.

Wavelet Transform revisited

2 participants