Author Topic: Record  (Read 114 times)


  • Guest
« on: 1 May '21 - 13:09 »
In my project, I need to get the sound from the microphone and same time send it to the server via UDP
The server receives a packet 960 bytes of data every 50 milliseconds
And I used the Bass.BASS_RecordStart method to record audio, but this method has a limitation that BASSConfig.BASS_CONFIG_REC_BUFFER can not be set outside the range of 1000 milliseconds to 5000 milliseconds.
How can I do this?help me please

Code: [Select]
if (Bass.BASS_RecordInit(-1))
 _myRecProc = new RECORDPROC(MyRecording);
   recHandle = Bass.BASS_RecordStart(9600, 1, BASSFlag.BASS_DEFAULT,50, _myRecProc, IntPtr.Zero);
   Bass.BASS_ChannelPlay(recHandle, false);

 private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
            bool cont = true;
            if (length > 0 && buffer != IntPtr.Zero)
                _recbuffer = new byte[length];
                 Marshal.Copy(buffer, _recbuffer, 0, length);
                  // Send packet to the server
                 udpSender.Send(_recbuffer, _recbuffer.Length);
            return cont;

Ian @ un4seen

  • Administrator
  • Posts: 23640
Re: Record
« Reply #1 on: 3 May '21 - 15:40 »
It sounds like the BASS_ATTRIB_GRANULE option is what you're looking for. If the recording is mono 16-bit then try setting that to 480 (for 960 bytes). Please see the BASS_ATTRIB_GRANULE documentation for details. Note that your RECORDPROC may receive multiple "granules", ie. a multiple of 960 bytes. If you need to process 960 bytes at a time then you will need to split the data accordingly in the RECORDPROC.

The BASS_CONFIG_REC_BUFFER setting determines the maximum amount of data that a recording's buffer can hold but the buffer will usually be much emptier than that (it will usually be emptied in each RECORDPROC call). So you don't really need to be concerned about that setting.