文档章节

在 Delphi 下使用 DirectSound (12): 测试失真效果器 IDirectSoundFXDistortion8

涂孟超
 涂孟超
发布于 2014/09/26 15:36
字数 695
阅读 10
收藏 0

{相关结构:}
TDSFXDistortion = packed record
  fGain: Sinle;                  //-60 .. 0    : -18  (dB) //好像默认值不是 -18
  fEdge: Single;                  //  0 .. 100  : 15   (%)
  fPostEQCenterFrequency: Single; //100 .. 8000 : 2400 (Hz)
  fPostEQBandwidth: Single;       //100 .. 8000 : 2400 (Hz)
  fPreLowpassCutoff: Single;      //100 .. 8000 : 800  (Hz)
end;

//该结构相关常量:
DSFXDISTORTION_GAIN_MIN                  = -60.0;
DSFXDISTORTION_GAIN_MAX                  = 0.0;

DSFXDISTORTION_EDGE_MIN                  = 0.0;
DSFXDISTORTION_EDGE_MAX                  = 100.0;

DSFXDISTORTION_POSTEQCENTERFREQUENCY_MIN = 100.0;
DSFXDISTORTION_POSTEQCENTERFREQUENCY_MAX = 8000.0;

DSFXDISTORTION_POSTEQBANDWIDTH_MIN       = 100.0;
DSFXDISTORTION_POSTEQBANDWIDTH_MAX       = 8000.0;

DSFXDISTORTION_PRELOWPASSCUTOFF_MIN      = 100.0;
DSFXDISTORTION_PRELOWPASSCUTOFF_MAX      = 8000.0;


