in reply to Output syntax for waveOutGetVolume API

Derived from waveOutGetVolume

## following on from your code ## If the values are wacky try 'nn' instead of 'vv' my( $leftVol, $rightVol ) = unpack 'vv', $vol; my $leftPercent = $leftVol * 100 / 0xffff; my $rightPercent = $rightVol * 100 / 0xffff; ## Numerically correct if not to a sound engineer my $totalVolPercent = ( $leftPercent + $rightPercent ) / 2;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^2: Output syntax for waveOutGetVolume API
by slloyd (Hermit) on Jul 14, 2004 at 04:07 UTC
    Thanks a lot. That worked great!

    For the record, here is the final code wrapped into a subroutine.

    sub getSoundVolume { #usage: $tpcnt=getSoundVolume($hwnd) or ($tpcnt,$lpcnt,$rpcnt)=get +SoundVolume($hwnd); #info: gets sound volume - $tpcnt is a number from 0 to 100. my $hwnd = shift || 0; my $vol=" "x10; $waveOutGetVolume ||= new Win32::API("Winmm", "waveOutGetVolume", +['N','P'], 'N') || return; my $ck = $waveOutGetVolume->Call($hwnd, $vol); my ($leftVol,$rightVol) = unpack 'vv', $vol; my $leftPercent = int($leftVol * 100 / 0xffff); my $rightPercent = int($rightVol * 100 / 0xffff); my $totalVolPercent = int(($leftPercent+$rightPercent)/2); if(wantarray){return ($totalVolPercent,$leftPercent,$rightPercent) +;} return $totalVolPercent; }