Author Topic: Playing Received Buffer to stream  (Read 705 times)

nikos

  • Posts: 63
Playing Received Buffer to stream
« on: 4 Aug '19 - 11:02 »
Hi all.

i am trying to do a voice udp chat program in delphi.
I toll the sample code rectest and i did the follow.

On startrecording function I create a channel named playchan

Code: [Select]
playchan :=  BASS_StreamCreate(44100, 1, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF} , STREAMPROC_PUSH, nil);
BASS_ChannelPlay(playchan, false);




On record procedure @recordACM i did the follow

Code: [Select]
function recordACM(channel: HENCODE; chan:DWORD;buffer: Pointer; len:DWORD; user: DWORD): Boolean; stdcall;
begin
UDPCLIENT.SendBuffer('192.168.1.20', 4646, RawToBytes(buffer, sizeOf(buffer)));
end;

and on server side on recive data i did

Code: [Select]
BASS_StreamPutData(playchan, adata, sizeof(adata));
adata is the buffer of TidBytes

i start record the microphone and all i here is TICK  TICK  TICK  TICK  TICK   TICK  TICK  TICK

what i am doing wrong?
 









MB_SOFT

  • Posts: 384
Re: Playing Received Buffer to stream
« Reply #1 on: 4 Aug '19 - 17:45 »
you should send uncompressed mono 16bit samples data, is it so?

nikos

  • Posts: 63
Re: Playing Received Buffer to stream
« Reply #2 on: 5 Aug '19 - 07:12 »
No I dont care about hertz.
All i want is to Transfer and play the Stream but i hear tik tak tik tak and no sound.

MB_SOFT

  • Posts: 384
Re: Playing Received Buffer to stream
« Reply #3 on: 5 Aug '19 - 11:28 »
BASS_StreamCreate(44100, 1, function expect uncompressed sample data.  If your buffer is compressed data you should use BASS_StreamCreateFileUser

nikos

  • Posts: 63
Re: Playing Received Buffer to stream
« Reply #4 on: 5 Aug '19 - 13:35 »
i will add full code now to see where is my mystake thank you.

nikos

  • Posts: 63
Re: Playing Received Buffer to stream
« Reply #5 on: 5 Aug '19 - 13:38 »
i will add full code now to see where is my mystake thank you.

here is the code

Code: [Select]
function RecordingCallback(channel: HRECORD; buffer: Pointer; length, user: DWORD): Boolean; stdcall;
begin
form1.xudp.SendBuffer(xhost, xport,RawToBytes(buffer, length));
result:=true;
end;




RECORD BUTTON1 On Click
------------------------------------------

Code: [Select]
  if (chan <> 0) then // free old recording
  begin
    BASS_StreamFree(chan);
    chan := 0;
  end;

  rchan := BASS_RecordStart(44100, 1, BASS_RECORD_PAUSE, @RecordingCallback, 0);
  if rchan = 0 then
  begin
    Error('Couldn''t start recording');
    Exit;
  end;

  BASS_ChannelPlay(rchan, FALSE); // resume recoding



playchan :=  BASS_StreamCreate(44100, 1, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF} , STREAMPROC_PUSH, nil);
BASS_ChannelPlay(playchan, false);





And here is the UDP onRead Server

Code: [Select]
procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
 begin
BASS_StreamPutData(playchan, adata, length(adata));
end;
« Last Edit: 5 Aug '19 - 13:50 by nikos »

Ian @ un4seen

  • Administrator
  • Posts: 22829
Re: Playing Received Buffer to stream
« Reply #6 on: 5 Aug '19 - 14:11 »
The BASS calls there look fine, but I'm not familiar with the Delphi UDP stuff, so I don't know if that stuff is fine too. To help locate where the problem is, can you try writing the received data to a file (in the TForm1.IdUDPServer1UDPRead function) and then see if that file sounds OK in a sample editor?

Are you recording from a microphone, and playing it on speakers in the same room? If so, you may get some feedback. You could try using headphones in that case.

nikos

  • Posts: 63
Re: Playing Received Buffer to stream
« Reply #7 on: 5 Aug '19 - 14:55 »
I Save The data and they dont have a header they cannot be played.


« Last Edit: 5 Aug '19 - 15:07 by nikos »

Ian @ un4seen

  • Administrator
  • Posts: 22829
Re: Playing Received Buffer to stream
« Reply #8 on: 5 Aug '19 - 15:42 »
Most sample editing software will be able to load raw PCM files. For example, Audacity has a File > Import > Raw Data menu option.

nikos

  • Posts: 63
Re: Playing Received Buffer to stream
« Reply #9 on: 5 Aug '19 - 15:46 »
I FIX it !!!!!
I put BASS_StreamPutData(playchan, AData, length(adata));
instead of

BASS_StreamPutFileData(playchan, @AData, length(adata)); and is Playing Now i will try to Encode it so i will not have WAV but something smaller.