23 May '13 - 10:18 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2  All
  Reply  |  Print  
Author Topic: Low frequencies and the Misc.Visuals class (Bass.Net - VB.NET)  (Read 2002 times)
ViRUS2012
Posts: 12


« on: 17 Jul '12 - 20:11 »
Reply with quoteQuote

Hey guys, I'm developing a music player for an online radio and I've noticed that the first lines of the visualisation (the ones representing the lower frequencies) never reach the top. In fact, the first line never goes above 50%.



While I'm almost sure my code isn't the problem, here's how I'm drawing the visualisation:

Declarations:
Public drawing As New Un4seen.Bass.Misc.Visuals
Public Smoothness As Integer
Public MainColour As Integer
Public SecondaryColour As Integer
Public PeakColour As Integer
Public BackgroundColour As Integer

This code is on a Timer (named VisTimer) that gets the image from Bass and drops it on a PictureBox (named VisualisationBox):
VisTimer.Interval = Smoothness

        If Visualisation = True And Me.WindowState = FormWindowState.Normal Then

            Dim SpectrumImage As Image
            SpectrumImage = New Bitmap(VisualisationBox.Width, VisualisationBox.Height)
            Dim SpectrumRectangle As New Rectangle(VisualisationBox.Location.X, VisualisationBox.Location.Y, VisualisationBox.Width, VisualisationBox.Height)

            Using g As Graphics = Graphics.FromImage(SpectrumImage)
                If VisualisationType = 0 Then
                    drawing.CreateSpectrumBean(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), 5, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 1 Then
                    drawing.CreateSpectrumDot(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), 5, 1, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 2 Then
                    drawing.CreateSpectrum(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 3 Then
                    drawing.CreateSpectrumEllipse(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), 3, 1, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 4 Then
                    drawing.CreateSpectrumLine(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), 5, 1, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 5 Then
                    drawing.CreateSpectrumLinePeak(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(PeakColour), Color.FromArgb(BackgroundColour), 5, 5, 1, 100, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage
                ElseIf VisualisationType = 6 Then
                    drawing.CreateSpectrumWave(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), 5, LinearRepresentation, FullSoundRange, False)
                    VisualisationBox.Image = SpectrumImage

                ElseIf VisualisationType = 7 Then
                    drawing.CreateWaveForm(stream, g, SpectrumRectangle, Color.FromArgb(MainColour), Color.FromArgb(SecondaryColour), Color.FromArgb(BackgroundColour), Color.FromArgb(BackgroundColour), 5, FullSoundRange, False, False)
                    VisualisationBox.Image = SpectrumImage

                End If
            End Using

        Else
            VisTimer.Stop()
        End If

Thanks in advance for any help you provide  Smiley
« Last Edit: 17 Jul '12 - 20:14 by ViRUS2012 » Logged
radio42
Posts: 4012


« Reply #1 on: 17 Jul '12 - 20:48 »
Reply with quoteQuote

What type of audio file are you using?
Note, that most lossy formats like MP3, WMA, AAC etc. do implement (in the eoncoding stage) some intenal frequency filtering (basically some Loww- and High-Pass-Filters) to eliminate frequencies which are commonly unheard by the human ear - as a result those filtered frequencies are not/can not be restored during decoding and are simply lost.
Might that be the reason?
Logged
ViRUS2012
Posts: 12


« Reply #2 on: 18 Jul '12 - 05:45 »
Reply with quoteQuote

I'm streaming MP3, AAC or WMA (depending on user's choice); but I think it's not that because I've also used Bass.Net with other player I developed, which played MP3 files and the visualisation had the same problem while all other players showed the vis just fine.

Anyway, when I get home I'll try playing a WAV file or some other format to test.
Just got home and tried using a .WAV file that I recorded myself - the vis doesn't go past 50% on the first bar and the second one seems to be stuck at around 80% as well, so it's not the station I'm streaming.

Any ideas?
Logged
ViRUS2012
Posts: 12


« Reply #3 on: 20 Jul '12 - 04:55 »
Reply with quoteQuote

Any ideas? Can anybody at least try to replicate the problem? That way I'd know if it's something with my code or not.
Logged
radio42
Posts: 4012


« Reply #4 on: 20 Jul '12 - 14:38 »
Reply with quoteQuote

I guess the main issue is, that we/you don't know how the 'other player' do represent a graph.
May be they do some filtering or alignment of their visualization - so you can not really compare that.

Depending on what FFT size you are using, it is quite normal, that the very low and the very high frequency FFT buckets never reach a value of 1.0!
A single FFT bucket represents the energy contained in that frequency band - e.g. for 10Hz.

I guess there is no error in the current display/visualization.

You can try to generate a wave sine file only containing a single frequency and see what is displayed.
Logged
ViRUS2012
Posts: 12


« Reply #5 on: 20 Jul '12 - 21:48 »
Reply with quoteQuote

