0

I'm trying to record an audio streaming using bass.net but using the documentation example i'm only able to record 5 seconds. How can i record more time?

Following is my code:

class Program
{
    private static FileStream _fs = null;
    private static DOWNLOADPROC _myDownloadProc;
    private static byte[] _data;

    static void Main(string[] args)
    {
        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
        _myDownloadProc = new DOWNLOADPROC(MyDownload);
        int stream = Bass.BASS_StreamCreateURL("http://m2.fabricahost.com.br:8704/;stream.mp3", 0,
                          BASSFlag.BASS_STREAM_BLOCK | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_STREAM_STATUS, _myDownloadProc, IntPtr.Zero);
    }

    private static void MyDownload(IntPtr buffer, int length, IntPtr user)
    {
        if (_fs == null)
        {
            // create the file
            _fs = File.OpenWrite("output.mp3");
        }
        if (buffer == IntPtr.Zero)
        {
            // finished downloading
            _fs.Flush();
            _fs.Close();
        }
        else
        {
            // increase the data buffer as needed
            if (_data == null || _data.Length < length)
                _data = new byte[length];
            // copy from managed to unmanaged memory
            Marshal.Copy(buffer, _data, 0, length);
            // write to file
            _fs.Write(_data, 0, length);
        }
    }
}

Thanks

Star
  • 3,222
  • 5
  • 32
  • 48
kozima
  • 45
  • 5
  • Documentation link: http://www.bass.radio42.com/help/html/1117c99d-24de-57c6-f6f4-9ac73059a608.htm – kozima Jan 17 '18 at 13:43

1 Answers1

0

I found out why, the bass.net default net buffer size is 5000ms(5 seconds). I just changed the size using Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_BUFFER, 10000); to record as much as i wanted.

kozima
  • 45
  • 5
  • Also, you need to play and add a delay time to keep recording. For example: `Bass.BASS_ChannelPlay(stream, false); Console.ReadLine();` – kozima Jan 22 '18 at 12:20