Search code examples
c#bass

Bass.net DOWNLOADPROC only record 5 seconds


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


Solution

  • 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.