I guess the main issue is, that we/you don't know how the 'other player' do represent a graph.
May be they do some filtering or alignment of their visualization - so you can not really compare that.

Yes, indeed, even though it does seem quite strange that all other players (Winamp, foobar2000, WMP) apply some form of correction, we still don't know for a fact so comparing BASS or my code to theirs is quite useless.

Depending on what FFT size you are using, it is quite normal, that the very low and the very high frequency FFT buckets never reach a value of 1.0!
A single FFT bucket represents the energy contained in that frequency band - e.g. for 10Hz.

I guess there is no error in the current display/visualization.

So I should change the FFT size? How would I do that? I had a look at BASS.Net's help but all I could find was Bass.BASS_ChannelGetData, which would tell me which is the FFT size but not how to set it so I'm obviously missing something.

You can try to generate a wave sine file only containing a single frequency and see what is displayed.

I'll try to look into that as well; though I feel more inclined towards the FFT solution.

Sorry if I seem a bit clueless on this post, tbh it's the first time I've dealt with visualisations and FFT sizes and all that!  Undecided
Logged
ViRUS2012
Posts: 12


« Reply #6 on: 21 Jul '12 - 20:02 »
Reply with quoteQuote

After giving Bass.Net's a more throughout read, I found how to set FFT values, and it didn't make the low freqs go above 50%, but it did throw some interesting results:

http://i.imgur.com/Wsasm.png

I'm linking the image so as not to make the post unnecesarily long.

The fact that not even the ScaleFactor setting made the low frequencies go any higher looks to me as quite a good indication that Bass simply won't draw anything above that point.

Now, this post has a lot of views already. Can anyone please try the Visuals class to check?

Logged
Chris
Posts: 1507


« Reply #7 on: 22 Jul '12 - 11:11 »
Reply with quoteQuote

Hi
 Test this spectrum
 by the way its written in delphi xe2 and not in Net.
  the spectrum has the follwing values
 
  86.1Hz ,172.3Hz ,344.5Hz,516.8Hz,1033.6Hz,1550.4Hz,516.8Hz,9302.2Hz,10336Hz,11370Hz,13437Hz,15503Hz.

Cheers Chris

* spectrumtest.rar (623.45 KB - downloaded 11 times.)
« Last Edit: 22 Jul '12 - 11:15 by Chris » Logged
ViRUS2012
Posts: 12


« Reply #8 on: 22 Jul '12 - 17:51 »
Reply with quoteQuote

That's nice, but are you using the .CreateSpectrumLine function? Because I don't know how did you do to get that kind of Spectrum just using the default call on Bass.

Just for the record, I do know that I can create my own visualisation using the values about frequencies' peaks that Bass gives but I'd like to avoid doing that since it uses a lot more CPU than I'd like for a simple visualisation (your test, for example, uses a full core on my PC, while the app I'm coding only uses around 5% for a much bigger and fluid representation).
Logged
Chris
Posts: 1507


« Reply #9 on: 22 Jul '12 - 19:36 »
Reply with quoteQuote

Update I have a little bit modified the source Now CPU max 1 % here

Hi
 a full Core????
I will have here an abolute old PC (AM2, AMD Sempron 1150 2 GHZ,Nforce Chip,2 Gb Ram ,Geforce 7800 GS Graphic Card)
My Spectrum will have 0 - Max 2 % CPU !!!!!
by the way are you testing on a Netbook / Laptop with a small GraphicCard??
Here is the Code but you must it convert to Net

The first thing

every bin of the Spectrum have the Values Min0 Max 100


const
 // FreqCoef defines the last index number of FFTData[x] for each band.
  
FreqCoef: array [0 .. NumFFTBands - 1] of word = (1, 2, 3, 6,
   // narrow interval for low freq. range
  
12, 18, 24, 30, 36,
// normal interval for middle freq. range
    
42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 120, 132, 156, 180);
 // wide interval for high freq. range
 
Boost = 0.15;
// Factor to intensify high frequency bands
  
Scale = 160;
// Factor to calibrate the output range of BandOut[x]

  
NumFFTBands = 25;
type
TFFTData = array [0 .. 512] of Single;
TBandOut = array [0 .. NumFFTBands - 1] of word;
private
    { Private-Deklarationen }
    BandOut: TBandOut;
    FFTData: TFFTData;
    NewBandOut: TBandOut;

var
 Channel: HStream = 0;


The TimerStuff


procedure TForm3.Timer1Timer(Sender: TObject);
var
  StartIndex: integer;
  i, value, k: integer;
  tmpIntensity: double;
begin
    TimerFFT.Enabled := false;
 // Avoid duplicate timer interrupt

  
if (Channel = 0) or (BASS_ChannelIsActive(Channel) <> BASS_ACTIVE_PLAYING)
  then
    exit;
// exit without re-enabling TimerFFT

 
if BASS_ChannelGetData(Channel, @FFTData, BASS_DATA_FFT512) = DW_ERROR { -1 }
  then
    for i := 0 to (NumFFTBands - 1) do
      BandOut[i] := 0;

   //all errorchecking okay lets start the stuff

  
