Simple volume meter of stream sounds?

Started by VB_Guy, 1 Aug '03 - 04:02

VB_Guy

Hi, I've been using the Bass control, and I was wondering is it possible to do a simple volume meter of stream sounds, in Visual Basic.

(I'm Using Visual Basic.NET, but I'm sure it VB6 code would work)


Thanks

VB Guy

gogman

#1
Here's the VB6 code I use in my prototype app to show volume levels and current volume setting.

This is drawn directly on the form and scaled to the current volume level (tracked in a configuration class called settings).

Sub DoVolumeLevel()
    On Local Error Resume Next

    Dim L As Integer
    Dim R As Integer
    Dim Level As Long

    Level = BASS_ChannelGetLevel(lng_BASSChannel)

    L = (LoWord(Level) * (Settings.VolumeLevel * 0.01)) * (0.8)
    R = (HiWord(Level) * (Settings.VolumeLevel * 0.01)) * (0.8)

    If L > 100 Then L = 11
    If R > 100 Then R = 11

    Line (62, 4)-(62 + (L * 0.5), 6), RGB(0, 128, 0), BF
    Line -(63 + (L * 0.5), 4), RGB(0, 255, 0), BF
    If L < 99 Then Line (64 + (L * 0.5), 4)-(113, 6), 0, BF


    Line (62, 7)-(62 + (Settings.VolumeLevel * 0.5), 9), RGB(0, 0, 128), BF
    Line -(63 + (Settings.VolumeLevel * 0.5), 7), RGB(0, 0, 255), BF
    If Settings.VolumeLevel < 99 Then Line (64 + (Settings.VolumeLevel * 0.5), 7)-(113, 9), 0, BF

    Line (62, 10)-(62 + (R * 0.5), 12), RGB(0, 128, 0), BF
    Line -(63 + (R * 0.5), 10), RGB(0, 255, 0), BF
    If R < 99 Then Line (64 + (R * 0.5), 10)-(113, 12), 0, BF

End Sub


The " * (Settings.VolumeLevel * 0.01) " in the call scales the line length against the volume setting level. Dump that to have it not scale against your current volume setting.

The 0.8 scaling is used because the levels are returned as 0 to 128 and I want them to scale to 100. Then we multiply by .5 to get it fit in a 50 (not 128) pixel space. Remove the R an L multipliers if you want a full 100 pixel graph.

The form ScaleMode is 3 (pixel). Background color is black.

I have a timer that fires every 250 milliseconds that calls this Sub to update the display.

Enjoy!

-gogman-

Note: Sorry for the edits, I had to clear up what is going on there, it's late, I am tired.

VB_Guy

Sweet - i had to change one thing - the LoWord to GetLoWord (same with hiword)- Then I just used  progress bars to display the values and it works like a charm.

Here's my code:
        Dim Level As Long

        Level = BASS_ChannelGetLevel(strm)

        LprgsLevel.Value = (GetLoWord(Level) * (0.8))
        RprgsLevel.Value = (GetHiWord(Level) * (0.8))

Thanks so much.


VB Guy

VB_Guy

Sorry, the little smiley guys are supposed to be an 8 and a close parenthesis.

I have a little problem though, when the song has ended, do you get Left meter go to maximum? It's a little wierd, oh well.

ANy help would be nice.

Thanks

VB Guy

bigjim

I have had the same thing- in vb just use something like>

If BASS_ChannelGetPosition < Bass_StreamGetLength then Level = BASS_ChannelGetLevel(lng_BASSChannel) else Level = 0
or Level = 127/128 dependending on how the function works- i cant be bothered to read it im tired ::)

VB_Guy

Nice, good thinking, I didn't htink of that. Thanks.

Is that some sort of bug in Bass of something? Because there certainly isn't a peak at the end of the songs, and it's a little odd that it's just on the left side.

Oh well. Thank you.


VB Guy

Chris

#6
I have it made in Delphi so...


procedure TForm1.GetVULevel(var R, L : Integer);
var  Sterio_Level : DWORD;
  begin
       Sterio_level := BASS_ChannelGetLevel(RECORDChan);
        L := LOWORD(Sterio_Level);
        R := HIWORD(Sterio_Level);
end;


And now the OnTimerEvent


procedure TForm1.Timer1Timer(Sender: TObject);
var
L,R : Integer;
begin
L := 0;
R := 0;

If BASS_ChannelIsActive (RecordChan)= BASS_ACTIVE_PLAYING  then
     GetVULevel(R,L);

     GaugeL.Value := L;
     GaugeR.Value := R;
end;


Greets Chris