윈도우즈에서 소리 출력 제어
CoInitialize(NULL);
IMMDeviceEnumerator *pEnum = NULL;
IMMDevice *pDevice = NULL;
IAudioMeterInformation *pMeter = NULL;
float peak;
HRESULT hr;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMMDeviceEnumerator),
(void**)&pEnum);
hr = pEnum -> GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
pDevice -> Activate(__uuidof(IAudioMeterInformation),
CLSCTX_ALL,
NULL,
(void**)&pMeter);
pMeter -> GetPeakValue(&peak); // I need this value
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.ActiveX, System.Win.ComObj, MMSystem,
Vcl.ComCtrls, Vcl.ExtCtrls;
type
EDATAFLOW = TOleEnum;
EROLE = TOleEnum;
IMMDevice = interface(IUnknown)
['{D666063F-1587-4E43-81F1-B948E807363F}']
function Activate(const iid: TGUID; const dwClsCtx: UINT; const pActivationParams: PPropVariant; out ppInterface: IUnknown)
: HRESULT; stdcall;
end;
IMMDeviceCollection = interface(IUnknown)
['{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}']
end;
IMMDeviceEnumerator = interface(IUnknown)
['{A95664D2-9614-4F35-A746-DE8DB63617E6}']
function EnumAudioEndpoints(const dataFlow: EDATAFLOW; const dwStateMask: DWORD; out ppDevices: IMMDeviceCollection): HRESULT; stdcall;
function GetDefaultAudioEndpoint(const dataFlow: EDATAFLOW; const role: EROLE; out ppEndpoint: IMMDevice): HRESULT; stdcall;
end;
IAudioMeterInformation = interface(IUnknown)
['{C02216F6-8C67-4B5B-9D00-D008E73E0064}']
function GetPeakValue(out pfPeak: Single): HRESULT; stdcall;
function GetMeteringChannelCount(out pnChannelCount: UINT): HRESULT; stdcall;
function GetChannelsPeakValues(u32ChannelCount: UINT; out afPeakValues: pSingle): HRESULT; stdcall;
function QueryHardwareSupport(out pdwHardwareSupportMask: UINT): HRESULT; stdcall;
end;
TForm1 = class(TForm)
ProgressBar1: TProgressBar;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
IID_IMMDeviceEnumerator: TGUID = '{A95664D2-9614-4F35-A746-DE8DB63617E6}';
CLASS_IMMDeviceEnumerator: TGUID = '{BCDE0395-E52F-467C-8E3D-C4579291692E}';
IID_IAudioMeterInformation: TGUID = '{C02216F6-8C67-4B5B-9D00-D008E73E0064}';
eRender = $00000000;
eConsole = $00000000;
var
Form1: TForm1;
peak: IAudioMeterInformation = nil;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
device: IMMDevice;
deviceEnumerator: IMMDeviceEnumerator;
begin
Timer1.Enabled := False;
ProgressBar1.Max := 65535;
CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, deviceEnumerator);
deviceEnumerator.GetDefaultAudioEndpoint(eRender, eConsole, device);
device.Activate(IID_IAudioMeterInformation, CLSCTX_ALL, nil, IUnknown(peak));
Timer1.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
Temp: Single;
begin
peak.GetPeakValue(Temp);
ProgressBar1.position := Round(Temp * 65535);
end;
end.
UsingAudioVolumeControlApi.pas
(*
Category: SWAG Title: Borland DELPHI
Original name: 0424.PAS
Description: Using Audio Volume Control API
Author: SWAG SUPPORT TEAM
Date: 01-02-98 07:34
*)
//
unit WaveUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, MMSystem, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
NumDevs : Integer;
waveCaps : TWaveOutCaps;
Volume : DWORD;
Left, Right : Word;
Version : Word;
begin
// We should have at least one device
NumDevs := waveOutGetNumDevs;
Edit1.Text := Format('Number of devices is %d', [NumDevs]);
// for the 1st device (hard-coded)
// Get Device Caps
waveOutGetDevCaps(0, @waveCaps, SizeOf(waveCaps));
// Show device caps
Memo1.Lines.Add('IατΓαφΦσ: '+waveCaps.szPName);
Version := waveCaps.vDriverVersion;
Memo1.Lines.Add(Format('Aσd±Φ ΣdαΘΓσdα: %d.%d', [Hi(Version), Lo(Version)]));
Case waveCaps.wChannels of
1 : Memo1.Lines.Add('Iεφε');
2 : Memo1.Lines.Add('╤≥σdσε');
End;
// Standard formats
If waveCaps.dwFormats AND WAVE_FORMAT_1M08 <> 0 Then
Memo1.Lines.Add('11.025 kHz, mono, 8-bit');
If waveCaps.dwFormats AND WAVE_FORMAT_1M16 <> 0 Then
Memo1.Lines.Add('11.025 kHz, mono, 16-bit');
{
WAVE_FORMAT_1S08 11.025 kHz, stereo, 8-bit
WAVE_FORMAT_1S16 11.025 kHz, stereo, 16-bit
WAVE_FORMAT_2M08 22.05 kHz, mono, 8-bit
WAVE_FORMAT_2M16 22.05 kHz, mono, 16-bit
WAVE_FORMAT_2S08 22.05 kHz, stereo, 8-bit
WAVE_FORMAT_2S16 22.05 kHz, stereo, 16-bit
WAVE_FORMAT_4M08 44.1 kHz, mono, 8-bit
WAVE_FORMAT_4M16 44.1 kHz, mono, 16-bit
WAVE_FORMAT_4S08 44.1 kHz, stereo, 8-bit
WAVE_FORMAT_4S16 44.1 kHz, stereo, 16-bit
}
// If Volume Control Supported
If waveCaps.dwSupport AND WAVECAPS_VOLUME <> 0 Then
Begin
waveOutGetVolume(0, @Volume);
Left := LoWord(Volume);
Right := HiWord(Volume);
// Show values of WAVE Device on volume control panel
Edit2.Text := Format('Left : %d, Right : %d', [Left, Right]);
waveOutSetVolume(0, $40008000);
End;
end;
end.
links
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.