Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:48:48+00:00 2026-06-02T22:48:48+00:00

Important update: I already figured out the answers and put them in this simple

  • 0

Important update: I already figured out the answers and put them in this simple open-source library: http://bartolsthoorn.github.com/NVDSP/ Check it out, it will probably save you quite some time if you’re having trouble with audio filters in IOS!

^

I have created a (realtime) audio buffer (float *data) that holds a few sin(theta) waves with different frequencies.

The code below shows how I created my buffer, and I’ve tried to do a bandpass filter but it just turns the signals to noise/blips:

    // Multiple signal generator
__block float *phases = nil;
[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
    float samplingRate = audioManager.samplingRate;
    NSUInteger activeSignalCount = [tones count];

    // Initialize phases
    if (phases == nil) {
        phases = new float[10];
        for(int z = 0; z <= 10; z++) {
            phases[z] = 0.0;
        }
    }

    // Multiple signals
    NSEnumerator * enumerator = [tones objectEnumerator];
    id frequency;
    UInt32 c = 0;
    while(frequency = [enumerator nextObject])
    {
        for (int i=0; i < numFrames; ++i)
        {
            for (int iChannel = 0; iChannel < numChannels; ++iChannel) 
            {
                float theta = phases[c] * M_PI * 2;
                if (c == 0) {
                    data[i*numChannels + iChannel] = sin(theta);
                } else {
                    data[i*numChannels + iChannel] = data[i*numChannels + iChannel] + sin(theta);
                }
            }
            phases[c] += 1.0 / (samplingRate / [frequency floatValue]);
            if (phases[c] > 1.0) phases[c] = -1;
        }
        c++;
    }

    // Normalize data with active signal count
    float signalMulti = 1.0 / (float(activeSignalCount) * (sqrt(2.0)));
    vDSP_vsmul(data, 1, &signalMulti, data, 1, numFrames*numChannels);


    // Apply master volume
    float volume = masterVolumeSlider.value;
    vDSP_vsmul(data, 1, &volume, data, 1, numFrames*numChannels);


    if (fxSwitch.isOn) {
        // H(s) = (s/Q) / (s^2 + s/Q + 1)
        // http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
        // BW 2.0  Q 0.667
        // http://www.rane.com/note170.html
        //The order of the coefficients are, B1, B2, A1, A2, B0.
        float Fs = samplingRate;

        float omega = 2*M_PI*Fs; // w0 = 2*pi*f0/Fs

        float Q = 0.50f;
        float alpha = sin(omega)/(2*Q); // sin(w0)/(2*Q)

        // Through H
        for (int i=0; i < numFrames; ++i)
        {
            for (int iChannel = 0; iChannel < numChannels; ++iChannel) 
            {
                data[i*numChannels + iChannel] = (data[i*numChannels + iChannel]/Q) / (pow(data[i*numChannels + iChannel],2) + data[i*numChannels + iChannel]/Q + 1);
            }
        }

        float b0 = alpha;
        float b1 = 0;
        float b2 = -alpha;
        float a0 = 1 + alpha;
        float a1 = -2*cos(omega);
        float a2 = 1 - alpha;

        float *coefficients = (float *) calloc(5, sizeof(float));


        coefficients[0] = b1;
        coefficients[1] = b2;
        coefficients[2] = a1;
        coefficients[3] = a2;
        coefficients[3] = b0;

        vDSP_deq22(data, 2, coefficients, data, 2, numFrames);

        free(coefficients);
    }

    // Measure dB
    [self measureDB:data:numFrames:numChannels];
 }];

My aim is to make a 10-band EQ for this buffer, using vDSP_deq22, the syntax of the method is:
vDSP_deq22(<float *vDSP_A>, <vDSP_Stride vDSP_I>, <float *vDSP_B>, <float *vDSP_C>, <vDSP_Stride vDSP_K>, <vDSP_Length __vDSP_N>)
See: http://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html#//apple_ref/doc/c_ref/vDSP_deq22

Arguments:

float *vDSP_A is the input data
float *vDSP_B are 5 filter coefficients
float *vDSP_C is the output data

I have to make 10 filters (10 times vDSP_deq22). Then I set the gain for every band and combine them back together. But what coefficients do I feed every filter? I know vDSP_deq22 is a 2nd order (butterworth) IIR filter, but how do I turn this into a bandpass?

Now I have three questions:

a) Do I have to de-interleave and interleave the audio buffer? I know setting stride to 2 just filters on channel but how I filter the other, stride 1 will process both channels as one.

b) Do I have to transform/process the buffer before it enters the vDSP_deq22 method? If so, do I also have to transform it back to normal?

c) What values of the coefficients should I set to the 10 vDSP_deq22s?

I’ve been trying for days now but I haven’t been able to figure this on out, please help me out!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:48:49+00:00Added an answer on June 2, 2026 at 10:48 pm

    Your omega value need to be normalised, i.e. expressed as a fraction of Fs – it looks like you left out the f0 when you calculated omega, which will make alpha wrong too:

        float omega = 2*M_PI*Fs; // w0 = 2*pi*f0/Fs
    

    should probably be:

        float omega = 2*M_PI*f0/Fs; // w0 = 2*pi*f0/Fs
    

    where f0 is the centre frequency in Hz.

    For your 10 band equaliser you’ll need to pick 10 values of f0, spaced logarithmically, e.g. 25 Hz, 50 Hz, 100 Hz, 200 Hz, 400 Hz, 800 Hz, 1.6 kHz, 3.2 kHz, 6.4 kHz, 12.8 kHz.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IMPORTANT UPDATE This question was made over 9 years ago. It made sense then,
Important : Please see this very much related question: Return multiple values in C++
Screenshot Important Note : This application does not support Internet Explorer. I will be
Important: This question is getting quite long, if this is the first time you're
I'm already tossing around a solution but as I haven't done something like this
Hey wanted to ask if someone already tried to update the newly released XCode
My problem is similar to this one, How to update a widget every minute
I have a ListView which after populating it, will look like this: I already
Introduction: I asked this question on the P2-forum already but I couldnt get any
first: My technical problem is already solved, so this is not urgent, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.