-3

I am a beginner in audio programming and was wondering how would you get the amount of bass in just one single audio sample. I was thinking it would be measured in db maybe but i don't know if there a unit that is actually for measuring bass. I have no code to show for the measuring of the bass since I have no idea where to look or to start out by doing by I've already got everything up to the point of having all the samples of my audio file stored as a float array using the juce library, now its just a matter of going through each sample measuring the bass of each sample

Any help please?

uguigui75
  • 13
  • 1
  • 2
    @uguiugi75 Try researching on what you want. your question is really really vague. I wish I could help but I assume you do not know the theory behind audio sampling. An audio sample is just a level of voltage at a particular instance. I will be SO impressed if one day some one would find out the bass using just one audio sample. – RC0993 Nov 08 '19 at 06:58
  • what you mean by audio sample? is it PCM ? – Spektre Nov 08 '19 at 08:46
  • yes sample is pcm – uguigui75 Nov 09 '19 at 02:09

2 Answers2

1

I am assuming by one audio sample you mean an array of floats, and not just one element of that array.

If you "Google" the word Bass you land on the very first result telling:

Bass (also called bottom end) describes tones of low (also called "deep") frequency, pitch and range from 16 to 256 Hz.

Yes, Bass is just the audio in that range.

Now, with that I think you would be able to figure out how to find frequencies using audio samples and if not, then this is the best I can do...

Now, you can find the amount of Bass, frequencies in the said range, clearly.. :)

RC0993
  • 898
  • 1
  • 13
  • 44
  • 1
    By a quick read of all of this, one though came to my mind. When you know the frequency range, you could use FFT (Fast Fourier Transformation) to get "the amount of bass". – skratchi.at Nov 08 '19 at 07:14
  • I am shooting in the dark here. but is that a question @skratchi.at **?** – RC0993 Nov 08 '19 at 07:16
  • FFT requires more than one sample. – user4581301 Nov 08 '19 at 07:19
  • It is nothing more then a guess. Until we know nothing more then we do what OP wants to do, it is questionable, if FFT fits. – skratchi.at Nov 08 '19 at 07:20
  • 1
    @user4581301 Exactly why I added `I am assuming by one audio sample you mean an array of floats` at the beginning – RC0993 Nov 08 '19 at 07:22
  • yes an array of floats im not good at audio programming at all so I dont know if it was possible to find the bass in one sample. So really the more samples that contain frequencies in that range means more bass in the audio?, and if you were to say add bass to the samples using an audio plugin would that increase the number of samples with those lower frequencies? – uguigui75 Nov 09 '19 at 02:26
  • and so Im really just counting samples that are within that frequency range and the more sample that have those frequencies the amount of bass increase? – uguigui75 Nov 09 '19 at 02:28
  • how would i get the frequency of a single sample? – uguigui75 Nov 09 '19 at 02:42
  • @uguigui75 you obviously lack the math ... either use [DFT](https://stackoverflow.com/a/26355569/2521214) (FFT) to convert your big enough array of samples into set of Niquist frequencies see [RT signal -> spectrum](https://stackoverflow.com/a/24822928/2521214) or use a FIR filter that pass only the wanted range and then you sum up what comes out of it per second ... – Spektre Nov 09 '19 at 16:47
1

There's just one solution here, and it's not what you think. You need to transform your signal in the time domain to a signal in the frequency domain. Bass is the lower part of the frequency domain.

The first thing you need then is the FFT. This takes a number of samples as input. A typical value would be 2048 samples. If your input is a 48 kHz signal, this will divide the signal into 1024 bins of 47 Hz each. The lower 5 bins or so contain the bass part of your signal. (Bin 0 also contains any DC offset, which might be problematic)

You then need to convert these 5 bins into energy; that's just squaring the 5 values and summing them.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • There is another option not using FFT ...instead you could do a band pass digital FIR filter. But I agree using FFT is easier (but slower) as for FIR you need to do the math for designing it (coefficient values and count ...) – Spektre Nov 08 '19 at 08:44