Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup AddRadioEffect #737

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Cleanup AddRadioEffect #737

wants to merge 7 commits into from

Conversation

gcask
Copy link
Contributor

@gcask gcask commented Jan 4, 2025

Isolated the various FX being applied to separate Filter objects, that are now applied onto the input.

This should make it easier to add new post process, as well as give a better understanding of how they stack together.

Additionally, tweaked the Bandpass to be a single filter instead of multiple ones where the second would be essentially a noop.

Isolated the various FX being applied to separate Filter objects, that are now applied onto the input.

This should make it easier to add new post process, as well as give a better understanding of how they stack together.

Additionally, tweaked the Bandpass to be a single filter instead of multiple ones where the second would be essentially a noop.
_filters[0] =
OnlineFilter.CreateBandpass(ImpulseResponse.Finite, AudioManager.OUTPUT_SAMPLE_RATE, 560, 3900);
_filters[1] =
OnlineFilter.CreateBandpass(ImpulseResponse.Finite, AudioManager.OUTPUT_SAMPLE_RATE, 100, 4500);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two bandpasses were applied back to back: the first one at [560,3900], and the second [100,4500].

AFAICT, there's no need for the second, since all the frequencies in the range it covers were already cut off.

audio = (double)buffer[outputIndex];
}

audio *= RadioFilter.BOOST;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why this was here?
I'd rather work on having lower volumes for the FX?

{
var filter = _filters[j];
audio = filter.ProcessSample(audio);
if (double.IsNaN(audio))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this to a single filter, at the end.
If there are NaN, we'll backfill with random values, as to make some audio glitches.

* CachedAudioFX filters start enabled by default.
* Fixed null variables (woopsies)
* Initialize AM collision FX before refresh settings is called.
@gcask gcask marked this pull request as ready for review January 4, 2025 23:17
@gcask gcask marked this pull request as draft January 7, 2025 00:46

namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Audio.Providers
{
namespace Wave
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now everything has been moved to follow the paradigm of ISampleProvider (a decorator-based approach) from NAudio.

public class ClientEffectsPipeline
{
private readonly Random _random = new Random();

private OnlineFilter[] _filters;
private IOnlineFilter _bandpassFilter = OnlineIirFilter.CreateBandpass(ImpulseResponse.Finite, AudioManager.OUTPUT_SAMPLE_RATE, 560, 3900);
private Dictionary<CachedAudioEffect.AudioEffectTypes, VolumeCachedEffectProvider> _fxProviders = new Dictionary<CachedAudioEffect.AudioEffectTypes, VolumeCachedEffectProvider>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All FX moved to a dictionary, for ease of access


buffer[outputIndex] = (float) audio;
private void AddRadioEffect(float[] buffer, int count, int offset, RadioInformation.Modulation modulation, double freq)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the most composability, should embrace the ISampleProvider decorator approach and return the one we set up, and do a single Read() at the end to process them all.

But I had to find a stopping point somewhere.

@gcask gcask marked this pull request as ready for review January 9, 2025 04:09
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