[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

ntu-kpi.comp.programming

[?] Sound Analizer in Delphi

Yurik

4/12/2005 9:47:00 AM

èÏÞÕ ÎÁÐÉÓÁÔØ "ÄÒÁÊ×ÅÒ" ÐÏÄ ÔÁËÏÊ ÄÅ×ÁÊÓ, ËÁË Ã×ÅÔÏÍÕÚÙËÁ (ÓÏÂÓÔ×ÅÎÎÏÇÏ
ÉÚÇÏÔÏ×ÌÅÎÉÑ :).
ôÁË ×ÏÔ, ÂÌÉÖÅ Ë ÄÅÌÕ. ëÁË ÒÅÁÌÉÚÏ×ÁÔØ ÁÎÁÌÉÚÁÔÏÒ Ú×ÕËÁ, ËÏÔÏÒÙÊ ÉÄÅÔ ÎÁ
Ú×ÕËÏ×ÕÈÕ ÐÏÄ íÁÓÔäÁÊ.

3 Answers

Yurik

4/12/2005 10:39:00 AM

0

îÁÛÅÌ ÏÄÉÎ ËÏÄ, ÎÏ ÏÎ Õ ÍÅÎÑ ÐÏÞÅÍÕÔÏ (ÔÏÌÉ ÏÛÉÂËÁ × ËÏÄÅ, ÔÏÌÉ Ú×ÕËÏ×ÕÈÁ
ÅÂ@ÎÕÔÁÑ) ÎÅ ÒÁÂÏÔÁÅÔ :(
íÏÖÅÔ Õ ËÏÇÏ ÚÁÒÁÂÏÔÁÅÔ, Ó×ÉÓÎÉÔÅ

{
Every line going into and out of the mixer has a number of "controls"
associated with it. Some of those controls are "meters," which give
you a real-time value of the sound level on the corresponding line.
Not all lines have meter controls, and not all sound cards provide
support for meters.

Here's some code that will retrieve a handle to the meter attached to
the WaveOut source of the speaker line, if there is one:
}

uses
MMSystem;

procedure TForm1.Button1Click(Sender: TObject);
var
MixerControl: TMixerControl;
MixerControlDetails: TMixerControlDetails;
MixerControlDetailsSigned: TMixerControlDetailsSigned;
Mixer: THandle;
MixerLine: TMixerLine;
MixerLineControls: TMixerLineControls;
PeakMeter: DWORD;
Rslt: DWORD;
SourceCount: Cardinal;
WaveOut: DWORD;
I: Integer;
X: Integer;
Y: Integer;
begin
Rslt := mixerOpen(@Mixer, 0, 0, 0, 0);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t open mixer (%d)', [Rslt]);
FillChar(MixerLine, SizeOf(MixerLine), 0);
MixerLine.cbStruct := SizeOf(MixerLine);
MixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
Rslt := mixerGetLineInfo(Mixer, @MixerLine,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t find speaker line (%d)', [Rslt]);
SourceCount := MixerLine.cConnections;
WaveOut := $FFFFFFFF;
for I := 0 to SourceCount - 1 do
begin
MixerLine.dwSource := I;
Rslt := mixerGetLineInfo(Mixer, @MixerLine,
MIXER_GETLINEINFOF_SOURCE);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t get source line (%d)', [Rslt]);
if MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT then
begin
WaveOut := MixerLine.dwLineId;
Break;
end;
end;
if WaveOut = $FFFFFFFF then
raise Exception.Create('Can''t find wave out device');
FillChar(MixerLineControls, SizeOf(MixerLineControls), 0);
with MixerLineControls do
begin
cbStruct := SizeOf(MixerLineControls);
dwLineId := WaveOut;
dwControlType := MIXERCONTROL_CONTROLTYPE_PEAKMETER;
cControls := 1;
cbmxctrl := SizeOf(TMixerControl);
pamxctrl := @MixerControl;
end;
Rslt := mixerGetLineControls(Mixer, @MixerLineControls,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t find peak meter control (%d)',
[Rslt]);
PeakMeter := MixerControl.dwControlID;

// at this point, I have the meter control ID, so I can
// repeatedly query its value and plot the resulting data
// on a canvas

X := 0;
FillChar(MixerControlDetails, SizeOf(MixerControlDetails), 0);
with MixerControlDetails do
begin
cbStruct := SizeOf(MixerControlDetails);
dwControlId := PeakMeter;
cChannels := 1;
cbDetails := SizeOf(MixerControlDetailsSigned);
paDetails := @MixerControlDetailsSigned;
end;
repeat
Sleep(10);
Rslt := mixerGetControlDetails(Mixer, @MixerControlDetails,
MIXER_GETCONTROLDETAILSF_VALUE);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t get control details (%d)',
[Rslt]);
Application.ProcessMessages;
Inc(X);
Y := 300 - Round(300 * Abs(MixerControlDetailsSigned.lValue) / 32768);
with Canvas do
begin
MoveTo(X, 0);
Pen.Color := clBtnFace;
LineTo(X, 300);
Pen.Color := clWindowText;
LineTo(X, Y);
end;
until X > 500;

Rslt := mixerClose(Mixer);
if Rslt <> 0 then
raise Exception.CreateFmt('Can''t close mixer (%d)', [Rslt]);
end;

Yurik

4/12/2005 10:53:00 AM

0

õÖÅ ÎÁÛÅÌ!
ëÏÍÕ ÉÎÔÅÒÅÓÔÎÏ, ×ÏÔ ÌÉÎË:
ftp://armagedon.its.ntu-kpi.kiev.ua/Incoming/oscil...

Moderator

4/12/2005 6:22:00 PM

0


Tue, 12 Apr 2005 10:39:26 +0000 (UTC)
"Yurik" <yurik@its.ntu-kpi.kiev.ua>

uAIA?AIEA [*] -- IAOU.


* On Tue, 12 Apr 2005 10:39:26 +0000 (UTC) you wrote:

> iAUAI IAEI EIA, II II O IAIN ?I?AIOOI (OIIE IUEAEA ? EIAA, OIIE U?OEI?OEA
> AA@IOOAN) IA OAAIOAAO :(
> iIOAO O EICI UAOAAIOAAO, O?EOIEOA

...skip..

--
With Respect, ICQ# 34006064 ftp://reali...
Yuriy [haze at reality.org.ua] [Ahraywah Ohmankogah Skeeda]

np: 11. The Flower Kings - [Retropolis] - The Road Back Home [08:57] [stopped]