This works, but not the way it should. The output is kind of "truncated", i get only few pieces of the sound being inputed.
I tried to enable the BASSFlag.BASS_MUSIC_PRESCAN on the BASS_RecordStart method and it worked, but not for long. After a few minutes of reproducing I get the same noisy sound.
Any suggestions?
The BASS_MUSIC_PRESCAN flag doesn't apply to BASS_RecordStart. What you're actually doing with that flag is lowering the recording period (the time between RECORDPROC calls). The HIWORD of the "flags" parameter can be used to set the recording period, and the BASS_MUSIC_PRESCAN flag (0x20000) sets that to 2.
It sounds like the problem you're having may be related to the output running out of data to play, ie. the playback buffer is empty. You could try pre-buffering some data before starting playback. The LIVEFX example (in the BASS package) does that like this...
BASS_INFO bi;
// initialize output, get latency
if (!BASS_Init(-1,44100,BASS_DEVICE_LATENCY,win,NULL)) {
Error("Can't initialize output");
return FALSE;
}
BASS_GetInfo(&bi);
...
// create a stream to play the recording
chan=BASS_StreamCreate(44100,2,0,STREAMPROC_PUSH,0);
// start recording with 10ms period
if (!BASS_RecordInit(-1) || !(rchan=BASS_RecordStart(44100,2,MAKELONG(0,10),RecordingCallback,0))) {
BASS_RecordFree();
BASS_Free();
Error("Can't initialize recording");
return FALSE;
}
...
{ // prebuffer at least "minbuf" amount of data before starting playback
DWORD prebuf=BASS_ChannelSeconds2Bytes(chan,bi.minbuf/1000.f);
while (BASS_ChannelGetData(chan,NULL,BASS_DATA_AVAILABLE)<prebuf)
Sleep(1);
}
BASS_ChannelPlay(chan,FALSE);
The strange thing is that the output sound is perfectly clear at the beginning, but after a few minutes it starts distorting (like when the bass volume is too high).
If the problem only happens after some time, then it could be that the recording and playback are going at slightly different speeds (are both using the same soundcard?), eg. if the playback is going faster than the recording then it will eventually run out of data to play and start stuttering. Does the noise you hear sound like stuttering?