flutter_soloud icon indicating copy to clipboard operation
flutter_soloud copied to clipboard

Make filters easier to use and pitchshift filter

Open alnitak opened this issue 1 year ago โ€ข 1 comments

Description


Removed the main example which was too much complicate for a first approach. In the futere I'll make a new GitHub repository with that. For now there are 2 little example:

  • a metronome
  • a filter use case

Added pitch shift filter to somehow resolve #98. This filter has these parameters:

  • shift: a value of 0.5 means one octave down (12 semitones down), a value of 2.0 means one octave up (12 semitones up).
  • semitones: increases or decrease using semitones (ยน/12 of an octave).

This filter can be used in conjunction with SoLoud.setRelativePlaySpeed() to for example play a sound with voices at double speed without changing the tone speech.


The filters can now be used for single sounds instead of using them only globally.

IMPORTANT: filters for individual sounds are not supported on the web platform. On the other platforms the filter must be added before playing. Only voice handles played after adding the filter will play with the filter chosen.

Filters can now be accessed globally using SoLoud.instance.filters or for single [AudioSource] sounds with sound.filters to resolve #108. With something like:

/// For global filters.
final ps = SoLoud.instance.filters.pitchShiftFilter;
ps.activate();
ps.shift(soundHandle: soundHandle).value = 0.6; // set value.
final shift = ps.shift(soundHandle: soundHandle).value; // get value.
ps.fadeFilterParameter(to: 3, time: const Duration(milliseconds: 2500));
ps.oscillateFilterParameter(from: 0.5 to: 1.5, time: const Duration(milliseconds: 2500));
ps.queryShift.[min | max | def] // to get filter min, max and default values.

/// For single sound filters.
final ps = sound.filters.pitchShiftFilter;
[as for global]

Look at the respective documentation to see how to use them.

Type of Change

  • [x] โœจ New feature (non-breaking change which adds functionality)
  • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
  • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
  • [x] ๐Ÿงน Code refactor
  • [ ] โœ… Build configuration change
  • [ ] ๐Ÿ“ Documentation
  • [ ] ๐Ÿ—‘๏ธ Chore

alnitak avatar Jul 29 '24 12:07 alnitak

For this PR we should think about the version to choose, the check fails on CHANGELOG.md which doesn't have it. On pub.dev this plugin has not been updated to the main branch since PR 85 so we may think of releasing 2.1.0 or a major 3.0 since the news are important.

For this review, regarding the new filters' way to manage them, in the filters dir there are 10 source files for the same number of filters. These sources differ only in their different parameter count and names, so looking only at one will be enough I think.

filters/filters.dart is the source for managing those filters. There is a FiltersSingle class which is instantiated as AudioSource.filters class and a FilterGlobal class which is instantiated as SoLoud.filters.

update: I have fixed the CHANGELOG just to see if this PR is mergeable

alnitak avatar Jul 29 '24 13:07 alnitak

LGTM! Thanks!

filiph avatar Aug 23 '24 12:08 filiph

Also verified the examples on macOS. Love the new tests/tests.dart test app, btw!

filiph avatar Aug 23 '24 13:08 filiph