Programming C# C++ (7) Delphi (617) .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280) Java (8) JavaScript (31) perl (9) php (4) VBScript (1) Visual Basic (1)
Exchange Links About this site Links to us 
|
Determine the Bitrate of a WAVE file
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
How can I determine the bitrate of a *.WAV file?
Answer:
Use the MCI and follow these steps:
- open the file: TForm1.OpenMedia using MCI_OPEN
- obtain the desired status information: TForm1.GetStatus using MCI_STATUS
- then close it: TForm1.CloseMedia using MCI_CLOSE
The unit below shows how it's done. | |  | | unit fMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure OpenMedia(WaveFile: string);
function GetStatus(StatusRequested: DWord) : LongInt;
procedure CloseMedia;
public
end;
var
Form1: TForm1;
implementation
uses
MMSystem;
var
MyError,
dwFlags: LongInt;
FDeviceID: Word;
procedure TForm1.OpenMedia(WaveFile: string);
var
MyOpenParms: TMCI_Open_Parms;
begin
with MyOpenParms do
begin
dwCallback := Handle; lpstrDeviceType := PChar('WaveAudio');
lpstrElementName := PChar(WaveFile)
end;
dwFlags := MCI_WAIT or MCI_OPEN_ELEMENT or MCI_OPEN_TYPE;
MyError := mciSendCommand(0, MCI_OPEN, dwFlags, LongInt(@MyOpenParms));
if MyError=0 then
FDeviceID := MyOpenParms.wDeviceID
else
raise Exception.Create('Open Failed')
end;
function TForm1.GetStatus(StatusRequested: DWord) : LongInt;
var
MyStatusParms: TMCI_Status_Parms;
begin
dwFlags := MCI_WAIT or MCI_STATUS_ITEM;
with MyStatusParms do
begin
dwCallback := Handle;
dwItem := StatusRequested
end;
MyError := mciSendCommand(FDeviceID, MCI_STATUS, MCI_WAIT or MCI_STATUS_ITEM,
LongInt(@MyStatusParms));
if MyError=0 then
Result := MyStatusParms.dwReturn
else
raise Exception.Create('Status call to get status of ' + IntToStr(StatusRequested)
+ ' Failed')
end;
procedure TForm1.CloseMedia;
var
MyGenParms: TMCI_Generic_Parms;
begin
if FDeviceID>0 then
begin
dwFlags := 0;
MyGenParms.dwCallback := Handle; MyError := mciSendCommand(FDeviceID, MCI_CLOSE, dwFlags, LongInt(@MyGenParms));
if MyError=0 then
FDeviceID := 0
else
begin
raise Exception.Create('Close Failed')
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
OpenMedia(OpenDialog1.FileName);
with ListBox1.Items do
begin
Clear;
Add(OpenDialog1.FileName);
Add('Average Bytes / Sec : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_AVGBYTESPERSEC)));
Add('Bits / Sample : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_BITSPERSAMPLE)));
Add('Samples / Sec : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_SAMPLESPERSEC)));
Add('Channels : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_CHANNELS)))
end;
CloseMedia
end;
end;
end. | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|