bobby

About

Username
bobby
Joined
Visits
9
Last Active
Roles
Member
Points
1
  • How to process an audio data from KiwiSDR on C#?

    I resolve it!Uhhhuuu....)

    here is my c# code

    correct settings

    await SendCommand("SET auth t=kiwi p= ");

    await SendCommand("SET AR OK in=12000 out=12000");

    await SendCommand("SET squelch=0 max=0");

    await SendCommand("SET genattn=0");

    await SendCommand("SET gen=0 mix=-1");

    await SendCommand("SET ident_user=kiwibob");

    await SendCommand("SET mod=usb low_cut=0 high_cut=6000 freq=10100.000");

    await SendCommand("SET agc=1 hang=0 thresh=-110 slope=6 decay=1000 manGain=50");

    await SendCommand("SET compression=0");

    await SendCommand("SET keepalive");


    code for process byte array, received from KiwiSDR

     var buffer = new byte[4096];

     while (true)

     {

       var result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);


       if (result.MessageType == WebSocketMessageType.Close)

       {

         await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);

         break;

       }


       if (result.MessageType == WebSocketMessageType.Binary)

       {


         if (Encoding.ASCII.GetString(buffer, 0, 3) == "SND")

         {

           int audioLength = result.Count - 16;

           if (audioLength <= 0) return;


           byte[] audioBytes = new byte[audioLength];

           Array.Copy(buffer, 16, audioBytes, 0, audioLength);


           // Convert from Big Endian to Little Endian

           for (int i = 0; i < audioBytes.Length; i += 2)

           {

             byte tmp = audioBytes[i];

             audioBytes[i] = audioBytes[i + 1];

             audioBytes[i + 1] = tmp;

           }


           audioPlayer.provider.AddSamples(audioBytes, 0, audioBytes.Length);

         }

         

       }


    Settings for WaveOut

    class KiwiAudioPlayer

    {

      public BufferedWaveProvider provider;

      private WaveOutEvent waveOut;



      public KiwiAudioPlayer()

      {

        var waveFormat = new WaveFormat(12000,16, 1); // 12kHz, 16-bit, Mono

        provider = new BufferedWaveProvider(waveFormat)

        {    

          DiscardOnBufferOverflow = true

        };


        waveOut = new WaveOutEvent();

        waveOut.Init(provider);

        waveOut.Play();

      }


      public void AddAudioBytes(byte[] audioBytes)

      {

        provider.AddSamples(audioBytes, 0, audioBytes.Length);

      }


      public void Stop()

      {

        waveOut?.Stop();

        waveOut?.Dispose();

      }

    }

    Thank U!

    F5AFY