22 May '13 - 13:45 *
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]
  Reply  |  Print  
Author Topic: Simple volume meter of stream sounds?  (Read 4350 times)
VB_Guy
Posts: 17


« on: 1 Aug '03 - 04:02 »
Reply with quoteQuote

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
Logged
gogman
Posts: 5


« Reply #1 on: 1 Aug '03 - 11:00 »
Reply with quoteQuote

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.
« Last Edit: 1 Aug '03 - 12:24 by gogman » Logged
VB_Guy
Posts: 17


« Reply #2 on: 1 Aug '03 - 21:52 »
Reply with quoteQuote

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.Cool)
       RprgsLevel.Value = (GetHiWord(Level) * (0.Cool)

Thanks so much.


VB Guy
Logged
VB_Guy
Posts: 17


« Reply #3 on: 1 Aug '03 - 22:09 »
Reply with quoteQuote

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
Logged
bigjim
Posts: 232


« Reply #4 on: 2 Aug '03 - 01:55 »
Reply with quoteQuote

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 Roll Eyes
Logged
VB_Guy
Posts: 17


« Reply #5 on: 2 Aug '03 - 07:18 »
Reply with quoteQuote

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
Logged
Chris
Posts: 1507


« Reply #6 on: 5 Aug '03 - 10:51 »
Reply with quoteQuote

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
« Last Edit: 5 Aug '03 - 10:54 by Chris » Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines