procedure TForm1.Button3Click(Sender: TObject);
var
filelength, framewanted: integer;
thememorystream1: Tmemorystream; // The memorystream that we will use
begin
Edit4.Text := application.Location + directoryseparator + 'sound' + directoryseparator + 'test.flac'; // use libsndfile
form1.Height := 456;
form1.Position := poScreenCenter;
if fileexists(Edit4.Text) then
begin
if Assigned(waveformBMP) then
waveformBMP.Free;
waveformBMP := TBitmap.Create;
PaintBox2.Parent.DoubleBuffered := True;
waveformBMP.Height := PaintBox2.Height;
waveformBMP.Width := PaintBox2.Width;
waveformBMP.Canvas.AntialiasingMode := amOn;
waveformBMP.Canvas.Pen.Width := 1;
waveformBMP.Canvas.brush.Color := clgray;
waveformBMP.Canvas.FillRect(0, 0, PaintBox2.Width, PaintBox2.Height);
PaintBox2.Refresh;
PlayerIndex1 := 0;
// Create a memory stream from a audio file wav, ogg, flac, mp3, opus.
thememorystream1 := TMemoryStream.Create;
thememorystream1.LoadFromFile(PChar(Edit4.Text));
thememorystream1.Position := 0;
// Create the player.
uos_CreatePlayer(PlayerIndex1);
// PlayerIndex : from 0 to what your computer can do !
// If PlayerIndex exists already, it will be overwritten...
In1Index := uos_AddFromMemoryStream(PlayerIndex1, thememorystream1, 0, -1, 2, 1024 * 8);
// Add a input from memory stream with custom parameters
// MemoryStream : Memory stream of encoded audio.
// TypeAudio : default : -1 --> 0 (0: flac, ogg, wav; 1: mp3; 2:opus)
// OutputIndex : Output index of used output
// -1: all output, -2: no output, other a existing OutputIndex
// (if multi-output then OutName = name of each output separeted by ';')
// SampleFormat : default : -1 (2:Int16) (0: Float32, 1:Int32, 2:Int16)
// FramesCount : default : -1 (4096)
// Result : Input Index in array -1 = error
chan := uos_InputGetChannels(PlayerIndex1, In1Index);
// Get the number of channels.
// no output because only decode the steam for wave form
// get the length of the audio file
filelength := uos_InputLength(PlayerIndex1, In1Index);
///// set calculation of level/volume into array (useful for wave form procedure)
uos_InputSetLevelArrayEnable(PlayerIndex1, In1Index, 2);
///////// set level calculation (default is 0)
// 0 => no calcul
// 1 => calcul before all DSP procedures.
// 2 => calcul after all DSP procedures.
//// determine how much frame will be designed
framewanted := filelength div paintbox2.Width;
uos_InputSetFrameCount(PlayerIndex1, In1Index, framewanted);
///// Assign the procedure of object to execute at end of stream
uos_EndProc(PlayerIndex1, @DrawWaveForm);
uos_Play(PlayerIndex1); /////// everything is ready, here we are, lets do it...
end
else
MessageDlg(edit4.Text + ' do not exist...', mtWarning, [mbYes], 0);
end;