为什么读出来的是0?(10分)

  • 主题发起人 主题发起人 abcxca
  • 开始时间 开始时间
A

abcxca

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp;v:longint;<br>begin<br>&nbsp; waveoutgetvolume(0,@v);<br>end;<br><br><br>在 win xp下读出来的v 是0值? 谁知道为什么?<br>
 
可能应该在FormShow事件中。
 
&nbsp;这没有区别吧,试过在FormShow事件中,结果是一样的.
 
waveoutgetvolume(0,v)试试<br>这个不管放在哪儿调用都是一样的!
 
&nbsp;用waveoutgetvolume(0,v),编译报错.<br>&nbsp; Incompatible types: 'Integer' and 'PDWORD'<br>&nbsp;
 
那你就把“ v ”定义成" DWORD "。
 
代码:
<br>&nbsp; WTWaveOut=class(TObject)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; hWaveOut:HWAVEOUT;<br>&nbsp; &nbsp; wfex:tWAVEFORMATEX;<br>&nbsp; &nbsp; isInited:Boolean;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure Play(buf:LPCTSTR;size:DWORD);<br>&nbsp; published<br>&nbsp; &nbsp; { published declarations }<br>&nbsp; &nbsp; property wFormatTag:Word read wfex.wFormatTag default 1;<br>&nbsp; &nbsp; property nChannels:Word read wfex.nChannels default 1;<br>&nbsp; &nbsp; property nSamplesPerSec:Cardinal read wfex.nSamplesPerSec default 8000;<br>&nbsp; &nbsp; property wBitsPerSample:Word read wfex.wBitsPerSample default 8;<br>&nbsp; &nbsp; property nAvgBytesPerSec:Cardinal read wfex.nAvgBytesPerSec default 0;<br>&nbsp; &nbsp; property nBlockAlign:Word read wfex.nBlockAlign default 0; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; Constructor Create(channels,freq,bits:Int64;wFormat:Word;hWnd:HWND);<br>&nbsp; &nbsp; destructor Destroy;<br>&nbsp; end;<br><br>{WTWaveOut}<br><br>Constructor WTWaveOut.Create(channels,freq,bits:Int64;wFormat:Word;hWnd:HWND);<br>var<br>&nbsp; res:MMRESULT;<br>begin<br>&nbsp; isInited:=True;<br>// &nbsp;wfex.cbSize:=sizeof(tWAVEFORMATEX);<br>&nbsp; wfex.cbSize:=32;<br>&nbsp; wfex.wFormatTag := wFormat ;<br>&nbsp; wfex.nChannels := channels;<br>&nbsp; wfex.nSamplesPerSec := freq;<br>&nbsp; wfex.wBitsPerSample := bits;<br>&nbsp; wfex.nBlockAlign := wfex.nChannels * (wfex.wBitsPerSample div 8);<br>&nbsp; wfex.nAvgBytesPerSec := wfex.nSamplesPerSec * wfex.nBlockAlign;<br><br>&nbsp; res := waveOutOpen(@hWaveOut,<br>&nbsp; &nbsp; WAVE_MAPPER, @wfex, DWORD(hWnd), 0, CALLBACK_WINDOW);<br>&nbsp; if (res&lt;&gt;MMSYSERR_NOERROR) then<br>&nbsp; begin<br>&nbsp; &nbsp; isInited:=False;<br>// &nbsp; &nbsp;self.Free;<br>// &nbsp; &nbsp;self:=nil;<br>&nbsp; end;<br>end;<br><br>destructor WTWaveOut.Destroy;<br>begin<br>&nbsp; isInited:=False;<br>&nbsp; waveOutReset(hWaveOut);<br>&nbsp; waveOutClose(hWaveOut);<br>&nbsp; hWaveOut := 0;<br>end;<br><br>procedure WTWaveOut.Play(buf:LPCTSTR;size:DWORD);<br>var<br>&nbsp; pwh:PWaveHdr;<br>begin<br>&nbsp; if isInited then<br>&nbsp; begin<br>&nbsp; &nbsp; pwh:=GetMemory(sizeof(WAVEHDR));<br>&nbsp; &nbsp; pwh.dwFlags:=0;<br>&nbsp; &nbsp; pwh.dwBufferLength:=size;<br>&nbsp; &nbsp; pwh.lpData:=GetMemory(size);<br>// &nbsp; &nbsp;FillMemory(pwh.lpData,size,0);<br>&nbsp; &nbsp; CopyMemory(pwh.lpData,buf,size);<br>&nbsp; &nbsp; waveOutPrepareHeader(hWaveOut, pwh, sizeof(WAVEHDR));<br>&nbsp; &nbsp; waveOutWrite(hWaveOut, pwh, sizeof(WAVEHDR));<br>&nbsp; end;<br>end;<br>
<br>利用以上示例,你只需“<br>&nbsp; waveoutgetvolume(hWaveOut,@v);<br>”
 
