Guten Abend zusammen.
Ich benutze für meine Art von VU Meter die Audio IO Recource.
Möchte jetzt mal wissen, was ich alles aus der Audio IO so alles auslesen kann.
Denke da an so einen Equalizer ala Winamp, mit den verschiedenen Balken.
Bisher funktioniert es schon ganz gut. Habe für das Hauptprogramm auch die Master Sound werte.
Für mehr INfos wären halt mehr Werte sinnvoll.
Danke schonmal für eure Hilfe.
MfG
S4SH
[code=delphi]
type
TSample = record
Left : SmallInt;
Right : SmallInt;
end;
const
MasterVolumeControl = 0;
MaxVolume = 65535;
MinVolume = 0; //
function _VolumeControl(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;
procedure SetMasterVolume(Mixer: hMixerObj; Value: Word);
var
MasterVolume : TMixerControl;
Details : TMixerControlDetails;
UnsignedDetails : TMixerControlDetailsUnsigned;
Code : MMResult;
begin
Code := _VolumeControl(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;
Code := mixerSetControlDetails(Mixer,
@Details,
MIXER_SETCONTROLDETAILSF_VALUE);
end;
if Code <> MMSYSERR_NOERROR then
raise
Exception.CreateFmt('SetMasterVolume failure, '+
'multimedia system error #%d', [Code]);
end;
function GetMasterVolume(Mixer: hMixerObj): Word;
var
MasterVolume : TMixerControl;
Details : TMixerControlDetails;
UnsignedDetails : TMixerControlDetailsUnsigned;
Code : MMResult;
begin
Result := 0;
Code := _VolumeControl(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;
Code := mixerGetControlDetails(Mixer,
@Details,
MIXER_GETCONTROLDETAILSF_VALUE);
Result := UnsignedDetails.dwValue;
end;
if Code <> MMSYSERR_NOERROR then
raise
Exception.CreateFmt('GetMasterVolume failure, '+
'multimedia system error #%d',
Code:
);
end;
function TForm1.AudioInBufferFilled(Buffer: PChar; var Size: Integer): Boolean;
var
SampleData : ^Cardinal;
I : Integer;
Current : TSample;
PeakL : Integer;
PeakR : Integer;
LowL : Integer;
LowR : Integer;
begin
SampleData := Pointer(Buffer);
PeakL := 0;
PeakR := 0;
LowL := 0;
LowR := 0;
for I := 0 to (Size div sizeof(Integer)) - 1 do
begin
Current := TSample(SampleData^);
Inc(SampleData);
if (Current.Left > PeakL) then
PeakL := Current.Left;
if (Current.Left < LowL) then
LowL := Current.Left;
if (Current.Right > PeakR) then
PeakR := Current.Right;
if (Current.Right < LowR) then
LowR := Current.Right;
end;
PrevLPeak := (PeakL - LowL) div 2;
PrevRPeak := (PeakR - LowR) div 2;
LeftPeak := (PrevLPeak + LeftPeak) div 2;
RightPeak := (PrevRPeak + RightPeak) div 2;
VuMeter.LeftPos := LeftPeak;
VuMeter.RightPos := RightPeak;
Result := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
VuMeter := TVuMeter.Create(Self);
AudioIn := TAudioIn.Create(Self);
with AudioIn do
begin
Stereo := true;
BufferSize := 4098;
FrameRate := 22500;
NumBuffers := 2;
Quantization := 16;
OnBufferFilled := AudioInBufferFilled;
Start(AudioIn);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AudioIn.StopAtOnce;
end;