Forum > Audio and Video

Audio Component Suite - how convert mp3 to wav?

(1/1)

domasz:
There are these units in the ACS: acs_mp3.pas and mp3.pas but I am not sure how to convert mp3 to wav using them.
I couldn't find any example.

I tried this way:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var mp3: TMP3In;    buff: array of Byte;    len: Integer;    sum: Int64;begin  mp3 := TMP3In.create(Form1);  mp3.FileName:='test.mp3';  mp3.init;   setlength(buff, 4096);     sum := 0;   repeat    len := mp3.GetData(@buff[0], 4096);     sum := sum + len;     if len < 4096 then break;  until 1=0;    mp3.free;  showmessage(inttostr(sum)); end;
[Edited to add code tags: please read How to use the Forums.]

serbod:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program mp3test; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes, SysUtils, CustApp  { you can add units after this }  ,mp3; type   { TMyApplication }   TMyApplication = class(TCustomApplication)  protected    procedure DoRun; override;  public    constructor Create(TheOwner: TComponent); override;    destructor Destroy; override;     procedure Test();  end; type  TWaveHeader = record    Marker1: array[0..3] of AnsiChar;    BytesFollowing: LongInt;    Marker2: array[0..3] of AnsiChar;    Marker3: array[0..3] of AnsiChar;    Fixed1: LongInt;    FormatTag: Word;    Channels: Word;    SampleRate: LongInt;    BytesPerSecond: LongInt;    BytesPerSample: Word;    BitsPerSample: Word;    Marker4: array[0..3] of AnsiChar;    DataBytes: LongInt;  end; procedure CreateWavFile(AFileName: string; ms: TStream; Channels, SampleRate, Resolution: Integer);var  DataBytes: Integer;  WaveHeader: TWaveHeader;  fsOut: TFileStream;begin  DataBytes := ms.Size;   WaveHeader.Marker1 := 'RIFF';  WaveHeader.BytesFollowing := DataBytes + 36;  WaveHeader.Marker2 := 'WAVE';  WaveHeader.Marker3 := 'fmt ';  WaveHeader.Fixed1 := 16;  WaveHeader.FormatTag := 1;  WaveHeader.SampleRate := SampleRate;  WaveHeader.Channels := Channels;  WaveHeader.BytesPerSecond := Channels;  WaveHeader.BytesPerSecond := WaveHeader.BytesPerSecond * SampleRate;  WaveHeader.BytesPerSecond := WaveHeader.BytesPerSecond * Resolution;  WaveHeader.BytesPerSecond := WaveHeader.BytesPerSecond div 8;  WaveHeader.BytesPerSample := Channels * Resolution div 8;  WaveHeader.BitsPerSample := Resolution;  WaveHeader.Marker4 := 'data';  WaveHeader.DataBytes := DataBytes;   if FileExists(AFileName) then    DeleteFile(AFileName);  fsOut := TFileStream.Create(AFileName, fmCreate or fmShareDenyNone);  try    fsOut.Write(WaveHeader, Sizeof(WaveHeader));    ms.Position := 0;    fsOut.CopyFrom(ms, ms.Size);  finally    fsOut.Free();  end;end; { TMyApplication } procedure TMyApplication.DoRun;var  ErrorMsg: String;begin   { add your program here }  Test();   // stop program loop  Terminate;end; constructor TMyApplication.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  StopOnException := True;end; destructor TMyApplication.Destroy;begin  inherited Destroy;end; procedure TMyApplication.Test;var  id: TPdmp3Handle;  fsIn, fsOut: TStream;  InBuf, OutBuf: TByteArray;  InSize, OutSize: Integer;  res: Integer;  dt: TDateTime;begin  if FileExists('out.raw') then    DeleteFile('out.raw');   fsIn := TFileStream.Create('sample-3s.mp3', fmOpenRead or fmShareDenyNone);  fsOut := TMemoryStream.Create();   dt := Now();   try    pdmp3_open_feed(id);     res := PDMP3_NEED_MORE;    while (res = PDMP3_OK) or (res = PDMP3_NEED_MORE) do    begin      // transcode      inSize := fsIn.Read(InBuf, 2048);      FillChar(OutBuf, SizeOf(OutBuf), 0);      res := pdmp3_decode(id, InBuf, inSize, OutBuf, SizeOf(OutBuf), OutSize);       if (res = PDMP3_OK) or (res = PDMP3_NEED_MORE) then      begin        fsOut.Write(OutBuf, OutSize);      end;    end;     CreateWavFile('out.wav', fsOut, 2, 44100, 16);   finally    fsOut.Free();    fsIn.Free();  end;   WriteLn(FormatDateTime('nn:ss.zzz', Now()-dt));  ReadLn();end;  var  Application: TMyApplication;begin  Application := TMyApplication.Create(nil);  Application.Title := 'My Application';  Application.Run;  Application.Free;end. 

Navigation

[0] Message Index

Go to full version