cycfi / q

C++ Library for Audio Digital Signal Processing
MIT License
1.12k stars 146 forks source link

Use q with a float array ? #40

Closed SeleDreams closed 2 years ago

SeleDreams commented 2 years ago

Hi, I am working on making a vst that performs some equalization tasks by reducing two frequency peaks and increasing two others. I work in a run function that receives a const float inputs and a const float outputs and the uint32_t frame count, i'm not sure how i'm supposed to go about modifying this signal with q

I tried

cycfi::q::audio_channels<const float> inputChannels(inputs,sizeof(const float) * frames,frames);
cycfi::q::audio_channels<float> outputChannels(outputs,sizeof(float) * frames,frames);
cycfi::q::audio_stream stream;
stream.process(inputChannels,outputChannels);

which seems to compile but I am not sure yet if it is the right way to use these methods, I also am not sure about the way to go to do some EQ on the signal

djowel commented 2 years ago

It seems that you already got the answer to this question in Discord?

Generically, say you have a filter f instantiated in your class, you can mix it with the original signal s by adding to boost or subtracting to cut. The factor you apply g is your gain or cut:

   out = s + f(s) * g;

To make it clear, assume (for now) f to be to identity, meaning it simply returns the signal s passed to it. Then you can see that:

   out = s + s * g;

if for example, g is 1, then you get out = s + s * 1, hence s is doubled. If for example g is -1, then you get out = s + s * -1, or 0 (full attenuation, s will cancel out).

Now, imagine that a bandpass filter is used, Then the same operation above applies, but only applied to the frequencies that the bandpass returns. Ditto for lowpass and highpass.

Makes sense?