Playing the stream on the fly (tcp / udp)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Playing the stream on the fly (tcp / udp)

Samuel
This post was updated on .
In one application, I send audio over the network.
In the second application I receive the data and save it to a file, the file can be played:

$ mplayer -demuxer rawaudio test.wav

It works.

And now I'm trying to play it on the fly using UOS.
No combinations work for me. Fragments of what I am saying can be heard and then it crashes.

How to play such a stream on the fly?


I use a proprietary component that I use to control the UOS: http://studiojahu.duckdns.org/pliki/uos_components.tgz
Reply | Threaded
Open this post in threaded view
|

Re: Playing the stream on the fly (tcp / udp)

fredvs
Administrator
Hello Samuel.

> Fragments of what I am saying can be heard and then it crashes.

Could you give the code that you used?

Also upload the wav file that you want to play?

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Playing the stream on the fly (tcp / udp)

Samuel
This is my code:

Broadcasting data in socket tcp:

Create procedure:
procedure TFClient.FormCreate(Sender: TObject);
var
  v1,v2,v3,v4: integer;
begin
  CreatePipeStreams(muse_out,muse_in);
  ...
  (* uos *)
  if DirectoryExists(MyDir('uos')) then
  begin
    uos.Tag:=1;
    uos.LibDirectory:=MyDir('uos');
  end;
  if uos.Tag=1 then uELED4.Active:=uos.LoadLibrary;
  ...
end;

And code to send media for tcp:

  "A." mic.Start(TMemoryStream(muse_in));  //--->
 
      uos_CreatePlayer(xindex);
      if aMemoryStream=nil then uos_AddIntoFile(xindex,Pchar(FFileName))
      else uos_AddIntoMemoryStream(xindex,aMemoryStream,-1,-1,-1,-1);
      {function uos_AddIntoMemoryStream(PlayerIndex: cint32; MemoryStream: TMemoryStream; SampleRate: LongInt;
             SampleFormat: LongInt ; Channels: LongInt; FramesCount: LongInt): LongInt;
       Add a Output into TMemoryStream
       Parameters:
         2. MemoryStream : the TMemoryStream to use to store memory.
         3. SampleRate : delault : -1 (44100)
         4. SampleFormat : default : -1 (2:Int16) ( 1:Int32, 2:Int16)
         5. Channels : delault : -1 (2:stereo) (0: no channels, 1:mono, 2:stereo, ...)
         6. FramesCount : default : -1 (= 4096)
      }
      outindex:=uos_AddIntoDevOut(xindex);
      uos_outputsetenable(xindex,outindex,FListenMic);
      InIndex:=uos_AddFromDevIn(xindex);  /// add Input from mic into IN device with default parameters
      uos_InputAddDSPVolume(xindex,InIndex, 1, 1);
      uos_InputSetDSPVolume(xindex,InIndex,FVolume,FVolume,True); /// Set volume

  "B." LOOP SENDING TO SOCKET TCP:

  procedure TFClient.tloopTimer(Sender: TObject);
  const
    BUFFER_SIZE = 65536;
  var
    cc,n,i: integer;
    buf: array [0..BUFFER_SIZE-1] of byte;
  begin
    cc:=muse_out.NumBytesAvailable;
    if cc=0 then exit;
    if cc>65536 then cc:=65536;
    n:=muse_out.Read(buf,cc);
    if n>0 then muse.SendBinary(buf,n);
    writeln('Sending: ',n);
  end;

And receiver of data in fly:

  Declaration (private):
        muse_full: TMemoryStream;
        muse_in: TOutputPipeStream;
        muse_out: TInputPipeStream;

  procedure TFServer.museReceive(aSocket: TLSocket);
  const
    BUFFER_SIZE = 65536;
  var
    n,i: integer;
    buf: array [0..BUFFER_SIZE-1] of byte;
  begin
    n:=aSocket.Get(buf,BUFFER_SIZE);
    muse_in.WriteBuffer(buf,n);
    if (not rozmowa.Busy) and (muse_count=0) then
    begin
      play.Start(TMemoryStream(muse_out));  /* Look down */
    end;
    inc(muse_count);
  end;

PLAY.START(...) -->
    uos_CreatePlayer(xindex);

    if aMemoryStream=nil then InIndex:=uos_AddFromFile(xindex,Pchar(FFileName)) else
    if FPlayRawMode then
    begin
      uos_CustBufferInfos(Bufferinfos,44100,2,2,-1);
      InIndex:=uos_AddFromMemoryStreamDec(xindex,aMemoryStream,Bufferinfos,-1,-1);
    end else InIndex:=uos_AddFromMemoryStream(xindex,aMemoryStream,-1,-1,-1,-1);
   
 OutIndex:=uos_AddIntoDevOut(xindex,-1,-1,uos_InputGetSampleRate(xindex,InIndex),uos_InputGetChannels(xindex,InIndex),-1,-1,-1);
    uos_InputAddDSP1ChanTo2Chan(xindex,InIndex);
    uos_InputAddDSPVolume(xindex,InIndex,1,1);
    uos_InputSetDSPVolume(xindex,InIndex,a,a,true); /// Set volume
    uos_EndProc(xindex,@ClosePlayer);

    //for cc:=1 to 200 do
    //begin
    //  sleep(10);
    //  if assigned(FProcessMessage) then FProcessMessage;
    //end;

    if FNoFreeOnStop then uos_PlayNoFree(xindex) else uos_Play(xindex);  /////// everything is ready to play...
  end ....

Reply | Threaded
Open this post in threaded view
|

Re: Playing the stream on the fly (tcp / udp)

Samuel
Hello Fre!

The wav file does not exist. In one application I create a stream from a microphone, in the other I want to receive it. Everything in real time.

It seems to me that the indicated stream length is a problem, and here the length is not known.
Reply | Threaded
Open this post in threaded view
|

Re: Playing the stream on the fly (tcp / udp)

Samuel
Everything is already working!
It turned out I was taking a break too late to load the buffer.
When playing with TMemoryStream - it works.

I am still wondering if this will work for creating two pipes:
    muse_in: TOutputPipeStream;
    muse_out: TInputPipeStream;

But I will test it myself, thanks for your help!