I decided not to use the BASS_StreamCreateFileUser vs. BASS_StreamPutFileData scheme. Because the noise problem could not be solved for the time being, but soon I found another way to solve the problem: Since these sound data are AI voice data, there must be a pause in the middle of the sentence, so I searched for the silent data in the MP3 data frame. , and soon found the data tag "FFF3E4C400000003", so when I receive these data, I save all fragmented data in a complete data stream, and use a list to save the start position and end position of different sentences, when the list When the number of buffers in the memory is suitable, a timer event is triggered, and the playback memory stream is controlled in the timer event. This only needs to use the conventional method:
procedure TForm1.Timer1Timer(Sender: TObject);
var iLen,i:integer;
begin
if Mp3treamFull=nil then exit;
FLock.Enter;
iLen:= Length(List);
if iLen=0 then exit;
if BASS_ChannelIsActive(Fhs)<> BASS_ACTIVE_PLAYING then
begin
for I := 0 to iLen-1 do
begin
if (List[i].start>-1) and (List[i].end>-1) and (not List[i].IsPlayed) then
begin
List[i].IsPlayed:= true;
BASS_StreamFree(Fhs);
if mem=nil then mem:= TMemoryStream.Create;
mem.Clear;
Mp3treamFull.Position:= List[i].start;
mem.CopyFrom(Mp3treamFull, List[i].end-List[i].start);
Fhs := BASS_StreamCreateFile(True, mem.Memory , 0, mem.Size, 0);
BASS_ChannelPlay(Fhs, false);
if (I = iLen-1) then Timer1.Enabled:= false;
break;
end;
end;
end;
FLock.Exit();
Application.ProcessMessages;
end;
now, you can hear clear sound, perfect, don't have to worry about too many other technical details, all manage the cache data by yourself.
Summarizing experience: BASS_StreamCreateFileUser and BASS_StreamPutFileData are based on data frame push streaming, and there are many technical difficulties. The solution I am using now is to synthesize the fragmented data frame into a sentence, cache the corresponding location information, and then play it with a timer