// Um die Wave-Datei-Daten zu ermitteln, kann man folgendes machen:
// Getestet mit D4 unter NT4
// Variante1: Nur die Länge ermitteln
uses mmsystem;
function WaveLaenge(datei: string): double;
var
i: integer;
r: array[0..29] of char;
procedure aus;
begin
MCISendString(pchar('stop wavsound'), nil, 0, 0);
MCISendString(pchar('close wavsound'), nil, 0, 0);
end;
begin
aus;
MCISendString(pchar('open ' + datei + ' type waveaudio alias wavsound'), nil, 0, 0);
i := MCISendString(pchar('status wavsound length'), r, 30, 0);
if i = 0 then result := strtoint(r) / 1000
else result := -1;
aus;
end;
// Beispielaufruf
procedure TForm1.Button3Click(Sender: TObject);
var
d: double;
s, n: string;
begin
s := 'c:\drums.wav';
d := wavelaenge(s);
n := ansiuppercase(extractfilename(s) + ': ');
if d = -1 then showmessage(n + 'Länge konnte nicht ermittelt werden.') else
showmessage(n + formatfloat('#,##0.000 Sekunden', d));
end;
//-----------------------------------------------------------------
// Variante2: Wave-Daten auslesen
uses mmsystem;
var
dwFlags: DWord;
IDDevice: MCIDEVICEID = 0;
function OpenWave(datei: string): MCIERROR;
var
oParms: tagMCI_OPEN_PARMSA;
begin
with oParms do begin
dwCallback := 0;
lpstrDeviceType := 'WaveAudio';
lpstrElementName := PChar(datei);
end;
dwFlags := MCI_WAIT or MCI_OPEN_ELEMENT or MCI_OPEN_TYPE;
result := mciSendCommand(0, MCI_OPEN, dwFlags, DWord(@oParms));
if result = 0 then IDDevice := oParms.wDeviceID;
mciSendCommand(oParms.wDeviceID, MCI_PLAY, MCI_WAIT, DWord(@oParms));
end;
procedure CloseWave;
var
gParms: tagMCI_GENERIC_PARMS;
begin
if IDDevice > 0 then begin
dwFlags := 0;
gParms.dwCallback := 0;
mciSendCommand(IDDevice, MCI_CLOSE, dwFlags, DWord(@gParms));
end;
end;
function GetStatus(Statusq: DWord): DWord;
var
sParms: tagMCI_STATUS_PARMS;
begin
dwFlags := MCI_WAIT or MCI_STATUS_ITEM;
sParms.dwCallback := 0;
sParms.dwItem := Statusq;
if not mciSendCommand(IDDevice, MCI_STATUS,
dwFlags, DWord(@sParms)) = 0 then begin
CloseWave;
raise exception.create('Status konnte nicht ermittelt werden');
end else result := sParms.dwReturn;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Listbox1.clear;
if OpenDialog1.Execute then begin
if OpenWave(OpenDialog1.FileName) = 0 then begin
with ListBox1.Items do begin
Add('FormatTag: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_FORMATTAG)));
Add('Channels: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_CHANNELS)));
Add('SamplesPerSec: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_SAMPLESPERSEC)));
Add('AvgBytesPerSec: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_AVGBYTESPERSEC)));
Add('BlockAlign: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_BLOCKALIGN)));
Add('BitsPerSample: ' +
IntToStr(GetStatus(MCI_WAVE_STATUS_BITSPERSAMPLE)));
Add('Length (Sec.): ' +
formatfloat('#,##0.000', GetStatus(MCI_STATUS_LENGTH) / 1000));
end;
CloseWave;
end else raise exception.create('Fehler beim Öffnen');
end;
end;
|