Система обработки аудиоинформации. Подсистема фильтрации и обработки сигнала

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование



0Round(AudioPosition*TrackBar.Max/AudioSize)thenTrackBar.Position:=Round(AudioPosition*TrackBar.Max/AudioSize);"> if TrackBar.Position <> Round(AudioPosition*TrackBar.Max/AudioSize) then TrackBar.Position := Round(AudioPosition*TrackBar.Max/AudioSize);

S2 := ;

Long := Trunc(AudioPosition/AudioData.nSamplesPerSec);

Str(Trunc(Long/3600), S);

Long := Long - Trunc(Long/3600)*3600;

S2 := S2 + S +:;

Str(Trunc(Long/60), S);

Long := Long - Trunc(Long/60)*60;

if Length(S)=1 then S2 := S2 + 0;

S2 := S2 + S +:;

Str(Long, S);

if Length(S)=1 then S2 := S2 + 0;

S2 := S2 + S + / ;

Long := Trunc(AudioSize/AudioData.nSamplesPerSec);

Str(Trunc(Long/3600), S);

Long := Long - Trunc(Long/3600)*3600;

S2 := S2 + S +:;

Str(Trunc(Long/60), S);

Long := Long - Trunc(Long/60)*60;

if Length(S)=1 then S2 := S2 + 0;

S2 := S2 + S +:;

Str(Long, S);

if Length(S)=1 then S2 := S2 + 0;

S2 := S2 + S + ;

S2thenTimePosition.Caption:=S2;"> if TimePosition.Caption<>S2 then TimePosition.Caption := S2;

{PaintBox1.Repaint;}

PaintAudioGraph;

end;

procedure TMainForm.SetMarker;

var

AudioSize: Cardinal;

begin

if (Status = starting) then Exit;

with AudioData do AudioSize := Data.Size div nBlockAlign;

with Selection do

begin

if (AudioPosition=Start)and(StartExists) or (AudioPosition=Finish)and(FinishExists) then Exit;

if not StartExists then

begin

Start := AudioPosition;

StartExists := True;

Marker1.Left := 8+Round(Start*(TrackBar.Max-20)/AudioSize);

Marker1.Visible := True;

Exit;

end;

if (StartExists) and (not FinishExists) then

begin

if AudioPosition>Start then

Finish := AudioPosition

else

begin

Finish := Start;

Start := AudioPosition;

end;

FinishExists := True;

TrackBar.SelStart := Round(Start*TrackBar.Max/AudioSize);

TrackBar.SelEnd := Round(Finish*TrackBar.Max/AudioSize);

Marker1.Left := 8+Round(Start*(TrackBar.Max-20)/AudioSize);

Marker1.Visible := True;

Marker2.Left := 8+Round(Finish*(TrackBar.Max-20)/AudioSize);

Marker2.Visible := True;

PaintBox1.Repaint;

Exit;

end;

if (StartExists) and (FinishExists) then

begin

if AudioPosition<Start then

Start := AudioPosition

else

if AudioPosition>Finish then

Finish := AudioPosition;

TrackBar.SelStart := Round(Start*TrackBar.Max/AudioSize);

TrackBar.SelEnd := Round(Finish*TrackBar.Max/AudioSize);

Marker1.Left := 8+Round(Start*(TrackBar.Max-20)/AudioSize);

Marker1.Visible := True;

Marker2.Left := 8+Round(Finish*(TrackBar.Max-20)/AudioSize);

Marker2.Visible := True;

PaintBox1.Repaint;

Exit;

end;

end;

end;

procedure TMainForm.DeleteMarkers;

begin

Selection.StartExists := False;

Selection.FinishExists := False;

Marker1.Visible := False;

Marker2.Visible := False;

TrackBar.SelStart := 0;

TrackBar.SelEnd := 0;

PaintBox1.Repaint;

end;

procedure TMainForm.OpenButtonClick(Sender: TObject);

var

FileName, S, Ext: String;

i: Byte;

PCM: TPCMFile;

MP3: TMP3File;

EM1: TEM1File;

begin

if (Statuswaiting) then Exit;

if OpenDialog.Execute then FileName := OpenDialog.FileName else Exit;

Status := opening;

AudioData.Data.Clear;

if GetFileAttributes(PChar(FileName)) and FILE_ATTRIBUTE_READONLY = FILE_ATTRIBUTE_READONLY then

SetFileAttributes(PChar(FileName), GetFileAttributes(PChar(FileName)) xor FILE_ATTRIBUTE_READONLY);

Ext := ExtractFileExt(FileName);

for i := 1 to Length(Ext) do Ext[i] := UpCase(Ext[i]);

if Ext = .WAV then

begin

PCM := TPCMFile.Open(FileName);

PCM.ReadAudioData(AudioData);

PCM.Destroy;

end;

if Ext = .MP3 then

begin

MP3 := TMP3File.Open(FileName);

MP3.ReadAudioData(AudioData);

MP3.Destroy;

end;

if Ext = .EM1 then

begin

EM1 := TEM1File.Open(FileName);