测试代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    LabeledEdit5: TLabeledEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure LabeledEdit1Change(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses DirectSound, ReadWave2; //ReadWave2 是前面(9)自定义的单元

var
  myDSound: IDirectSound8;
  buf8: IDirectSoundBuffer8;
  fxDistortion: IDirectSoundFXDistortion8; //IDirectSoundFXDistortion8 效果器

procedure TForm1.FormCreate(Sender: TObject);
begin
  System.ReportMemoryLeaksOnShutdown := True;
  DirectSoundCreate8(nil, myDSound, nil);
  myDSound.SetCooperativeLevel(Handle, DSSCL_NORMAL);

  Button1.Caption := '打开并播放';
  Button2.Caption := '停止播放';

  LabeledEdit1.EditLabel.Caption := 'fGain: -60 - 0';
  LabeledEdit1.Text := '-18.0';
  LabeledEdit1.Tag := 1;

  LabeledEdit2.EditLabel.Caption := 'fEdge: 0 - 100';
  LabeledEdit2.Text := '15.0';
  LabeledEdit2.Tag := 2;

  LabeledEdit3.EditLabel.Caption := 'fPostEQCenterFrequency: 100 - 8000';
  LabeledEdit3.Text := '2400.0';
  LabeledEdit3.Tag := 3;

  LabeledEdit4.EditLabel.Caption := 'fPostEQBandwidth: 100 - 8000';
  LabeledEdit4.Text := '2400.0';
  LabeledEdit4.Tag := 4;

  LabeledEdit5.EditLabel.Caption := 'fPreLowpassCutoff: 100 - 8000';
  LabeledEdit5.Text := '800.0';
  LabeledEdit5.Tag := 5;

  LabeledEdit2.OnChange := LabeledEdit1.OnChange;
  LabeledEdit3.OnChange := LabeledEdit1.OnChange;
  LabeledEdit4.OnChange := LabeledEdit1.OnChange;
  LabeledEdit5.OnChange := LabeledEdit1.OnChange;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  buf: IDirectSoundBuffer;
  bufDesc: TDSBufferDesc;
  rEffect: TDSEffectDesc;
  wav: TReadWave;
  p1: Pointer;
  n1: DWORD;
begin
  wav := TReadWave.Create;
  if not wav.OpenDialog then begin wav.Free; Exit; end;

  ZeroMemory(@bufDesc, SizeOf(TDSBufferDesc));
  bufDesc.dwSize := SizeOf(TDSBufferDesc);
  bufDesc.dwFlags := DSBCAPS_CTRLFX;
  bufDesc.dwBufferBytes := wav.Size;
  bufDesc.lpwfxFormat := @wav.Format;
  myDSound.CreateSoundBuffer(bufDesc, buf, nil);
  buf.QueryInterface(IID_IDirectSoundBuffer8, buf8);

  buf8.Lock(0, 0, @p1, @n1, nil, nil, DSBLOCK_ENTIREBUFFER);
  wav.Read(p1, n1);
  wav.Free;
  buf8.Unlock(p1, n1, nil, 0);

  ZeroMemory(@rEffect, SizeOf(TDSEffectDesc));
  rEffect.dwSize := SizeOf(TDSEffectDesc);
  rEffect.dwFlags := 0;
  rEffect.guidDSFXClass := GUID_DSFX_STANDARD_DISTORTION;
  buf8.SetFX(1, @rEffect, nil);
  buf8.GetObjectInPath(GUID_DSFX_STANDARD_DISTORTION, 0, IID_IDirectSoundFXDistortion8, fxDistortion);
  buf8.Play(0, 0, DSBPLAY_LOOPING);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if Assigned(buf8) then buf8.Stop;
end;

procedure TForm1.LabeledEdit1Change(Sender: TObject);
var
  rDistortion: TDSFXDistortion;
  f: Single;
  obj: TLabeledEdit;
begin
  obj := Sender as TLabeledEdit;
  if obj.Text = '-' then Exit;

  f := StrToFloatDef(obj.Text, MaxInt);
  case obj.Tag of
    1: if (f < -60)  or (f > 0)   then obj.Text := '-18.0';
    2: if (f < 0) or (f > 100)  then obj.Text := '15.0';
    3: if (f < 100) then Exit else if (f > 8000) then obj.Text := '2400.0';
    4: if (f < 100) then Exit else if (f > 8000) then obj.Text := '2400.0';
    5: if (f < 100) then Exit else if (f > 8000) then obj.Text := '800.0';
  end;

  if buf8 = nil then Exit;
  rDistortion.fGain                  := StrToFloat(LabeledEdit1.Text);
  rDistortion.fEdge                  := StrToFloat(LabeledEdit2.Text);
  rDistortion.fPostEQCenterFrequency := StrToFloat(LabeledEdit3.Text);
  rDistortion.fPostEQBandwidth       := StrToFloat(LabeledEdit4.Text);
  rDistortion.fPreLowpassCutoff      := StrToFloat(LabeledEdit5.Text);
  fxDistortion.SetAllParameters(rDistortion);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  buf8 := nil;
  myDSound := nil;
end;

end.


窗体设计:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 253
  ClientWidth = 363
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 32
    Top = 28
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 32
    Top = 75
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
    OnClick = Button2Click
  end
  object LabeledEdit1: TLabeledEdit
    Left = 144
    Top = 30
    Width = 193
    Height = 21
    EditLabel.Width = 61
    EditLabel.Height = 13
    EditLabel.Caption = 'LabeledEdit1'
    TabOrder = 2
    OnChange = LabeledEdit1Change
  end
  object LabeledEdit2: TLabeledEdit
    Left = 144
    Top = 77
    Width = 193
    Height = 21
    EditLabel.Width = 61
    EditLabel.Height = 13
    EditLabel.Caption = 'LabeledEdit2'
    TabOrder = 3
  end
  object LabeledEdit3: TLabeledEdit
    Left = 144
    Top = 125
    Width = 193
    Height = 21
    EditLabel.Width = 61
    EditLabel.Height = 13
    EditLabel.Caption = 'LabeledEdit3'
    TabOrder = 4
  end
  object LabeledEdit4: TLabeledEdit
    Left = 144
    Top = 173
    Width = 193
    Height = 21
    EditLabel.Width = 61
    EditLabel.Height = 13
    EditLabel.Caption = 'LabeledEdit4'
    TabOrder = 5
  end
  object LabeledEdit5: TLabeledEdit
    Left = 144
    Top = 221
    Width = 193
    Height = 21
    EditLabel.Width = 61
    EditLabel.Height = 13
    EditLabel.Caption = 'LabeledEdit5'
    TabOrder = 6
  end
end


运行效果图:


本文转载自:http://www.cnblogs.com/del/archive/2011/01/23/1942709.html

共有 人打赏支持
涂孟超
粉丝 12
博文 2011
码字总数 14107
作品 0
深圳
程序员
效果器及音响相关术语解释

cable:连线,过线,以上是常规的翻译,意思就是连接一个输出到另一个输入,但根据信号的不同,cable分的很细的种类. instrument cable:乐器线,在电声领域特指高阻抗低电流的信号过线,必须有完善的...

v289
2017/05/29
0
0
DirectSound入门

文档内容: (费话篇) 关于DirectSound DirectSound是DirectX API的音频(waveaudio)组件之一,它可以提供快速的混音、硬件加速功能,并且可以直接访问相关设备,当然,最主要的是它提供的...

长平狐
2012/08/13
824
0
golang语言中的math库中效率低下,可能是类型转换花费了大量时间?

今天写了个加密的东西,用到了math.Sqrt求质数,发现用的时间很久,先不管下面的例子算法是否有问题,我就写了个demo寻找10 000 000以内的质数个数,原本这个demo是delphi写的,我把它翻译成...

大洋的顶端
2017/10/26
0
14
使用three.js的着色器通道渲染地球模型

我们都知道,three.js库里面内置了很多着色器通道对象供我们渲染场景,本文将对EffectComposer、RenderPass、FilmPass这三个通道进行学习和实现: 1.RenderPass这个通道会在当前场景(scene...

qq_37338983
05/12
0
0
SDL2源代码分析1:初始化(SDL_Init())

===================================================== SDL源代码分析系列文章列表: SDL2源代码分析1:初始化(SDLInit()) SDL2源代码分析2:窗口(SDLWindow) SDL2源代码分析3:渲染器...

leixiaohua1020
2014/11/01
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

c语言之内存分配笔记

先看一个数组: short array[5] = {1,2} // 这儿定义的一个int类型的数组,数组第1和第2个元素值是1和2.其余后面默认会给值为0; 或者 short array[] = {1,2};//这儿数组第1和第2个元素,数组...

DannyCoder
今天
2
0
Shell | linux安装包不用选择Y/N的方法

apt-get install -y packageOR echo "y" | sudo apt-get install package

云迹
今天
2
0
Hadoop的大数据生态圈

基于Hadoop的大数据的产品圈 大数据产品的一句话概括 Apache Hadoop: 是Apache开源组织的一个分布式计算开源框架,提供了一个分布式文件系统子项目(HDFS)和支持MapReduce分布式计算的软件架...

zimingforever
今天
5
0
八大包装类型的equals方法

先看其中一个源码 结论:八大包装类型的equals方法都是先判断类型是否相同,不相同则是false,相同则判断值是否相等 注意:包装类型不能直接用==来等值比较,否则编译报错,但是数值的基本类型...

xuklc
今天
2
0
NoSQL , Memcached介绍

什么是NoSQL 非关系型数据库就是NoSQL,关系型数据库代表MySQL 对于关系型数据库来说,是需要把数据存储到库、表、行、字段里,查询的时候根据条件一行一行地去匹配,当量非常大的时候就很耗...

TaoXu
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部