Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Analyzing "loudness" of an audio input.  (Read 246 times)

0 Members and 1 Guest are viewing this topic.

TheBlayder

  • Newbie
  • *
  • Posts: 3
    • View Profile
Analyzing "loudness" of an audio input.
« on: October 13, 2020, 01:30:08 pm »
I am working on a project that requires me to have a auido input i.e. a microphone, which my program constantly checks how loud the sound that gets passed through the microphone is. Is there a way for being able to do this?

I know there is a function called sf::SoundSource::getVolume(). But that just gives a constant value of what volume the sound is being played at. Is there a fuction that I'm missing that can fix my problem, or is that function I need not a thing that exists in SFML?
« Last Edit: October 13, 2020, 01:45:32 pm by TheBlayder »

fallahn

  • Sr. Member
  • ****
  • Posts: 420
  • Buns.
    • View Profile
    • Trederia
Re: Analyzing "loudness" of an audio input.
« Reply #1 on: October 13, 2020, 02:14:42 pm »
This is possible with a class which inherits sf::SoundRecorder and implements onProcessSamples():
https://www.sfml-dev.org/tutorials/2.5/audio-recording.php#custom-recording

I did something similar a few years back which you might be able to adapt: https://github.com/fallahn/scratchvaders/blob/master/src/AudioIn.cpp#L58

TheBlayder

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Analyzing "loudness" of an audio input.
« Reply #2 on: November 12, 2020, 09:56:59 am »
This is possible with a class which inherits sf::SoundRecorder and implements onProcessSamples():
https://www.sfml-dev.org/tutorials/2.5/audio-recording.php#custom-recording

I did something similar a few years back which you might be able to adapt: https://github.com/fallahn/scratchvaders/blob/master/src/AudioIn.cpp#L58

I've been looking at your project that you sent me for a while now, and it has helped a lot to understand how it works and it has ofcourse helped the process of creating my project. Although something that has been bothering me is that I seem unable to find where you're calling the onProcessSamples() function. I can see that you are declaring it and defining it in AudioIn.h and AudioIn.cpp, but I can't find where the function is actually called and used.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Re: Analyzing "loudness" of an audio input.
« Reply #3 on: November 12, 2020, 10:14:00 am »
onProcessSamples is not called in user code, it's called by SFML (more specifically, the base class) whenever there are new samples to process from the audio input (microphone).
Laurent Gomila - SFML developer

TheBlayder

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Analyzing "loudness" of an audio input.
« Reply #4 on: November 12, 2020, 10:52:00 am »
I see. Thanks.
I actually managed to find what wasn't working for me. I was printing out the decibel levels from the audio-input but the numbers were always remaining at 0. Because I had forgotten to update it in the onProcessSamples() function. So it was only calling the text at the beginning of the program, and not constantly updating it with the new info from onProcessSamples().
« Last Edit: November 30, 2020, 10:53:34 am by TheBlayder »