Problem with equalizer

Started by lazaruz,

lazaruz

I'm converting some old C# stuff to the latest dlls and I'm having a problem with equalizer...
The EQ consists of 10 bands and if I push the last two or three bands to max and leave the other at 0 I get really bad distortions.

I have put together a small test to demonstrate, could anyone see what I'm missing...

int _stream;
private readonly string _fileName = Path.Combine(Application.StartupPath, "audio.mp3");
private readonly float[] EQ_CenterFreq = { 30.0f, 60.0f, 120.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f, 8000.0f, 16000.0f };
private int[] _fxEq = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

public Form1()
{
InitializeComponent();
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
}

private void buttPlay_Click(object sender, EventArgs e)
{
_stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_DEFAULT);
InitEq();
if (_stream != 0) Bass.BASS_ChannelPlay(_stream, false);
}

private void InitEq()
{
Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_FREQ, 44100f);
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true);
Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_COMPRESSOR2, -1);

BASS_DX8_PARAMEQ eq = new BASS_DX8_PARAMEQ();

for (int i = 0; i < _fxEq.Length; i++)
_fxEq[i] = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0);

eq.fBandwidth = 18f;

for (int i = 0; i < EQ_CenterFreq.Length; i++)
{
eq.fCenter = EQ_CenterFreq[i];
eq.fGain = 0.0f;
Bass.BASS_FXSetParameters(_fxEq[i], eq);
}
}

private void UpdateEq(int band, float gain)
{
BASS_DX8_PARAMEQ eq = new BASS_DX8_PARAMEQ();
if (Bass.BASS_FXGetParameters(_fxEq[band], eq))
{
eq.fGain = gain;
Bass.BASS_FXSetParameters(_fxEq[band], eq);
}
}

private void trackBar_ValueChanged(object sender, EventArgs e)
{
TrackBar trackBar = (TrackBar) sender;
int trackbarNum = Convert.ToInt32(trackBar.Tag);
UpdateEq(trackbarNum, trackBar.Value/10f);
}

(: JOBnik! :)

Hi ;D

To avoid distortions use Compressor as well ;)

lazaruz

Isn't that what I'm doing with this?

Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_COMPRESSOR2, -1);

I have also tried with this

Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_COMPRESSOR, -1);

(: JOBnik! :)

#3
Hi ;D

For better performance you should use Floating point samples, e.g: BASS_SAMPLE_FLOAT flag
also enable floating-point DSP BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE)

lazaruz

Thanks, changing this

_stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_DEFAULT);

to this

_stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);

does make it sound better but it still seems that there is something missing...
If I maximize all sliders to 15, the sound gets to high and kinda wobbly.

AndyMK

A well mixed song will usually have the loudest parts of it's audio close to the upper limit of the volume range. If you push frequencies up then the audio will be clipped at the loudest points. Floating point audio improves this somewhat but you will still get some soft clipping. Unlike analog audio, digital audio has a hard cut off point. Like JOBnik! says, use a compressor as a limiter and the result will be much much better. This is not a fault of BASS, all software and hardware dealing with digital audio employ some kind of soft saturation.

stevenmmm

lazaruz, i found using BASS_FX_DX8_PARAMEQ that no adjustments are actually made to the first 2 bands in a 10 band equaliser. Do you find the same?
I ended up using BASS_FX_BFX_PEAKEQ which does work with all bands but find the CPU usage to be significantly higher.

lazaruz

AndyMK: I thought adding this was enough for the compressor, do I have to do something else?

Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_COMPRESSOR2, -1);

stevenmmm: Do you mean that you hear no changes when sliding the first two bands? in that case, no I don't have that problem...