德尔福将音频路由到特定频道

时间:2015-06-09 21:42:14

标签: delphi

我想知道音频是否可以路由到特定频道(仅限左侧或右侧)

我有这段代码,当然,在这种情况下,音频会被路由到两个频道。

//------------------------------------------------------------------------------
//                               system
//------------------------------------------------------------------------------
constructor TCustomSoundInOut.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  SetBufCount(DEFAULTBUFCOUNT);

  FDeviceID := WAVE_MAPPER;

  //init WaveFmt
  with WaveFmt do
    begin
    wf.wFormatTag := WAVE_FORMAT_PCM;
    wf.nChannels := 1;             //mono
    wf.nBlockAlign := 2;           //SizeOf(SmallInt) * nChannels;
    wBitsPerSample := 16;          //SizeOf(SmallInt) * 8;
    end;

  //fill nSamplesPerSec, nAvgBytesPerSec in WaveFmt
  SamplesPerSec := 48000;
end;


destructor TCustomSoundInOut.Destroy;
begin
  Enabled := false;
  inherited;
end;


procedure TCustomSoundInOut.Err(Txt: string);
begin
  raise ESoundError.Create(Txt);
end;

1 个答案:

答案 0 :(得分:0)

Windows Vista或更高版本

您应该使用Core Audio SDK中的IAudioEndpointVolume界面,更具体地说是IAudioEndpointVolume.SetChannelVolumeLevel()方法:

function SetChannelVolumeLevel(nChannel: uint; fLevelDB: double; pguidEventContext: PGUID): HRESULT; stdcall;

请参阅此处的文档: https://msdn.microsoft.com/fr-fr/library/windows/desktop/dd368053%28v=vs.85%29.aspx

Vista之前

如果您使用“旧”MMSystem API,则MSDN doc中也会给出答案:

MMRESULT waveOutSetVolume(
  HWAVEOUT hwo, 
  DWORD dwVolume 
); 
  

参数

     

hwo

     

处理开放式波形音频输出设备。此参数也可以是设备标识符。

     

dwVolume

     

指定新的音量设置。低位字包含左声道音量设置,高阶字包含   右声道设置。值0xFFFF表示已满   音量,值0x0000是静音。

https://msdn.microsoft.com/en-us/library/aa908146.aspx

相关问题