It looks like you want to forward the input to the output? There are a few changes that I would suggest. Firstly, you can remove the low BASS_CONFIG_UPDATEPERIOD and BASS_CONFIG_BUFFER settings, as there is no benefit in setting them low when using a "push" stream. Secondly, to reduce latency in the recording, you can specify an update period in the BASS_RecordStart call (HIWORD of "flags" parameter). Thirdly, you should pre-buffer some data before starting the output, otherwise the output could be stuttering due to a lack of data to play. You can use the "info.minbuf" value to decide how much to pre-buffer. The modified code could look something like this...
using System;
using Un4seen.Bass;
namespace SimpleAudio
{
class MainClass
{
private static RECORDPROC _recordingCallback;
private static int _streamChannel;
//private static int _recordChannel;
private static int _prebuf;
private const int _inputDevice=-1; //DISPOSITIVO DE ENTRADA -1 = POR DEFECTO
private const int _outputDevice=-1; //DISPOSITIVO DE SALIDA -1 = POR DEFECTO
public static void Main (string[] args)
{
BassNet.Registration ("XXXXXXXXX", "XXXXXXXXXX");
int version=Bass.BASS_GetVersion();
Console.WriteLine("BASS VERSION: "+version);
_recordingCallback = OnAudioData;
if (!Bass.BASS_Init (_outputDevice, 44100, BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero)) { //256
//SI NO SE HA PODIDO INICIALIZAR SALIMOS Y MOSTRAMOS MENSAJE
Console.WriteLine ("Can't initialize output device!!");
return;
}
var info = new BASS_INFO();
if (!Bass.BASS_GetInfo(info))
{
System.Diagnostics.Debug.WriteLine("Can't get information!!");
return;
}
_streamChannel = Bass.BASS_StreamCreate(44100, 2,0, BASSStreamProc.STREAMPROC_PUSH);
_prebuf = BASS_ChannelSeconds2Bytes(_streamChannel, info.minbuf/1000.f); // amount of data to pre-buffer
bool recordInitOk = Bass.BASS_RecordInit(_inputDevice);
Bass.BASS_RecordStart(44100, 2, MAKELONG(0, 10), _recordingCallback, IntPtr.Zero); // start recording with 10ms period
if ((!recordInitOk))
{
Bass.BASS_RecordFree();
Bass.BASS_Free();
System.Diagnostics.Debug.WriteLine("Can't initialize recording device");
return;
}
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
Bass.BASS_Stop();
Bass.BASS_RecordFree();
Bass.BASS_Free();
return;
}
private static bool OnAudioData(int handle, IntPtr buffer, int length, IntPtr user)
{
//COGEMOS EL BUFFER DE ENTRADA Y LO PONEMOS EN EL STREAM DE AUDIO DE SALIDA
Bass.BASS_StreamPutData(_streamChannel, buffer, length);
if (_prebuf && Bass.BASS_ChannelGetData(_streamChannel, 0, BASS_DATA_AVAILABLE)>=_prebuf) { // pre-buffered the wanted amount of data
Bass.BASS_ChannelPlay(_streamChannel, false); // start playing
_prebuf = 0; // done pre-buffering
}
return true;
}
}
}
If you still get problems (eg. stuttering output), you can try increasing the pre-buffer amount.