录音。 (50分)

  • 主题发起人 主题发起人 怡.梦
  • 开始时间 开始时间

怡.梦

Unregistered / Unconfirmed
GUEST, unregistred user!
1、用下面的过程录音,可是录出音我在写的示波程序中不显波形,不知道录音时这样设置参数对不对。帮我看一看!
2、TAudio控件可不以显示声音文件的波形!
procedure TForm1.CreateWav( channels : word;
{ 1(单声)或者2(立体声) } resolution : word;
{ 8或者16,代表8位或16位声音 }rate : longint;
{ 声音频率,如11025,22050, 44100} fn : string { 对应的文件名称 } );
var
wf : file of TWavHeader;
wh : TWavHeader;
begin

wh.rId := $46464952;
wh.rLen := 36;
wh.wId := $45564157;
wh.fId := $20746d66;
wh.fLen := 16;
wh.wFormatTag := WAVE_FORMAT_PCM;//WAVE_F0RAM_ADPCM;
wh.nChannels := channels;

wh.nSamplesPerSec := rate;
wh.nAvgBytesPerSec := channels*rate*(resolution div 8);
wh.nBlockAlign := channels*(resolution div 8);
wh.wBitsPerSample := resolution;
wh.dId := $61746164;

wh.wSampleLength := 0;
///在波形数据格式参数中,WFormatTag用来设置wav格式;nChannels用来设置声道个数;
//nSamplesPerSec用来设置采样频率;nAvgBytesPerSec用来设置每秒所需字节数;
//nBlockAlign用来设置每个采样点所需总字节数wBitsPerSample用来设置每个采样点所需Bit数。

assignfile(wf,fn);
{打开对应文件 }
rewrite(wf);
{移动指针到文件头}
write(wf,wh);
{写进文件头 }
closefile(wf);
{关闭文件 }
end;
 
用Mediaplayer录音时,制作成左右声道格式的文件。(像VCD时的原唱/伴唱)怎么做?
 
1。不能。
2。msdn。
delphi目录/source/vcl/mplayer.pas
.../source/rtl/win/Mmsystem.pas
 
用Mediaplayer录音时,制作成左右声道格式的文件。(像VCD时的原唱/伴唱)怎么做?
 
1、用下面的过程录音,可是录出音我在写的示波程序中不显波形,不知道录音时这样设置参数对不对。帮我看一看!
2、TAudio控件可不以显示声音文件的波形!
 
我这有一段关于录音的资料,不过我没试过,你看看吧
// 全局变量
var
BufferFinished : boolean;
// indicates current record buffer is full
.
UserStopRecord: boolean;

Recording: boolean;


WaveInHandle: HWaveIn;


CurrentUsingBuffer: integer;

WaveInHeader1: TWaveHdr;

WaveInHeader2: TWaveHdr;


RecordBufferSize: integer;

TotalRecordedSize: DWORD;



//进行录音
procedure TDlgRecord.BtnStartClick(Sender: TObject);

var
TempInt, TempCode: integer;

TempFileName: string;


MMR: MMResult;

MyWaveFormat: TWaveFormatEx;


begin

PrgsBarSpace.Position := 0;

Recording := false;

OldDiskFree := DiskFree (RecordDrive);

with RecordWaveFormatdo

begin

if RdoBtnMono.Checked = true then

Channels := 1
else

Channels := 2;

if RdoBtn8Bit.Checked = true then

BitsPerSample := 8
else

BitsPerSample := 16;

Val (EditFrequency.Text, TempInt, TempCode);

if TempCode <> 0 then

begin

Application.MessageBox ('无效数值', '错误', MB_Ok);

exit;

end
else
if TempInt > 48000 then

begin

Application.MessageBox('不能大于48000赫兹', '错误', MB_Ok);

exit;

end
else

begin

SamplesPerSecond := TempInt;

end;


BytesPerSecond := SamplesPerSecond * Channels * BitsPerSample div
8;

BlockAlign := BitsPerSample * Channels div 8 ;

end;



TempFileName := TempFileNameGenerator (Self.TempPath, 'WM_', 'TMP',
5);


AssignFile (RecordFile, TempFileName);

Rewrite (RecordFile, 1);

if IOResult <> 0 then

begin

Application.Messagebox ('无法创建暂时文件,请检查临时目录设定。',
'严重错误', MB_OK);

exit;

end;



RecordFileName := TempFileName;

RecordSuccess := false;
// 由于文件名已经改变,所以在这里修改该变量。


// Preparation jobs here
SttTextElapsedTime.Caption := '00:00:00';

ElapsedHours := 0;

ElapsedMinutes := 0;

ElapsedSeconds := 0;

CurrentUsingBuffer := 1;

TotalRecordedSize := 0;

BufferFinished := false;

UserStopRecord := false;

RecordBufferSize := RecordWaveFormat.BytesPerSecond * 2;
// for 2 se
conds
Buffer1 := nil;

Buffer2 := nil;


try
GetMem (Buffer1, RecordBufferSize);

