Система обработки аудиоинформации. Подсистема фильтрации и обработки сигнала
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
/p>
nBlockAlign := wBitsPerSample div 8 * nChannels;
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
cbSize := 0;
end;
hEvent := CreateEvent(nil, False, False, nil);
MMSYSERR_NOERRORthen"> if WaveInOpen(@WaveIn, MainForm.InDeviceComboBox.ItemIndex , @WaveFormatEx, hEvent, 0, CALLBACK_EVENT) <> MMSYSERR_NOERROR then
begin
Status := waiting;
CloseHandle(hEvent);
Terminate;
Exit;
end;
MainForm.RecordButton.Flat := True;
for i := 0 to BufNumber-1 do
begin
WaveHdr[i].lpData := @Buf[i];
WaveHdr[i].dwBufferLength := BlockSize;
WaveInPrepareHeader(WaveIn, @WaveHdr[i], SizeOf(TWaveHdr));
end;
WaveInStart(WaveIn);
WaitForSingleObject(hEvent, INFINITE);
for i := 0 to BufNumber-1 do
WaveInAddBuffer(WaveIn, @WaveHdr[i], SizeOf(TWaveHdr));
i := BufNumber-1;
while not Terminated do
begin
if i = BufNumber-1 then i := 0 else Inc(i);
if (WaveHdr[i].dwFlags and WHDR_DONE) <> WHDR_DONE then
WaitForSingleObject(hEvent, INFINITE);
AudioData.Data.Position := AudioPosition*AudioData.nBlockAlign;
AudioData.Data.Write(Buf[i], WaveHdr[i].dwBytesRecorded);
AudioPosition := AudioPosition + (WaveHdr[i].dwBytesRecorded div AudioData.nBlockAlign);
WaveInAddBuffer(WaveIn, @WaveHdr[i], SizeOf(TWaveHdr));
MainForm.SetAudioPosition;
end;
WaveInReset(WaveIn);
for i := 0 to BufNumber-1 do
WaveInUnprepareHeader(WaveIn, @WaveHdr[i], SizeOf(WaveHdr));
WaveInClose(WaveIn);
CloseHandle(hEvent);
if not Terminated then Terminate;
with MainForm.PositionSpinEdit do
begin
Value := AudioPosition;
MinValue := 0;
MaxValue := AudioData.Data.Size div AudioData.nBlockAlign;;
end;
MainForm.RecordButton.Flat := False;
Status := waiting;
end;
procedure TMainForm.PauseButtonClick(Sender: TObject);
begin
if Status = playing then PlayThread.Terminate;
if Status = recording then RecordThread.Terminate;
end;
procedure TMainForm.TrackBarChange(Sender: TObject);
var
AudioSize: Cardinal;
begin
if Status<>waiting then Exit;
with AudioData do
AudioSize := Data.Size div nBlockAlign;
Round(AudioPosition*TrackBar.Max/AudioSize)then"> if TrackBar.Position <> Round(AudioPosition*TrackBar.Max/AudioSize) then
begin
AudioPosition := Round(TrackBar.Position/TrackBar.Max*AudioSize);
SetAudioPosition;
end;
end;
procedure TMainForm.PositionSpinEditChange(Sender: TObject);
begin
if Status<>waiting then Exit;
AudioPosition := PositionSpinEdit.Value;
SetAudioPosition;
end;
procedure TMainForm.SaveButtonClick(Sender: TObject);
var
FileName, Ext, EncMode, StereoMode, BitRate: String;
i: Byte;
Code: Integer;
PCM: TPCMFile;
MP3: TMP3File;
EM1: TEM1File;
begin
if Status<>waiting then Exit;
if SaveDialog.Execute then
FileName := SaveDialog.FileName else Exit;
Ext := ExtractFileExt(FileName);
for i := 1 to Length(Ext) do Ext[i] := UpCase(Ext[i]);
if Ext = .WAV then
begin
PCM := TPCMFile.Create(FileName, AudioData);
PCM.Destroy;
end;
if Ext = .MP3 then
begin
if RadioButton1.Checked then
begin
BitRate := MP3OptionsForm.ConstantBitRateComboBox.Text;
EncMode := -b;
end;
if RadioButton2.Checked then
begin
BitRate := MP3OptionsForm.AverageBitRateComboBox.Text;
EncMode := --abr;
end;
if RadioButton3.Checked then
begin
Str(MP3OptionsForm.VariableBitrateComboBox.ItemIndex, BitRate);
EncMode := -V;
end;
case MP3OptionsForm.StereoModeComboBox.ItemIndex of
0: StereoMode := s;
1: StereoMode := j;
2: StereoMode := f;
3: StereoMode := d;
4: StereoMode := m;
end;
MP3 := TMP3File.Create(FileName, AudioData, BitRate, EncMode, StereoMode);
MP3.Destroy;
end;
if Ext = .EM1 then
begin
EM1 := TEM1File.Create(FileName, AudioData);
EM1.Destroy;
end;
end;
procedure TMainForm.SetMarkerButtonClick(Sender: TObject);
begin
SetMarker;
end;
procedure TMainForm.DeleteMarkersButtonClick(Sender: TObject);
begin
DeleteMarkers;
end;
procedure TMainForm.CopyButtonClick(Sender: TObject);
var
AudioSize: Cardinal;
S: String;
begin
if Status<>waiting then Exit;
Status := editing;
with AudioData do
AudioSize := Data.Size div nBlockAlign;
with Selection do
begin
if not StartExists or not FinishExists then
begin
DeleteMarkers;
Start := 0;
Finish := AudioSize-1;
end;
CopyAudio(AudioData, AudioClipBoard, Start, Finish);
end;
Str(AudioClipBoard.Data.Size div AudioClipBoard.nBlockAlign div AudioClipBoard.nSamplesPerSec, S);
Memo1.Text := + S + .;
Status := waiting;
end;
procedure TMainForm.DeleteButtonClick(Sender: TObject);
var
AudioSize: Cardinal;
begin
if Status<>waiting then Exit;
Status := editing;
SaveUndoInfo;
with AudioData do
AudioSize := Data.Size div nBlockAlign;
with Selection do
begin
if not StartExists or not FinishExists then
begin
DeleteMarkers;
Start := 0;
Finish := AudioSize-1;
end;
DeleteAudio(AudioData, Start, Finish);
DeleteMarkers;
AudioPosition := Start;
SetAudioPosition;
end;
Status := waiting;
end;
procedure TMainForm.CutButtonClick(Sender: TObject);
var
AudioSize: Cardinal;
S: String;
begin
if Status<>waiting then Exit;
Status := editing;
SaveUndoInfo;
with AudioData do
AudioSize := Data.Size div nBlockAlign;
with Selection do
begin
if not StartExists or not FinishExists then
begin
DeleteMarkers;
Start := 0;
Finish := AudioSize-1;
end;
CopyAudio(AudioData, AudioClipBoard, Start, Finish);
DeleteAudio(AudioData, Start, Finish);
DeleteMarkers;
AudioPosition := Start;
SetAudioPosition;
end;
Str(AudioClipBoard.Data.Size div AudioClipBoard.nBlockAlign div AudioClipBoard.nSamplesPerSec, S);
Memo1.Text := + S + .;
Status := waiting;
end;
procedure TMainForm.ClearButtonClick(Sender: TObject);
var
AudioSize, i: Cardinal;
Buf: Byte;
begin
if Status<>waiting then Exit;
Status := editing;
SaveUndoInfo;
with AudioData do
AudioSize := Data.Size div nBlockAlign;
with Selection do
begin
if not StartExists or not FinishExists then
begin
DeleteMarkers;
Start := 0;
Finish := AudioSize-1;
end;
Buf := 0;
AudioData.Data.Position := Start*AudioData.nBlockAlign;
for i := Start*AudioData.nBlockAlign to Finish*AudioData.nBlockAlign-1 do
AudioData.Data.Write(Buf, 1);
end;
Status := waiting;
PaintAudioGraph;
end;
procedure TMainForm.PasteButtonClick(Sender: TObject);
var
MP3: TMP3File;
PCM: TPCMFile;
EM1: TEM1File;
i: Byte;
FileName, S, Ext: String;
TempAudio: TAudioData;
begin
if (Statusstarting) then Exit;
if Sender = PasteFileButton then
begin
if OpenDialog.Execute then FileName := OpenDialog.FileName else Exit;
Status := opening;
Ext := ExtractFileExt(FileName);
if GetFileAttributes(PChar(FileName)) and FILE_ATTRIBUTE_READONLY = FILE_ATTRIBUTE_READONLY then
SetFileAttributes(PChar(FileName), GetFileAttributes(PChar(FileName)) xor FILE_ATTRIBUTE_READONLY);
TempAudio := TAudioData.Create;
for i := 1 to Length(Ext) do Ext[i] := UpCase(Ext[i]);
if Ext = .WAV then
begin
PCM := TPCMFile.Open(FileName);
PCM.ReadAudioData(TempAudio);
PCM.Destroy;
end;
if Ext = .MP3 then
begin
MP3 := TMP3File.Open(FileName);
MP3.ReadAudioData(TempAudio);
MP3.Destroy;
end;
if Ext =