-2

I'm trying to connect Delphi to Windows VolumeControl API to display WaveOut sound. I found the following code, but it doesn't work:

function Wave_SuportaControleVolume: boolean;
var
  Caps: TWaveOutCaps;
begin
  if WaveOutGetDevCaps(WAVE_MAPPER, @Caps,
       SizeOf(Caps)) = MMSYSERR_NOERROR then
    Result := Caps.dwSupport and WAVECAPS_VOLUME <> 0
  else
    Result := false;
end;

type
  TVolume = record
    Esquerdo: Word;
    Direito: Word;
  end;

function Wave_ObterVolume: TVolume;
begin
  waveOutGetVolume(integer(WAVE_MAPPER), @Result);
end;

procedure Wave_DefinirVolume(Volume: TVolume);
begin
  waveOutSetVolume(integer(WAVE_MAPPER), LongWord(Volume));
end; 

When I use this code, the value of Wave_ObterVolume is always 65535, no matter what I do.

My goal is very simple: I'd like to see the sound value as a progress bar when I play some MP4 or MP3 file. I already have the layout and timer component connected as it should be to display the sound on the progress bar. In fact, I'd use a kind of VUMeter component to do this.

Detail: Using Delphi 7. I know, it's very old, but it's my available tool.

So, the question is what code I use to reach WaveOut Windows VolumeControl?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    There's a problem with your question. Your problem description: "doesn't work". My assumption was that you did not understand what 65535 meant. Perhaps you didn't. But now it seems that you won't be satisfied until your problem, whatever it is, is solved. All we can do is try to answer the questions that you ask. – David Heffernan Jan 01 '15 at 07:03
  • Possible duplicate - http://stackoverflow.com/questions/25967462/delphi-get-wave-amplitude – Tom Brunberg Jan 01 '15 at 11:31

2 Answers2

0

The documentation says:

A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.

It looks like the volume is turned up full.

You don't check the return value of all your API calls. This is a mistake. Always check return values and implement suitable error handling.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you for your answer. In fact, I saw that explanation about full volume and silence. But the volume *is not* turned up full. – Gabarito007 Dec 31 '14 at 20:08
  • The system appears to think differently. Assuming of course that `waveOutGetVolume` succeeded (you can't tell), and that `WAVE_MAPPER` is the right device. – David Heffernan Dec 31 '14 at 20:36
  • So, how to solve that? How do you would write the code to check return values, to know about waveOutGetVolume succeeded and that WAVE_MAPPER is the right device? – Gabarito007 Dec 31 '14 at 22:33
  • 1
    Start by reading the documentation. It tells you how to check for errors. – David Heffernan Jan 01 '15 at 06:02
0

I'm afraid that the code you are using won't give you the results that you desire. Why?

The code you are using is intended to programatically retrieve or set the sound volume of wave output just as if you would do it throug moving the slider in sound mixer.

Now in order for you to be able to get the visual representation of the playing sound output you actually need to record that sound output and then get the sound value from recorded data.

If you are on Windows XP you do this simply by recording audio from "Software output" channel, but if you are on Windows Vista and newer this is no longer posible unless you are using some unoficial software drivers. Why?

All sound drivers that are made for Windows Vista or newer must not alow recording from "software output" channel becouse in the past this was used to often to circument any digital rights protection measures. Pepole simply played digitally protected content in Window Media player for instance and then at the same time recorded the sound output in another program. This meant that all digital protection mechanizms were simply obsolete.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • SilverWarior, may you please explain better how to record the audio using "Software output" channel? Yes, I am still on Windows XP. – Gabarito007 Dec 31 '14 at 22:59
  • About to record the audio, I already have it saved. I mean, I'd like to get the visual representation of the playing sound output from MP3 and MP4 files already saved on disk. – Gabarito007 Dec 31 '14 at 23:09
  • So far my only expirience working with sounds (recording, VU visualization) is by using the BASS sound library (http://www.un4seen.com/) which is not a freware library but you can still use it for noncomercial products. Now if my memory serves me corectly BASS sound library also comes with several examples on how to use it and one of them is the example for making VU visualization. I'm not sure about that as it is a while back since I used this. There are other libraries that might provide you with similar functionality and you could probably do this by using pure API but I don't know how. – SilverWarior Jan 01 '15 at 02:15