except
Application.MessageBox ('内存不足,分配第一缓冲区失败。', '错误',
MB_OK);

end;



try
GetMem (Buffer2, RecordBufferSize);

except
Application.MessageBox ('内存不足,分配第二缓冲区失败。', '错误',
MB_OK);

end;



if (Buffer1 = nil) or (Buffer2 = nil) then

begin

CloseFile (RecordFile);

exit;

end;



MyWaveFormat.wFormatTag := WAVE_FORMAT_PCM;

MyWaveFormat.nChannels := RecordWaveFormat.Channels;

MyWaveFormat.nSamplesPerSec := RecordWaveFormat.SamplesPerSecond;

MyWaveFormat.nAvgBytesPerSec := RecordWaveFormat.BytesPerSecond;

MyWaveFormat.nBlockAlign := RecordWaveFormat.BlockAlign;

MyWaveFormat.wBitsPerSample := RecordWaveFormat.BitsPerSample;

MyWaveFormat.cbSize := 0;


MMR := waveInOpen (Addr (waveInHandle),
SelectedDevice,
Addr (MyWaveFormat),
DWORD (Addr (WaveInCallBack)),
0,
CALLBACK_FUNCTION);

if MMR <> MMSYSERR_NOERROR then

begin

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Application.MessageBox ('无法打开输入设备,请检查设定。', '错误',
MB_OK);

exit;

end;



waveInHeader1.lpData := Buffer1;

waveInHeader1.dwBufferLength := RecordBufferSize;

waveInHeader1.dwBytesRecorded := 0;

waveInHeader1.dwUser := 0;
// 32 bits of user data
waveInHeader1.dwFlags := 0;

waveInHeader1.dwLoops := 0;

waveInHeader1.lpNext := nil;
// reserved;
must be zero
waveInHeader1.reserved := 0;
// reserved;
must be zero
MMR := waveInPrepareHeader (waveInHandle, Addr (waveInHeader1),
sizeof (waveInHeader1));

if MMR <> MMSYSERR_NOERROR then

begin

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Application.MessageBox ('第一录音缓冲区准备出错。', '错误', MB_OK)
;

exit;

end;



waveInHeader2.lpData := Buffer2;

waveInHeader2.dwBufferLength := RecordBufferSize;

waveInHeader2.dwBytesRecorded := 0;

waveInHeader2.dwUser := 0;
// 32 bits of user data
waveInHeader2.dwFlags := 0;

waveInHeader2.dwLoops := 0;

waveInHeader2.lpNext := nil;
// reserved;
must be zero
waveInHeader2.reserved := 0;
// reserved;
must be zero

MMR := waveInPrepareHeader (waveInHandle, Addr (waveInHeader2),
sizeof (waveInHeader2));

if MMR <> MMSYSERR_NOERROR then

begin

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader1), sizeof(
waveInHeader1));

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Application.MessageBox ('第二录音缓冲区准备出错。', '错误', MB_OK)
;

exit;

end;



MMR := waveInAddBuffer (WaveInHandle, Addr (waveInHeader1), sizeof (
waveInHeader1));

if MMR <> MMSYSERR_NOERROR then

begin

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader1), sizeof(
waveInHeader1));

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader2), sizeof(
waveInHeader2));

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Application.MessageBox ('添加第一缓冲区出错。', '错误', MB_OK);

exit;

end;



MMR := waveInAddBuffer (WaveInHandle, Addr (waveInHeader2), sizeof (
waveInHeader2));

if MMR <> MMSYSERR_NOERROR then

begin

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader1), sizeof(
waveInHeader1));

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader2), sizeof(
waveInHeader2));

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Application.MessageBox ('添加第二缓冲区出错。', '错误', MB_OK);

exit;

end;




TimerRecording.Enabled := true;

// Record has begun.
Recording := true;


MMR := waveInStart (waveInHandle);

if MMR <> MMSYSERR_NOERROR then

begin

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader1), sizeof(
waveInHeader1));

waveInUnprepareHeader (waveInHandle, Addr (waveInHeader2), sizeof(
waveInHeader2));

FreeMem (Buffer1);
FreeMem (Buffer2);

RecordBufferSize := 0;

CloseFile (RecordFile);

Recording := false;

TimerRecording.Enabled := false;

Application.MessageBox ('未能开始录音。', '错误', MB_OK);

exit;

end;



// 应该在这里开始创建线程.
// 需要传递参数: RecordFile, Buffer1, Buffer2,
with TMediaRecordThread.Create (Addr(RecordFile), Buffer1, Buffer2)
do
OnTerminate := ThreadRecordStop;


// disable/enable controls
BtnCancel.Enabled := false;

BtnStart.Enabled := false;

GrpBoxChannel.Enabled := false;

LBFrequency.Enabled := false;

EditFrequency.Enabled := false;

LstBoxFrequency.Enabled := false;

GrpBoxSample.Enabled := false;


BtnStop.Enabled := true;


end;


 
试一试。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
875
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
934
DelphiTeacher的专栏
D
I
回复
0
查看
719
import
I
后退
顶部