Coding volume meters - HOW TO?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi,

Im developing an audio player (wav/mp3) using MCI because i need to make it able to mix tracks. My code is finished but im looking for develope the VU meters (the volume meters as winamp ones).
I dont want to use dlls (bass, etc) because most of them arent free for commercial use.

What im looking for is how to make the vu meters.
In MCI i cant find a way to find the level of the input or output (dont want the level of volume control). I know there are a "status device level" thay maybe could give it, but since mp3s are not reproduced as waveaudio this command isnt available if playing mp3s.

Is there any way to obtain this level from soundcard or any other realiable source? (not DirectX because i think many users has not installed)
Mixer cant be because many soundcards dosent have vu meter (open you mixer and if there is not a vu meter with the wave level, your sound card dosent gives peak info - i read this somewhere)

Thanks for any help.

Best Regards

Ricardo

Dont cry anymore...:)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Froggerprogger.

I think you have to buffer the output. (and to write a lot of your code new)
Winamp does so, too. As Fmod and Bass.
Then you can read the sampledata manually from your buffer immediately before sending it to the soundcard.
I think there's a way with the waveIO-commands of the WinAPI to create a buffer and a Callback-Proc, but I don't really know, how it goes.


Purebasic - what a nice name for a girl-friend
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
Originally posted by Froggerprogger

I think you have to buffer the output. (and to write a lot of your code new)
Winamp does so, too. As Fmod and Bass.
Froggerprogger,

Yes, i know but as i want a more efficient VU that shows the REAL volume of output i have to calculate the amplitude of the mp3 with the volume of the stream (in Bass case) and with the volume of the Mixer of the PC to obtain a REAL Volume meter.
Thats why i thought that there could be a more easy way (and maybe more reliable), as the one that can read the peek of the soundcard... but its not always available :cry:

At the moment im coding using Bass.dll that is the only one that i know that let me easily do things like equalize, dsp, etc. I tried winamp plugins but cannot find a way to resolve some issues (the volume affect ALL the instances playing, how to equalize, etc).

In fact Bass.dll is something like a wrapper for DirectX (in the features that im using like the mentioned before) and as there is some $$$ considerations about Bass.dll im wondering if there is any known freeware dll that are a wrapper for DirectSound or if its possible to call directsound directly from PB. Of course there is a problem: DirectSoudn only play wav file ¿im i right?

Thanks

Best Regards

Ricardo

Dont cry anymore...:)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Froggerprogger.

As far as I know, DirectSound requests uncompressed PCM-data, as 'normal' WAV- and AIFF-Format is. So if you want to play MP3 or other formats, you have to decode it manually to PCM and then send it to DirectSound - therefore are some free decoders in the http://WWW. />
For playing MP3/Ogg-Files, etc. via MCI, you have to decode them complete to a WAVE-File before playing it - not the best way at all, and you would have no VU, either.

Or you could play it (pre-)buffered via the waveIO-commands (also of course only uncompressed PCM). This is a possibility to create and fill a buffer with (mixed, selfmaded or streamed) audiodata and to get a callback from the buffer to refill it. Then you could even decode the MP3 on-the-fly into a pre-buffer which is read from the callback to fill the output-buffer.
So you could get the actual samplevalue (+/- some milliseconds) and multiply it with the actual mixer-volume-setting to get the real output-value.
I have never coded this manually, yet, but I think there is an VB-example in the API-Guide and here I have an C++ - example on paper for a realtime-sinewave-generator using the waveIO-API - so it is possible.

But I'm wondering if there is a simple way, too. At one point in the cue, there is a value given to the soundcard, isn't it - but how to catch it ?
This would be the most comfortable way for it, followed by playing all files with fmod or bass - and pay for it - check the mainout-volume and optionally the Windows-Mixer-Settings to calculate the real output. BTW: Fmod e.g. doesn't even need DirectSound and works stable on all WIN32-Systems.


Purebasic - what a nice name for a girl-friend
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi Froggerprogger
For playing MP3/Ogg-Files, etc. via MCI, you have to decode them complete to a WAVE-File before playing it - not the best way at all, and you would have no VU, either.
No, MCI can play mp3.
In fact i finished my code using MCI with many advanced options, but has some lacks:

-All DSP must be done to the files before playing it!
-Cant find a way to code the VU meters
But I'm wondering if there is a simple way, too. At one point in the cue, there is a value given to the soundcard, isn't it - but how to catch it ?
Thats exaclty what im looking for.
This would be the most comfortable way for it, followed by playing all files with fmod or bass - and pay for it - check the mainout-volume and optionally the Windows-Mixer-Settings to calculate the real output. BTW: Fmod e.g. doesn't even need DirectSound and works stable on all WIN32-Systems.
Yes, i am testing both.
It seams to me that fmod is a little more stable ¿are you agree?






Best Regards

Ricardo

Dont cry anymore...:)
Post Reply