EM1.ReadAudioData(AudioData);

EM1.Destroy;

end;

Str(AudioData.nChannels, S);

AudioOptionsForm.nChannelsText.Caption := S + channels;

Str(AudioData.nBitsPerSample, S);

AudioOptionsForm.nBitsPerSampleText.Caption := S + bits;

Str(AudioData.nSamplesPerSec, S);

AudioOptionsForm.nSamplesPerSecText.Caption := S + Hz;

AudioPosition := 0;

AudioData.Calculate_nBlockAlign;

SetAudioPosition;

DeleteMarkers;

Status := waiting;

end;

procedure TMainForm.PlayButtonClick(Sender: TObject);

begin

if Status<>waiting then Exit;

if OutDeviceComboBox.ItemIndex = -1 then Exit;

=AudioData.Data.SizethenExit;"> if AudioPosition*AudioData.nBlockAlign >= AudioData.Data.Size then Exit;

Status := playing;

PlayThread := TPlayThread.Create(False);

end;

procedure TPlayThread.Execute;

const

BlockSize = 1024*24;

var

hEvent: THandle;

WaveFormatEx: TWaveFormatEx;

WaveHdr: array [0..1] of TWaveHdr;

Buf: array [0..1] of array [0..BlockSize-1] of Byte;

i: Cardinal;

begin

with WaveFormatEx do

begin

wFormatTag := WAVE_FORMAT_PCM;

nChannels := AudioData.nChannels;

nSamplesPerSec := AudioData.nSamplesPerSec;

wBitsPerSample := AudioData.nBitsPerSample;

nBlockAlign := wBitsPerSample div 8 * nChannels;

nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;

cbSize := 0;

end;

hEvent := CreateEvent(nil, False, False, nil);

MMSYSERR_NOERRORthen"> if WaveOutOpen(@WaveOut, MainForm.OutDeviceComboBox.ItemIndex , @WaveFormatEx, hEvent, 0, CALLBACK_EVENT) <> MMSYSERR_NOERROR then

begin

Status := waiting;

CloseHandle(hEvent);

Terminate;

Exit;

end;

MainForm.PlayButton.Flat := True;

for i := 0 to 1 do

begin

WaveHdr[i].lpData := @Buf[i];

WaveHdr[i].dwBufferLength := BlockSize;

AudioData.Data.Position := AudioPosition*AudioData.nBlockAlign;

if i<>1 then

begin

AudioData.Data.Read(Buf[i], BlockSize);

AudioPosition := AudioPosition + BlockSize div AudioData.nBlockAlign;

=AudioData.Data.SizethenAudioPosition:=AudioData.Data.SizedivAudioData.nBlockAlign;"> if AudioPosition*AudioData.nBlockAlign >= AudioData.Data.Size then AudioPosition := AudioData.Data.Size div AudioData.nBlockAlign;

end;

WaveOutPrepareHeader(WaveOut, @WaveHdr[i], SizeOf(TWaveHdr));

end;

i := 0;

while (not Terminated) and (AudioData.Data.Position<AudioData.Data.Size) do

begin

WaveOutWrite(WaveOut, @WaveHdr[i], SizeOf(TWaveHdr));

WaitForSingleObject(hEvent, INFINITE);

i := i xor 1;

AudioData.Data.Position := AudioPosition*AudioData.nBlockAlign;

AudioData.Data.Read(Buf[i], BlockSize);

AudioPosition := AudioPosition + (BlockSize div AudioData.nBlockAlign);

=AudioData.Data.SizethenAudioPosition:=AudioData.Data.SizedivAudioData.nBlockAlign;"> if AudioPosition*AudioData.nBlockAlign >= AudioData.Data.Size then AudioPosition := AudioData.Data.Size div AudioData.nBlockAlign;

MainForm.SetAudioPosition;

end;

WaveOutReset(WaveOut);

for i := 0 to 1 do WaveOutUnprepareHeader(WaveOut, @WaveHdr[i], SizeOf(WaveHdr));

WaveOutClose(WaveOut);

CloseHandle(hEvent);

if not Terminated then Terminate;

MainForm.PlayButton.Flat := False;

Status := waiting;

end;

procedure TMainForm.RecordButtonClick(Sender: TObject);

begin

if (Statusstarting) then Exit;

if InDeviceComboBox.ItemIndex = -1 then Exit;

Status := recording;

RecordThread := TRecordThread.Create(False);

end;

procedure TRecordThread.Execute;

const

BlockSize = 1024*24;

BufNumber = 8;

var

hEvent: THandle;

WaveFormatEx: TWaveFormatEx;

WaveHdr: array [0..BufNumber-1] of TWaveHdr;

Buf: array [0..BufNumber-1] of array [0..BlockSize-1] of Byte;

i: Cardinal;

begin

with WaveFormatEx do

begin

wFormatTag := WAVE_FORMAT_PCM;

nChannels := AudioData.nChannels;

nSamplesPerSec := AudioData.nSamplesPerSec;

wBitsPerSample := AudioData.nBitsPerSample;<