Autor Beitrag
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 01.06.08 20:14 
Hallo zusammen!

Ich versuche momentan, die Lautsprecherlautstärke (komisches Wort) systemweit aus einem Delphiprogramm heraus zu ändern, habe aber noch keine passende Win-API-Funktion gefunden.
Zur Verdeutlichung was gemeint ist, siehe Anhang.

Weiß irgendjemand wie das funktioniert?

Crosspost DP

mfg
jakobwenzel
Einloggen, um Attachments anzusehen!
_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.


Zuletzt bearbeitet von jakobwenzel am Mo 29.09.08 14:55, insgesamt 1-mal bearbeitet
Wonko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 69



BeitragVerfasst: So 01.06.08 21:41 
Hallo,
in der Open Sorce-Sparte gibt es ein Programm "A.L.A.R.M.". Dort wird aber, glaube ich, nur der Wave-Regler verstellt. Deshalb habe ich irgendwo anders her noch folgende Unit eingebunden, die eine Systemeinstellung ermöglicht. Ich weiß leider nicht mehr, wo ich die Unit her habe...
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
{ Frei nach by Serhiy Perevoznyk }
unit Volume;

interface
Uses SysUtils, Windows, MMSystem;

////////////////////////////////////////////////////////////////////////////////
function SetMasterVolume(Value: Cardinal) : boolean;
function GetMasterVolume : Cardinal;
procedure SetDeviceVolume(var volLe, volRi: Word);
procedure SetWaveVolume(var volLe, volRi: Word);
////////////////////////////////////////////////////////////////////////////////
implementation
////////////////////////////////////////////////////////////////////////////////
function InitMixer: HMixer;
var 
  Err: MMRESULT; 
begin 
  Err := mixerOpen(@Result, 0, 0, 0, 0);
  if Err <> MMSYSERR_NOERROR then 
    Result := 0; 
end;
////////////////////////////////////////////////////////////////////////////////
function GetMasterVolumeControl(Mixer: hMixerObj;
                                var Control: TMixerControl): MMResult; 
var 
  Line     : TMixerLine; 
  Controls : TMixerLineControls; 
begin 
  ZeroMemory(@Line, SizeOf(Line));
  Line.cbStruct := SizeOf(Line); 
  Line.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; 
  Result := mixerGetLineInfo(Mixer, 
                             @Line, 
                             MIXER_GETLINEINFOF_COMPONENTTYPE); 
  if Result = MMSYSERR_NOERROR then begin 
    ZeroMemory(@Controls, SizeOf(Controls)); 
    Controls.cbStruct := SizeOf(Controls); 
    Controls.dwLineID := Line.dwLineID; 
    Controls.cControls := 1; 
    Controls.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME; 
    Controls.cbmxctrl := SizeOf(Control); 
    Controls.pamxctrl := @Control; 
    Result := mixerGetLineControls(Mixer, 
                                   @Controls, 
                                   MIXER_GETLINECONTROLSF_ONEBYTYPE); 
  end; 
end; 
////////////////////////////////////////////////////////////////////////////////
function SetMasterVolume(Value: Cardinal) : boolean;
var 
  MasterVolume    : TMixerControl; 
  Details         : TMixerControlDetails; 
  UnsignedDetails : TMixerControlDetailsUnsigned; 
  Code            : MMResult;
  Mixer           : hMixerObj;
begin 
  Mixer := InitMixer; 
  Result := false; 
  Code := GetMasterVolumeControl(Mixer, MasterVolume); 
  if(Code = MMSYSERR_NOERROR)then begin 
    with Details do begin 
      cbStruct := SizeOf(Details); 
      dwControlID := MasterVolume.dwControlID; 
      cChannels := 1;  // set all channels 
      cMultipleItems := 0; 
      cbDetails := SizeOf(UnsignedDetails); 
      paDetails := @UnsignedDetails; 
    end; 
    UnsignedDetails.dwValue := Value; 
    if(mixerSetControlDetails(Mixer, 
                              @Details,
                              MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then 
      Result := true; 
  end; 
end; 
////////////////////////////////////////////////////////////////////////////////
function GetMasterVolume : Cardinal;
var
  MasterVolume    : TMixerControl; 
  Details         : TMixerControlDetails; 
  UnsignedDetails : TMixerControlDetailsUnsigned; 
  Code            : MMResult; 
  Mixer           : hMixerObj;
begin 
  Mixer := InitMixer; 
  Result := 0; 
  Code := GetMasterVolumeControl(Mixer, MasterVolume); 
  if(Code = MMSYSERR_NOERROR)then begin 
    with Details do begin 
      cbStruct := SizeOf(Details); 
      dwControlID := MasterVolume.dwControlID; 
      cChannels := 1;  // set all channels 
      cMultipleItems := 0; 
      cbDetails := SizeOf(UnsignedDetails); 
      paDetails := @UnsignedDetails; 

    end; 
    if(mixerGetControlDetails(Mixer, 
                              @Details, 
                              MIXER_GETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then
      result := UnsignedDetails.dwValue;
  end;
end; 
////////////////////////////////////////////////////////////////////////////////
//aus SoundControl.pas
////////////////////////////////////////////////////////////////////////////////
procedure SetWaveVolume(var volLe, volRi: Word);
  var
    hWO: HWAVEOUT;
    waveF: TWAVEFORMATEX;
    vol: DWORD;
  begin
    FillChar(waveF, SizeOf(waveF), 0);
    waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0);
    vol := volLe + volRi shl 16;
    waveOutSetVolume(hWO, vol);
    waveOutClose(hWO);
  end;

procedure SetDeviceVolume(var volLe, volRi: Word);
  var vol: DWORD;
    huhu: Boolean;
  begin
    vol := volLe + volRi shl 16;
    huhu:=SetMasterVolume(vol);
  end;

end.


Ein Teil davon scheint aus dem Open Source-Projekt "SoundControl" von user profile iconSaubäär zu sein.
Vielleicht helfen Dir die beiden Themen und der Rest. Leider ist das zu lange her, als das ich mich an Details erinnern könnte.

Wenn ich mir die Variable "huhu" anschaue, scheint diese Procedure aus meiner Feder zu stammen.

Grüße,
Wonko

_________________
"Read the directions, even if you don't follow them.", Mary Schmich
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 04.06.08 13:41 
Das hilft leider gar nicht. :?

Die einzige Prozedur, bei der überhaupt etwas passiert, ist SetMasterVolume, aber die ändert nur die Gesamtlautstärke, ich brauch aber die für die einzelnen Lautsprecher.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Wonko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 69



BeitragVerfasst: Mi 04.06.08 13:56 
Da habe ich wohl aus "Lautsprecherlautstärke" auf "Lautstärke" geschlossen. Für mich halt naheliegend.
Was verstehst Du unter "einzelne Lautsprecher"? Willst Du die Balance ändern?, oder angestöpselte Lautsprecher anders regeln als eingebaute?...

_________________
"Read the directions, even if you don't follow them.", Mary Schmich
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 04.06.08 14:06 
Ich will die Lautstärkewerte für einzelne Lautsprecher ändern. Beim Win-Lautstärkeregelprogramm geht das über "Lautstärke..." beim genz linken Regler - siehe Anhang vom ersten Post.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.