Use directsound (15) in Delphi: test the reverb effect idirectsoundfxwavesreverb8

Source: Internet
Author: User
{Related structure:} tdsfxwavesreverb = packed record fingain: single; //-96 .. 0: 0.0 (db) freverbmix: single; //-96 .. 0: 0.0 (db) freverbtime: single; // 0.001 .. 3000: 1000.0 (MS) fhighfreqrtratio: single; // 0.001 .. 0.999: 0.001end; // The structure constant dsfx_wavesreverb_ingain_min =-96.0; cost = 0.0; dsfx_wavesreverb_ingain_default = 0.0; cost =-96.0; cost = 0.0; cost = 0.0; cost =; dsfx_wavesreverb_reverbtime_min = 0.001; dsfx_wavesreverb_reverbtime_max = 3000.0; dsfx_wavesreverb_reverbtime_default = 1000.0; token = 0.001; token = 0.999; token = 0.001;
Test Code :
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; identifier: identifier; labelededit4: identifier; 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 is the preceding (9) custom unit var mydsound: idirectsound8; buf8: idirectsoundbuffer8; fxwavesreverb: idirectsoundfxwavesreverb8; // idirectsoundfxwavesreverb8 Effect Generator procedure tform1.formcreate (Sender: tobject); begin system. reportmemoryleaksonshutdown: = true; directsoundcreate8 (nil, mydsound, nil); mydsound. setcooperativelevel (handle, dsscl_normal); button1.caption: = 'open and play'; button2.caption: = 'Stop play'; labelededit1.editlabel. caption: = 'fingain:-96.0-0.0 '; labelededit1.text: = '0. 0'; labelededit1.tag: = 1; labelededit2.editlabel. caption: = 'freverbmix:-96.0-0.0 '; labelededit2.text: = '0. 0'; labelededit2.tag: = 2; labelededit3.editlabel. caption: = 'freverbtime: 0.001-3000 '; labelededit3.text: = '2017. 0'; labelededit3.tag: = 3; labelededit4.editlabel. caption: = 'fhighfreqrtratio: 0.001-0.999 '; labelededit4.text: = '0. 001 '; labelededit4.tag: = 4; tags: = tags; labelededit4.onchange: = labelededit1.onchange; end; Procedure identifier (Sender: tobject); var Buf: signature; 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: = signature; buf8.setfx (1, @ reffect, nil); buf8.getobjectinpath (signature, 0, signature, fxwavesreverb); buf8.play (0, 0, dsbplay_looping); end; procedure merge (Sender: tobject); begin if assigned (buf8) Then buf8.stop; end; procedure merge (Sender: tobject); var rwavesreverb: substring; F: single; OBJ: tlabelededit; begin OBJ: = sender as tlabelededit; If obj. TEXT = '-' Then exit; F: = strtofloatdef (obj. text, maxint); Case obj. tag of 1, 2: If (F 0) Then obj. text: = '0. 0 '; 3: If (F 3000) Then obj. text: = '100. 0'; 4: If (F 0.999) Then obj. text: = '0. 001'; end; If buf8 = nil then exit; rwavesreverb. fingain: = strtofloat (labelededit1.text); rwavesreverb. freverbmix: = strtofloat (labelededit2.text); rwavesreverb. freverbtime: = strtofloat (labelededit3.text); rwavesreverb. fhighfreqrtratio: = strtofloat (labelededit4.text); fxwavesreverb. setallparameters (rwavesreverb); end; Procedure tform1.formdestroy (Sender: tobject); begin buf8: = nil; mydsound: = nil; end.
Form Design:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 205 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 endend
Run:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.