Author Topic: BASS for Android DELPHI XE10  (Read 258 times)

ddreal

  • Posts: 2
BASS for Android DELPHI XE10
« on: 8 Jul '18 - 12:56 »
Good day forum users.
Im sorry for my english. ::)
I need a little help understanding how to compress sound.
I'm writing something like a voice messenger on Delphi XE10 for Android.

Record and transmit sound on the network turned out, but I can not compress the sound. More precisely, I do not understand how to use BASSenc to compress the sound of any codec. Here's a piece of code to record and transmit.

Code: [Select]
function RecCallback(Handle: HRECORD; buffer: Pointer; size, user: DWord): boolean; stdcall;
 var
  SenBuff:TIdBytes;
begin

  WaveStream.WriteBuffer(buffer^, size);  // Copy new buffer contents to the memory buffer
  if WaveStream.Size>8000 then
   Begin
// -- save end wav
     WaveStream.Position := 4;
      i := WaveStream.Size - 8;
      WaveStream.Write(i, 4);
      i := i - $24;
      WaveStream.Position := 40;
      WaveStream.Write(i, 4);
      WaveStream.Position := 0;
// -- save end wav
     leng:=WaveStream.Size;


     // WaveStream.SaveToFile(FormMain.pathfile+'record'+IntToStr(cnt)+'.wav'); // save record on device
    //  inc(cnt);

     SetLength(SenBuff,leng);
     WaveStream.ReadBuffer(SenBuff[0],leng);

    try
     UDPAudioClient.SendBuffer(UDPAudioClient.Host,UDPAudioClient.Port,SenBuff);
    finally

    end;
     WaveStream.Clear;
      with WaveHdr do  // insert begin wav header
        begin
       // riff := Hex2Byte('RIFF');
        riff[0]:=Ord('R');
        riff[1]:=Ord('I');
        riff[2]:=Ord('F');
        riff[3]:=Ord('F');
        len := 36;
     //   cWavFmt := Hex2Byte('WAVEfmt ');
        cWavFmt[0] := Ord('W');
        cWavFmt[1] := Ord('A');
        cWavFmt[2] := Ord('V');
        cWavFmt[3] := Ord('E');
        cWavFmt[4] := Ord('f');
        cWavFmt[5] := Ord('m');
        cWavFmt[6] := Ord('t');
        cWavFmt[7] := Ord(' ');
        dwHdrLen := 16;
        wFormat := 1;
        wNumChannels := 2;
        dwSampleRate := 8000;
        wBlockAlign := 4;
        dwBytesPerSec := 56400;
       // dwBytesPerSec := 176400;
        wBitsPerSample := 8;
        //cData := Hex2Byte('data');
        cData[0] := Ord('d');
        cData[1] := Ord('a');
        cData[2] := Ord('t');
        cData[3] := Ord('a');
        dwDataLen := 0;
        end;

    WaveStream.Write(WaveHdr, SizeOf(WaveHdr));
   End;
  Result:=True;
end;
Its full work code. Maybe this code will help other users for their projects..
 Please help me. Best regards me... ??? ??? ??? ???

Ian @ un4seen

  • Administrator
  • Posts: 21325
Re: BASS for Android DELPHI XE10
« Reply #1 on: 9 Jul '18 - 17:47 »
When encoding recorded sample data with the BASSenc add-on, you would generally just set an encoder on the recording channel (eg. via BASS_Encode_Start) and not do anything special in your RECORDPROC callback function (eg. just return "true" in there). Depending on the encoding format that you want, the easiest way to do it is with the BASSenc_FLAC/OGG/OPUS add-ons. A similar BASSenc_MP3 add-on will also be available soon.

If you want to transmit the encoded data, you may also want to have a look at BASSenc's built-in server feature, eg. BASS_Encode_ServerInit. Please see the documentation for details.

ddreal

  • Posts: 2
Re: BASS for Android DELPHI XE10
« Reply #2 on: 9 Jul '18 - 18:18 »
Thanks for the reply!!!.
Im found a solution.
i useв BASSens_OGG and got an excellent result.

Thank you for developing such a wonderful tool.
 :) :) :)