for i := 0 to (NumFFTBands - 1) do
  begin
    if i = 0 then
      StartIndex := 1
    else
      StartIndex := FreqCoef[i - 1] + 1;

     // tmpIntensity <= the greatest value in a group of classified FFTData[x]'s
    
tmpIntensity := 0;
    for k := StartIndex to FreqCoef[i] do
      if FFTData[k] > tmpIntensity then
        tmpIntensity := FFTData[k];
   
NewBandOut[i] := round(tmpIntensity * (1 + i * Boost) * Scale);

   // Decrease the value of BandOut smoothly for better looking
  
if NewBandOut[i] >= BandOut[i] then
      BandOut[i] := NewBandOut[i]
    else if BandOut[i] >= 2 then
      dec(BandOut[i], 2)
    else
      BandOut[i] := 0;

    // for the case that original NewBandOut is smaller than BandOut by 1
   if NewBandOut[i] > BandOut[i] then
      BandOut[i] := NewBandOut[i];
// Okay we will have the needed Stuff now its time for the Visual Painting
  
  Spectrum.Items[i].position := BandOut[i];  
  end;


 

  Timer1.Enabled := true;
end;
Chris

* spectrumtest.rar (623.35 KB - downloaded 26 times.)
« Last Edit: 22 Jul '12 - 20:21 by Chris » Logged
ViRUS2012
Posts: 12


« Reply #10 on: 23 Jul '12 - 07:00 »
Reply with quoteQuote

I've downloaded your new attachment and it no longer uses a full core.

I'm testing it on an AMD Phenom II X4 965 BE @ 3.42GHz, 4GB RAM, AMD HD5750.

Although your code is nice and all and it does work well, it simply doesn't apply at all to my problem. As I explained above, I know I can create my own visualisation using the info about the stream provided by Bass.

What I'm saying is that the Misc.Visuals class is bugged and the first three lines (the ones used for low frequencies) simply won't reach the top of the graphic, as I shown by the image linked on my previous post.

I hope I'm now clear enough that what I'd like someone to check it's the fact that what the Misc.Visuals function returns as a visualisation has the peak for low frequencies lowered down compared to the rest of the sound spectrum.
Logged
radio42
Posts: 4012


« Reply #11 on: 23 Jul '12 - 17:07 »
Reply with quoteQuote

I am not certain, that there is a bug in it - but I will double check this again!

But note, that the above delphi example also aggregates the frequency bands (see 'tmpIntensity') - which the Bass.Net Visual class is not doing.
As said before, you might generate a a wave sine file only containing a single low frequency and see what is displayed.
Logged
ViRUS2012
Posts: 12


« Reply #12 on: 25 Jul '12 - 02:34 »
Reply with quoteQuote

I think the fact that not even after using ScaleFactorSqr=10 will make the first bars reach the top (as shown in the image I linked above) is quite an indication that something is wrong.

On the other hand, programming as taught me to always leave room for doubts...
Logged
jdg2011
Posts: 18


« Reply #13 on: 25 Jul '12 - 05:21 »
Reply with quoteQuote

Nice spectrum, Chris ! Is this one a bass default spectrum?
« Last Edit: 25 Jul '12 - 05:35 by jdg2011 » Logged
Chris
Posts: 1507


« Reply #14 on: 25 Jul '12 - 05:25 »
Reply with quoteQuote

@jdg2011
Do you mean the code or the graphical Spectrum???
remember its written in Delphi.
Chris
« Last Edit: 25 Jul '12 - 05:28 by Chris » Logged
jdg2011
Posts: 18


« Reply #15 on: 25 Jul '12 - 05:36 »
Reply with quoteQuote

Sorry Chris, The graphical spectrum? Smiley

@Virus2012 I am sure you have some sound files for testing but here is a pretty good frequency testing file in MP3 format zipped for you.

* Sample1.zip (679.88 KB - downloaded 25 times.)
« Last Edit: 25 Jul '12 - 05:51 by jdg2011 » Logged
Chris
Posts: 1507


« Reply #16 on: 25 Jul '12 - 05:59 »
Reply with quoteQuote

Oops i have a little bit wrong understand your question. Yes its based on the default Bass Spectrum.
Logged
jdg2011
Posts: 18


« Reply #17 on: 25 Jul '12 - 06:08 »
Reply with quoteQuote

Very nice Chris, Great work Smiley
Logged
radio42
Posts: 4012


« Reply #18 on: 25 Jul '12 - 13:31 »
Reply with quoteQuote

I double-checked my code and there was indeed a small bug in it with the first fequency band (as I am interpolating near frequencies)!
I'll correct that in the next version!
Logged
ViRUS2012
Posts: 12


« Reply #19 on: 25 Jul '12 - 14:12 »
Reply with quoteQuote

Awesome. Can't wait for the next version!  Wink
Logged
Pages: [1] 2  All
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines