type
TBuffer8 =
array[0..0]
of Byte;
PBuffer8 = ^TBuffer8;
var
FBuffer : PBuffer8;
procedure TEncoderFLAC.FeederThreadWorkerCallback(Thread: TMultiThreadThread; Parameters: TObject;
var Data: TObject;
var Results: TObject);
var
//Buffer : PSmallInt;
//Buffer : PBuffer8;
i, samples : LongWord;
FB : PFLACBuf;
FBU : PFLACUBuf;
B8 : PBuffer8;
B16 : PBuffer16;
B32 : PBuffer32;
Length : DWORD;
WorkMessage: TWorkMessage;
WorkResult : TWorkResult;
Timer : TWaitResult;
begin
WorkMessage := TWorkMessage.Create;
WorkMessage.ID := TWork(Data).ID;
WorkMessage.Text := '
Starting.';
WorkMessage.Status:= thStarting;
Thread.SendMessage(WorkMessage);
BitrateConverter.BitRate:= br8BitInteger;
repeat
Timer:= TWork(Data).TimeEvent.WaitFor(TWork(Data).TimeToWait);
if Timer = wrTimeout
then
begin
Length:= Bass_ChannelGetData(Channel_Source, FBuffer, FBlockSize * (FBitsPerSample
shr 3) * FChannels);
if Length = DW_ERROR
then
exit;
Length:= BitrateConverter.Process(FBuffer, Length, 32, true);
if (FBuffer <>
nil)
and (Length <> 0)
then
begin
Samples := (Length
shl 3)
div FBitsPerSample;
GetMem(
FB, Samples * SizeOF(FLAC__int32));
if FBitsPerSample = 8
then <<----------------------------------------------
begin
if FChannels = 1
then // Mono
begin
for i := 0
to Samples - 1
do
FB[i] := FBuffer[i]
shr 1;
end else
if FChannels = 2
then // Stereo
begin
for i := 0
to Samples - 1
do
FB[i] := FBuffer[i]
div 2;
end;
end else
if FBitsPerSample = 16
then
begin
B16 := @FBuffer[0];
for i := 0
to Samples - 1
do
FB[i] := B16[i];
end else
if FBitsPerSample = 24
then
begin
FBU := PFLACUBuf(
FB);
for i := 0
to Samples - 1
do
FBU[i] := (ShortInt(FBuffer[i * 3 + 2])
shl 16) + (FBuffer[i * 3 + 1]
shl 8) + (FBuffer[i * 3]);
end else
if FBitsPerSample = 32
then
begin
B32 := @FBuffer[0];
for i := 0
to Samples - 1
do
FB[i] := B32[i];
end;
if not FLAC__stream_encoder_process_interleaved(_encoder, @
FB[0], Samples
div FChannels)
then
raise Exception.Create('
Failed to encode data.');
FreeMem(
FB);
end;
end;
until
(Timer <> wrTimeout)
or
(Thread.Terminated);
//* If the thread is terminated in the mean time we can be notifyied
if Thread.Terminated
then
begin
WorkMessage := TWorkMessage.Create;
WorkMessage.ID := TWork(Data).ID;
if Assigned(TWork(Data).TimeEvent)
then // test
TWork(Data).TimeEvent.SetEvent;
TWork(Data).TimeEvent.Free;
WorkMessage.Text := '
Terminated.';
WorkMessage.Status:= thTerminated;
Thread.SendMessage(WorkMessage);
Exit;
end;
WorkResult := TWorkResult.Create;
WorkResult.ID := TWork(Data).ID;
if Assigned(TWork(Data).TimeEvent)
then
TWork(Data).TimeEvent.SetEvent;
TWork(Data).TimeEvent.Free;
WorkResult.Text := '
Finished Successfuly.';
WorkResult.Status:= thFinished;
Results := WorkResult;
end;