Author Topic: Play back a recording whilst it is still in progress  (Read 124 times)

Ballinger

  • Posts: 50
Been struggling for a while with this one. I want to play back a recording from any given point whilst the recording is still ongoing. I have the recording side of things working fine... but I can't succeed with the playback. This is what I have so far.

function PlaybackCallback(Handle: HStream; buffer: Pointer; length: DWord; user: Pointer): DWord; stdcall;
begin
BASS_ChannelGetData(RecordStream, buffer, length);
end;

      PlaybackStream :=  BASS_StreamCreate(SampleFreq, ChannelCount, BASS_SAMPLE_FLOAT {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF}, @PlaybackCallback, nil);
      BASS_ChannelSetDevice(PlaybackStream, 1);
      BASS_ChannelSetAttribute(PlaybackStream, BASS_ATTRIB_BUFFER, 0);
      BASS_ChannelSetPosition(PlaybackStream, BufferClipInPoint, BASS_POS_BYTE);
      BASS_ChannelStart(PlaybackStream);

Not getting any errors, but not hearing anything either.
Any help would be greatly appreciated.

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 26077
If I understand correctly, you want to listen to the recorded data with some time delay rather than live? If so, your STREAMPROC should read from where you're storing the data rather than directly from the recording channel, eg. set a read pointer to where you want to start and advance that with each STREAMPROC call.

Ballinger

  • Posts: 50
Thanks for that Ian... I understand.
So now I have this:

function PlaybackCallback(Handle: HStream; buffer: Pointer; length: DWord; user: Pointer): DWord; stdcall;
var MemoryStreamPosition: Int64;
begin
MemoryStreamPosition := MemoryStream.Position;
MemoryStream.Position := PlayPointer;
MemoryStream.ReadBuffer(buffer^, length);
MemoryStream.Position := MemoryStreamPosition;
PlayPointer := PlayPointer + length;
end;

But the playback instantly stalls.

Any thoughts?
Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 26077
It doesn't look like your STREAMPROC function is setting a return value? That should be the amount of data that it placed in the buffer, ie. the "length" value if it has that much. Note it should check how much data it has available and limit the returned amount to that.

Ballinger

  • Posts: 50
Re: Play back a recording whilst it is still in progress
« Reply #4 on: 23 Sep '24 - 09:31 »
Thanks Ian... finally got back to this... and that sorted it! Thank you.