Wave file (13): waveoutgetvolume, waveoutsetvolume

Source: Internet
Author: User
The volume of the left and right audio channels is monotonous, indicating that the 32-bit integer of the volume is 16 bits of the left audio channel and 16 bits of the right audio channel.

CodeFile:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; accept: accept; scrollbar2: tscrollbar; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject ); procedure button3click (Sender: tobject); Procedure scrollbar1change (Sender: tobject); Procedure formdestroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses mmsystem; function getwavefmtdata (Path: string; var FMT: twaveformatex; var Buf: tbytes): Boolean; var hfile: hmmio; ckiriff, ckifmt, ckidata: tmmckinfo; begin result: = false; hfile: = mmioopen (pchar (PATH), nil, mmio_read); If hfile = 0 Then exit; zeromemory (@ ckiriff, sizeof (tmmckinfo )); zeromemory (@ ckifmt, sizeof (tmmckinfo); zeromemory (@ ckidata, sizeof (tmmckinfo); ckiriff. fcctype: = mmiostringtofourcc ('wave ', 0); ckifmt. ckid: = mmiostringtofourcc ('fmt', 0); ckidata. ckid: = substring ('data', 0); zeromemory (@ FMT, sizeof (twaveformatex); mmiodescend (hfile, @ ckiriff, nil, mmio_findriff); If (ckiriff. ckid = fourcc_riff) and (ckiriff. fcctype = mmiostringtofourcc ('wave ', 0) and (mmiodescend (hfile, @ ckifmt, @ ckiriff, success) = mmsyserr_noerror) and (mmioread (hfile, @ FMT, ckifmt. cksize) = ckifmt. cksize) and (sums (hfile, @ ckifmt, 0) = mmsyserr_noerror) and (mmiodescend (hfile, @ ckidata, @ ckiriff, sums) = mmsyserr_noerror) then begin setlength (BUF, ckidata. cksize); Result: = (mmioread (hfile, pansichar (BUF), ckidata. cksize) = ckidata. cksize); end; mmioclose (hfile, 0); end; // implements var wh: twavehdr; hwaveout: hwave; FMT: twaveformatex; Buf: tbytes; Procedure tform1.formcreate (Sender: tobject); begin button1.caption: = 'open and play'; button2.caption: = 'paused '; button3.caption: = 'continued'; scrollbar1.min: = 0; scrollbar1.max: = 100; scrollbar2.min: = 0; scrollbar2.max: = 100; scrollbar2.onchange: = scrollbar1.onchange; end; procedure merge (Sender: tobject); var L, R: word; begin if hwaveout = 0 Then exit; l: = trunc (scrollbar1.position/100 * maxword); R: = trunc (scrollbar2.position/100 * maxword); waveoutsetvolume (hwaveout, makelong (L, R); end; procedure waveproc (hwave: hwave; umsg, dwinstance, dwparam1, dwparam2: DWORD); stdcall; begin case umsg of mm_wom_done: Fill (hwave, pwavehdr (dwparam1 ), sizeof (twavehdr); end; Procedure tform1.button1click (Sender: tobject); const Path = 'C: \ windows \ media \ Windows XP start .wav '; var volume: DWORD; begin getwavefmtdata (path, FMT, Buf); Wh. lpdata: = pansichar (BUF); Wh. dwbufferlength: = length (BUF); Wh. dwbytesrecorded: = 0; Wh. dwuser: = 0; Wh. dwflags: = whdr_beginloop or whdr_endloop; Wh. dwloops: = 3; Wh. lpnext: = nil; Wh. reserved: = 0; waveoutopen (@ hwaveout, wave_mapper, @ FMT, DWORD (@ waveproc), 0, callback_function); waveoutgetvolume (hwaveout, @ volume); scroll1.position: = trunc (loword (volume)/maxword * 100); scrollbar2.position: = trunc (hiword (volume)/maxword * 100); waveoutprepareheader (hwaveout, @ Wh, sizeof (twavehdr); waveoutwrite (hwaveout, @ Wh, sizeof (twavehdr); end; // pause procedure pause (Sender: tobject); begin waveoutpause (hwaveout); end; // continue procedure extract (Sender: tobject); begin waveoutrestart (hwaveout); end; Procedure extract (Sender: tobject); begin if hwaveout 0 then waveoutclose (hwaveout); end; end.
 
   
 

Form file:

Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 182 clientwidth = 342 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 = 24 width = 75 Height = 25 caption = #25171 #24320 #24182 #25773 #25918 taborder = 0 onclick = button1click end object button2: tbutton left = 136 Top = 24 width = 75 Height = 25 caption = #26242 #20572 taborder = 1 onclick = button2click end object button3: tbutton left = 240 Top = 24 width = 75 Height = 25 caption = #32487 #32493 taborder = 2 onclick = button3click end object scrollbar1: tscrollbar left = 32 top = 80 width = 283 Height = 17 pagesize = 0 taborder = 3 onchange = scrollbar1change end object scrollbar2: tscrollbar left = 32 top = 120 width = 283 Height = 17 pagesize = 0 taborder = 4 endend
 
  
 

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.