调用waveoutgetvolume(hWaveOut,@v);<br>时出错,提示: '(' expected but ',' found
 
那是语法错误,可能是“ hWaveOut ”没有正确定义。<br>procedure WTWaveOut.Play(buf:LPCTSTR;size:DWORD);<br>var<br>&nbsp; V:DWORD;<br>begin<br>&nbsp; if isInited then<br>&nbsp; begin &nbsp; &nbsp;<br>&nbsp; &nbsp; waveOutGetVolume(hWaveOut,@V);<br>&nbsp; end;<br>end;<br>没有问题。
 
&nbsp; &nbsp;还是不很明,我是想做一个控制音量的东西,书上说的用waveoutgetvolume(0,@v);<br>读出音量,但读不出来.<br>&nbsp; &nbsp; 你的这个类是用来干什么的?具体怎样调用,特别是其中的参数,该怎样赋值?<br>&nbsp; &nbsp; 另外,你的这个类能实现这样的功能吗: 两个声道同时发左声道的东西,两个声道同时发右声道的东西(类卡拉ok).
 
我这个类不完善,也不能两个声道同时发左声道的东西,两个声道同时发右声道的东西,其实关键是“ procedure WTWaveOut.Play(buf:LPCTSTR;size:DWORD);<br>&nbsp;”中的“ buf ”它里面是什么,声卡就响什么。所以,只要你能把数据作好就行。
 
//音量控制<br>procedure TForm1.TrackBar1Change(Sender: TObject);<br>var<br>t,v:Longint;<br>begin<br>// if a=0 then Exit;<br>&nbsp;t:=TrackBar1.Position;<br>&nbsp;v:=(t shl 8)or(t shl 24);<br>&nbsp;waveOutSetVolume(0,v);<br>end;<br><br>//左声道控制<br>procedure TForm1.TrackBar2Change(Sender: TObject);<br>var<br>t,v:Longint;<br>begin<br>&nbsp; t:=TrackBar2.Position;<br>&nbsp; waveOutGetVolume(0,@v);<br>&nbsp; v:=v and $ffff0000 or (t shl 8);<br>&nbsp; waveOutSetVolume(0,v);<br>end;<br><br>//右声道控制<br>procedure TForm1.TrackBar3Change(Sender: TObject);<br>var<br>t,v:Longint;<br>begin<br>&nbsp; t:=TrackBar3.Position;<br>&nbsp; waveOutGetVolume(0,@v);<br>&nbsp; v:=v and $0000ffff or (t shl 24);<br>&nbsp; waveOutSetVolume(0,v);<br>end;<br><br>//获得当前音量值<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>v:longint;<br>begin<br>&nbsp; waveOutGetVolume(0,@v);<br>&nbsp; TrackBar2.Position:=hi(v);<br>&nbsp; TrackBar3.Position:=hi(v shr 16);<br>&nbsp; if hi(v)&amp;gt;hi(v shr 16) then<br>&nbsp; &nbsp;TrackBar1.Position:=hi(v)<br>&nbsp; else<br>&nbsp; &nbsp;TrackBar1.Position:=hi(v shr 16);<br>end;
 

Similar threads

后退
顶部