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 6556033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:53:33+00:00 2026-05-25T12:53:33+00:00

Possible Duplicate: How to catch the event when spectrum of an audio reached a

  • 0

Possible Duplicate:
How to catch the event when spectrum of an audio reached a specific height, like triggered event made by a loud sound?

I want to detect for a example, a beat or a loud sound from an audio file. All the modules are working except that I don’t know how to code the detection. Some says, I’ll iterate the data from the spectrum and record the parts where there is a load sound or a beat.

I’ll show you the code of my FFT, I got this from NAudio. Can you show me if I can detect an event here.

For example:

 if (waveLeft[] > amplitudeThreshold || waveleft[] < -amplitudeThreshold)
 listbox.items.add(ActiveStream.CurrentTime)

That’s the idea.

So here’s the code.

public SampleAggregator(int bufferSize)
    {
        channelData = new Complex[bufferSize];
    }

    public void Clear()
    {
        volumeLeftMaxValue = float.MinValue;
        volumeRightMaxValue = float.MinValue;
        volumeLeftMinValue = float.MaxValue;
        volumeRightMinValue = float.MaxValue;
        channelDataPosition = 0;
    }

    /// <summary>
    /// Add a sample value to the aggregator.
    /// </summary>
    /// <param name="value">The value of the sample.</param>
    public void Add(float leftValue, float rightValue)
    {            
        if (channelDataPosition == 0)
        {
            volumeLeftMaxValue = float.MinValue;
            volumeRightMaxValue = float.MinValue;
            volumeLeftMinValue = float.MaxValue;
            volumeRightMinValue = float.MaxValue;
        }

        // Make stored channel data stereo by averaging left and right values.
        channelData[channelDataPosition].X = (leftValue + rightValue) / 2.0f;
        channelData[channelDataPosition].Y = 0;
        channelDataPosition++;            

        volumeLeftMaxValue = Math.Max(volumeLeftMaxValue, leftValue);
        volumeLeftMinValue = Math.Min(volumeLeftMinValue, leftValue);
        volumeRightMaxValue = Math.Max(volumeRightMaxValue, rightValue);
        volumeRightMinValue = Math.Min(volumeRightMinValue, rightValue);


        if (channelDataPosition >= channelData.Length)
        {
            channelDataPosition = 0;
        }



    }

    /// <summary>
    /// Performs an FFT calculation on the channel data upon request.
    /// </summary>
    /// <param name="fftBuffer">A buffer where the FFT data will be stored.</param>
    public void GetFFTResults(float[] fftBuffer)
    {            
        Complex[] channelDataClone = new Complex[4096];
        channelData.CopyTo(channelDataClone, 0);
        // 4096 = 2^12
        FastFourierTransform.FFT(true, 12, channelDataClone);
        for (int i = 0; i < channelDataClone.Length / 2; i++)
        {
            // Calculate actual intensities for the FFT results.
            fftBuffer[i] = (float)Math.Sqrt(channelDataClone[i].X * channelDataClone[i].X + channelDataClone[i].Y * channelDataClone[i].Y);

        }


    }

Thank you for the help. 🙂

  • 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-05-25T12:53:34+00:00Added an answer on May 25, 2026 at 12:53 pm

    The basic idea:

    • You segment your stream of wave-form samples into timeslices and convert each slice to the F-domain with your FFT.

    • Then you have a stream of FFT frames in which you check each channel (bin) for peaks. You’ll need a lastValue and maybe even a little state-machine per bin.

    FFT width and peaklevel to be configured.

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

Sidebar

Related Questions

Possible Duplicate: Is there a way to catch the back button event in javascript?
Possible Duplicate: Trying to loop 3 threads in a specific order everytime I want
Possible Duplicate: catch exception by pointer in C++ I always catch exceptions by value.
Possible Duplicate: How to catch exceptions I have not really had to use try
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Why catch and rethrow Exception in C#? I've been scouring the net
Possible Duplicate: When to use try/catch blocks? Main method code entirely inside try/catch: Is
Possible Duplicate: What is the advantage of using try {} catch {} versus if

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.