Audio Monitor - How?

Blitz3D Forums/Blitz3D Programming/Audio Monitor - How?

polygoon(Posted 2005) [#1]
Is there any way to discover "volume levels" for any sound thats playing at a given time.

Could one find info for system volume, or the left and right channel levels of a playing tune for example?

I'd quite like to make a level meter to try this out. On the surface it seems it would be really trivial or simple, then, just below the surface, you wonder if there's any way to do it at all! Stumped.

Any one know how it's done from Blitz3d and care to share?


John Blackledge(Posted 2005) [#2]
Search for the forums for BlitzBass.
It's a wrapper for Bass.dll which allows yoou access to all low level params.
Trouble is, they charge for Bass.dll.


polygoon(Posted 2005) [#3]
Thanks, I thought it was me being thick as usual, I did not realise it was beyond Blitz3D's capabilities in it's raw form.

I wonder what plans they have to address this shortcoming in BlitzMAX. <shrug>

Not something I'd fail to think of checking before a second purchase, that much is clear.

A day older, a day wiser, and thanks again for it.


Beaker(Posted 2005) [#4]
There is a way to do this without BlitzBass in both Blitz3D and BlitzMax (at least on the PC version) using system userlibs. If I can find the code I will post it up.


polygoon(Posted 2005) [#5]
@ Beaker,

Thanks!

It's funny, I was just thinking how long we've had MP3s and by now you'd almost be forgiven for expecting to find a set of play_entity, level_left_entity and level_right_entity type commands! ;O)

On first glance it'd seem that a language that did not have a built in ability to quickly knock out a built in MP3 player was a touch behind the curve! ;O) Esp. when you think what it should be expected to do with graphics as a comparison.

I guess BlitzMM would not be such a daft plan really. (where MM=multimedia!)

Even the oft slothful Microsoft got XP MediaCentre edition by now, and have had for some time! ;O)


Banshee(Posted 2005) [#6]
"Even the oft slothful Microsoft got XP MediaCentre edition by now"
Which by default cannot play DVD (w/o 3rd party expansion), Realplay, Quicktime, or DivX. Which pretty much sums up everything downloadable off the net these days.


polygoon(Posted 2005) [#7]
@ Becky Rose,

Yes, it's pretty much what I'd expect though, given the somewhat proprietary nature of most of that list.

It's hard to imagine any of the owners of those technologies just offering to give this stuff to MS for free. Maybe exclusively, but I cant imagine how that would come about either.

It also means MS are in less of a position to just force whatever content they want on a user, and that's probably a good thing in an operating system.

These are so obviously about to become such seriously mundane, everyday technologies, that it's almost impossible to consider a programming or control based product which does not fully address the matter, and still be able to see it as even complete, let alone competent or serious. Making sure it's the best it possibly can be probably should go on some one's to do list somewhere or other.

Every time the BASIC world shrinks a little more, then the horizon opens wider to encompass far more than simply being a games specialist. Scary Big or what?


John Blackledge(Posted 2005) [#8]
Beaker, dont't want to burt your bubble, but I've been looking into this for months, and if there's a way to get the current amplitude at any instant for audio playing in Blitz3D (without using Bass.dll) then I, and many others, haven't found it.

"using system userlibs" - that's a bit vague.
Can you be more explicit?

If you really do know a way and can tell us, then I and many others will be very grateful, and call you 'Master'. ;)


Cold Storage(Posted 2005) [#9]
As is the case with most things on the "tricky" side with Blitz 3D.
.
.
.
.
Learn C++ and bin your copy of Blitz. :O(

Blitz is a lovely little bubble to be inside most of the time, but it's at times like this that it's shortcomings are all the more obvious.

It needs more low level access, for files and sound... but unless we all throw $$$ at Mr. Silby for some extra programming resource I can't see it happening.

Ho hum... ( sorry to be a misery! - hehehe! )


John Blackledge(Posted 2005) [#10]
Ignore the message "Learn C++ and bin your copy of Blitz."
- obviously pissed. Otherwise, what are you doing on this site. This is for true believers only - get thee gone, heretic!

@polygoon: We keep petitioning Mark Sibly for this, but (and I speak as a hem hem professional myself) apart from the need for money his priorities are always going to be what to spend time on for the benefit of the most people.

If it really is that important then pay for Bass.dll.
Personally I pray every night that one of the nerds... err sorry, geniuses on this site will one day crack it as a userlib.


markcw(Posted 2005) [#11]
no ColdStorage is right, Blitz won't let you
program everything, like this for example.

no point believing Blitz can do anything
when it can't, but also not much point
expecting Mark to make it do everything,
the dll support can cover this stuff now.


Hotcakes(Posted 2005) [#12]
First of all, The audio shortcomings are not necessarily Blitz's fault. Blitz uses a system called FMOD for it's sound system, which is similar to BASS - a special cut down limited license version has been sold to BRL which means we get basic audio functionality (plus the bonus of mod playback and automatic audio streaming) in exchange for not having to individually pay fees whenever we want to release a game. None of this is officially confirmed or denied, but it makes a lot of sense.

I wonder what plans they have to address this shortcoming in BlitzMAX. <shrug>

BlitzMAX's audio system is a homebrew called freeaudio - it's very young at the moment and so only very basic features have been granted to the average user - but the system is opensource (and freeware I think?!?) which means even if BRL never get around to it, at least -someone- here could tinker around and provide some features...

There is also talk that BRL plans to write a wrapper module for FMOD - but then licensing costs would be the individual's responsibility.

Which by default cannot play DVD (w/o 3rd party expansion), Realplay, Quicktime, or DivX.

Actually, if you have an internet connection WMP will automatically find a version of the DivX codec... also it will point you in the right direction to find a codec for QuickTime - that is, a 3rd party CODEC for QuickTime, not Apple's proprietary .dll apis for QuickTime... which means you can play QuickTime movies in anything ;]

unless we all throw $$$ at Mr. Silby for some extra programming resource I can't see it happening.

aka buying BlitzMax ;]

his priorities are always going to be what to spend time on for the benefit of the most people.

I would sincerely hope his priorities lie in spending time on what is for the benefit of Blitz Research Limited. Which at this very moment in time, means the Max3D module, so BRL can stop claiming B3D to be their flagship product...


Cold Storage(Posted 2005) [#13]
Surely Blitz uses DirectX 7 audio calls too? In which case there must be some low level access that didn't make it's way into blitz as a command.

Some things that you'd think'd be obvious like the dos "attrib" command as a Blitz Command are missing.

But then I guess the main purpose of Blitz 3D is to create 3D environments, and games? ;O)

I've been writing a music sequencer with it, and it's been a joy to use bar the limited file access/control/manipulation e.g. finding which drives are connected and available for importing samples.

So writing a full-on file browser, file manager style app. isn't really that easy.

Error trapping is somewhere where there could be much improvement too - so that you don't have to bomb out of the .exe just because a drive isn't mounted anymore etc.

But yes, I'm sure all hands are on deck creating BlitzMax...


polygoon(Posted 2005) [#14]
If BlitzMax rectifies the ommission to my liking then it'll go back on my shopping list, for now it's off the list.

I mean it's really simple; if I don't like it, why would I buy it?

No point buying it and hoping it will get fixed, as that's the exact problem I got now with THIS Blitz product. Having the same problem with a second Blitz product would definitely be my own fault! ;O)

Fixing this shortcoming in existing products is not part of Blitz's track record to date. The only real choice this leaves me is to be more wary of Blitz in future. I'm not looking for a 3rd party solution to that which, in my view, really should have been there from day one.


polygoon(Posted 2005) [#15]
@John Blackledge

Just an odd after thought; are you saying that given the price of bass itself could be gotten around then you could write the said code? And would that be interesting to you at all?

Could there be a collaborative effort in the offing here?


Damien Sturdy(Posted 2005) [#16]
This is where the windows HAL is a PITA. I miss programming my SB16 directly using poke commands >.<;;


polygoon(Posted 2005) [#17]
Yes, it's odd how something like an mp3 player might get written in spite of the OS and Language, rather than because of them.

I'm just a model maker so have slightly less than no chance of pulling this one off. ;O) I do have some slightly unusual ideas for how it might look once done though.

A 3D MP3_player/audio_mixer can't be all that common, can it?! ;O)


Damien Sturdy(Posted 2005) [#18]
Its not impossible. hell, itd be piss easy on windows 95- But any NT core? We have to use what windows gives up :(


polygoon(Posted 2005) [#19]
Well if anyone ever figures it out and can face having 3d controls that really work, then we could get the model side sorted in no time flat.

I've made plenty of dials knobs and buttons in my time.

What I'd really like is to get proper old fashioned VU meters
(read analogue) into this, with working peak lights etc.

I reckon the windows mixer looks a bit naff and could stand some "breathing on" too! ;O)


Damien Sturdy(Posted 2005) [#20]
Im going to look nito this later. I want to revive my old synth projects some :/


polygoon(Posted 2005) [#21]
How old? Ex VCS3 owner needs to be told! ;O)

Probably not THAT old I guess! ;O)


John Blackledge(Posted 2005) [#22]
@Polygon

Bass comes with a few examples, one of which I hacked (below).
Basically I was after some sort of UVmeter-like effect which would give me the amplitude of a wav file at any moment, then I could open and close a character's mouth in sync, using a bone.

Unfortunately other things have taken priority (it's probably 6 months ago) but at least the concept is proven
Graphics 200,130,32,2 : SetBuffer BackBuffer()
AppTitle "FX-Example" : Include "BASS.bb"

;File$ = "Example.mp3"
;File$ = "TITLE.xm"
File$ = "0.wav"

hWnd = GetActiveWindow()
If Not BASS_Init(-1,44100,0,hWnd) Then
	RuntimeError "BASS.dll can't be initialize!"
EndIf

If Not BASS_Start() Then
	BASS_Free()
	RuntimeError "Can't start it!"
EndIf 

Channel = BASS_StreamCreateFile(0,File$,0,0,BASS_SAMPLE_FX)
If Not Channel Then
	Channel = BASS_MusicLoad(0,File$,0,0,BASS_MUSIC_LOOP Or BASS_MUSIC_RAMP Or BASS_MUSIC_FX)
	If Not Channel Then
		BASS_Stop()
		BASS_Free()
		RuntimeError "Can't load " + File$ + "!"
	EndIf
EndIf

Dim ScrollValues(3) : Dim ScrollBarsSet(3)
ScrollValues(0) = 10
ScrollValues(1) = 10
ScrollValues(2) = 10
ScrollValues(3) = 00

Dim FX(3)
FX(0) = BASS_ChannelSetFX(Channel,BASS_FX_PARAMEQ)
FX(1) = BASS_ChannelSetFX(Channel,BASS_FX_PARAMEQ)
FX(2) = BASS_ChannelSetFX(Channel,BASS_FX_PARAMEQ)
FX(3) = BASS_ChannelSetFX(Channel,BASS_FX_REVERB)

BASS_FXPARAMEQ = CreateBank(12)
PokeFloat BASS_FXPARAMEQ,08,0.0
PokeFloat BASS_FXPARAMEQ,04,18.0

PokeFloat BASS_FXPARAMEQ,00,125.0
Result = BASS_FXSetParameters(FX(0),BASS_FXPARAMEQ)

PokeFloat BASS_FXPARAMEQ,00,1000.0
Result = BASS_FXSetParameters(FX(1),BASS_FXPARAMEQ)

PokeFloat BASS_FXPARAMEQ,00,8000.0
Result = BASS_FXSetParameters(FX(2),BASS_FXPARAMEQ)

UpdateFX(0)
UpdateFX(1)
UpdateFX(2)
UpdateFX(3)

BASS_StreamPlay(Channel, 0, 0) ;BASS_SAMPLE_LOOP)
BASS_MusicPlay(Channel)

While Not KeyDown(1)
	Cls
	; Q(+) And A(-) | W(+) And S(-) | E(+) And D(-) | R(+) And F(-)
	If KeyHit(16) And ScrollValues(0) < 20 Then ScrollValues(0) = ScrollValues(0) + 1 : ScrollBarsSet(0) = 1
	If KeyHit(30) And ScrollValues(0) > 00 Then ScrollValues(0) = ScrollValues(0) - 1 : ScrollBarsSet(0) = 1
	If KeyHit(17) And ScrollValues(1) < 20 Then ScrollValues(1) = ScrollValues(1) + 1 : ScrollBarsSet(1) = 1
	If KeyHit(31) And ScrollValues(1) > 00 Then ScrollValues(1) = ScrollValues(1) - 1 : ScrollBarsSet(1) = 1
	If KeyHit(18) And ScrollValues(2) < 20 Then ScrollValues(2) = ScrollValues(2) + 1 : ScrollBarsSet(2) = 1
	If KeyHit(32) And ScrollValues(2) > 00 Then ScrollValues(2) = ScrollValues(2) - 1 : ScrollBarsSet(2) = 1
	If KeyHit(19) And ScrollValues(3) < 20 Then ScrollValues(3) = ScrollValues(3) + 1 : ScrollBarsSet(3) = 1
	If KeyHit(33) And ScrollValues(3) > 00 Then ScrollValues(3) = ScrollValues(3) - 1 : ScrollBarsSet(3) = 1
	
	For I = 0 To 3
		If ScrollBarsSet(I) Then 
			UpdateFX(I) 
			ScrollBarsSet(I) = 0
		EndIf
	Next
	
	DrawScrollBars()
	
;DWORD level,Left,Right;
level%=BASS_ChannelGetLevel(Channel);
;L=LOwWORD(level); // the left level
;R=HIWORD(level); // the right level 
;L = level Shr 16
;L = level Xor %11111111111111110000000000000000
levleft = level% Shr 16
levright = level% Xor 8 ;%00000000000000000000000011111111
Text 0,0,levleft+" "
Line 0,10,levleft,10
Text 0,20,levright+" "
	
	Flip
Wend

BASS_Stop : BASS_StreamFree(Channel)
BASS_MusicFree(Channel) : BASS_Free()
End 

Function UpdateFX(ScrollIndex)
	Local Value,Parameters,Result
	
	Value = ScrollValues(ScrollIndex)
	If ScrollIndex > - 1 And ScrollIndex < 3
		Parameters = CreateBank(12)
		Result = BASS_FXGetParameters(FX(ScrollIndex),Parameters)
		PokeFloat Parameters,08,10 - (20 - Value)
		Result = BASS_FXSetParameters(FX(ScrollIndex),Parameters)
	Else
		Parameters = CreateBank(16)
		Result = BASS_FXGetParameters(FX(ScrollIndex),Parameters)
		PokeFloat Parameters,04,-0.012 * (20 - Value)^3
		Result = BASS_FXSetParameters(FX(ScrollIndex),Parameters)
	EndIf
End Function 

Function DrawScrollBars()
	Text 000,100,"125-hz" : Text 000,112,Scrollvalues(0)
	Text 050,100,"1-khz"  : Text 050,112,Scrollvalues(1)
	Text 100,100,"8-khz"  : Text 100,112,Scrollvalues(2)
	Text 150,100,"reverb" : Text 150,112,Scrollvalues(3)
	Rect 000,100 - ScrollValues(0) * 5,49,ScrollValues(0) * 5,1
	Rect 050,100 - ScrollValues(1) * 5,49,ScrollValues(1) * 5,1
	Rect 100,100 - ScrollValues(2) * 5,49,ScrollValues(2) * 5,1
	Rect 150,100 - ScrollValues(3) * 5,49,ScrollValues(3) * 5,1
End Function



polygoon(Posted 2005) [#23]
First it wanted bass.bb

I found a copy of bass.bb and shoved in in the same directory.

Then spotted the ref to an mp3 file, so I provided a file called Example.mp3

But on running I now got: function GetActiveWindow not found. And I'm not sure what to do about that one! ;O)

Bear in mind I have absolutely no clue what I am doing here! ;O)

I'll go do what I'm good with and make a nice 3d VU meter or two! I'm on much firmer ground with that. ;O)


John Blackledge(Posted 2005) [#24]
Sorry, polygon. Try this:

www.tla-data.co.uk/dowload/bassmeter.zip

(bass.dll, bass.bb etc)
I've included my copy of user32.lib for GetActiveWindow.


polygoon(Posted 2005) [#25]
Nope, dead link! I'll retry in about ten minutes then repeat! ;O)


Damien Sturdy(Posted 2005) [#26]

How old? Ex VCS3 owner needs to be told! ;O)

Probably not THAT old I guess! ;O)



I'd say about 1995 old. :P

whoah. Thats sweet! Have you ever tried TasMan for the PC? it looks like one of those, but its modular ^.^

BTW, I was talknig about a software synth- The closest to an actual synth I've ever owned was a PSS480 yamaha keyboard with inbuilt FM synthesis (and the ability to modify them, making that section of the keyb a synth)

I still want a Supernova pro X synth. Awesome sound!

I stated a few synth projects in QBASIC because i was able to directly access the sound card, however, it stopped working on NT based systems. I started again in blitz but lost my GUI and gave up hope :(


John Blackledge(Posted 2005) [#27]
Sorry, polygon. Try this:

www.tla-data.co.uk/download/bassmeter.zip

(download with an 'n'!)


polygoon(Posted 2005) [#28]
Sorry John, wasn't being my most imaginative, should have spotted that one. Check your mailbox BTW ;O)

Cyg, that's peretty cool assuming we are talking tassman4?

I just grabbed some of those mp3 samples and it can make some lovely noises for sure.


Damien Sturdy(Posted 2005) [#29]
Thas the wun!


gburgess(Posted 2006) [#30]
Sorry to resurrect this thread, but I was wondering if you could please repost this example, John? I can't seem to download it.


John Blackledge(Posted 2006) [#31]
Ok - it's back at the link specified above.
Good luck.


LamptonWorm(Posted 2009) [#32]
Hi, does anyone have a working link for this example please?

Cheers,
LW.


John Blackledge(Posted 2009) [#33]
Back on this link:

www.tla-data.co.uk/dowload/bassmeter.zip


LamptonWorm(Posted 2009) [#34]
Cool, thanks.