Sign in to follow this  
Followers 0
Delta

Auto Volume Control

1 post in this topic

I can't stand the volume on tv's. When your watching a show or a movie the volume is to low then when music comes on or a commercial comes on the volume is too loud. This script adjusts the volume automatically. You can test it out with music. I use it with my tv-tuner on my pc.

This script is an obvious rip off of CyberZeroCool's Audio Spectrascope and you will also need the Audio.au3 UDF by Volly. It was made quick and does what I wanted it to do.

#Include <string.au3>
#include <misc.au3>
#include <audio.au3>

Opt( "GUIOnEventMode", 1 )
Dim $ConstantVolume = 125; What you want your constant volume to be at. Play around with it a bit.
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError

$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat( "open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat( " ", 100)
$cchReturn = StringLen($lpszReturnString)

$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])

$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat( "status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags);

While 1
    $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
    If $mciError[0] <> 0 Then _mciShowError($mciError[0])
    If $mciError[2] > $ConstantVolume Then _SoundSetMasterVolume(_SoundGetMasterVolume()-1)
    If $mciError[2] < $ConstantVolume Then _SoundSetMasterVolume(_SoundGetMasterVolume()+1)
    ConsoleWrite($ConstantVolume&" : "&_SoundGetMasterVolume()&" : "&$mciError[2]&@CRLF)
    Sleep(1000)
WEnd

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc  ;==>_mciSendString

Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat( " ", 100); Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
    MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc  ;==>_mciShowError

[size="1"]Please stop confusing "how to" with "how do"[/size]

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0