Author Topic: artifact/noise/glitch at first seconds after starting recording  (Read 241 times)

mkllc

  • Posts: 17
In a small app I record from two different sources (speakers loopback + microphone) using one mixer and then encode it to vorbis. The problem is the first 2 seconds of the recording have a very loud noise/glitch/artifact, looks like buffer stuttering or something similar, at very big volume. Maybe I messed anything on buffering time? I increased them to 1-2 seconds (1 at this moment) to avoid gitch during the recording. After this annoying noise at first second/s of the file the rest of the recording goes flawless and with full quality.

Any tip or advice on which can be the cause? Thanks

Ian @ un4seen

  • Administrator
  • Posts: 23305
To narrow down where the problem is, try writing a WAV file instead of an OGG file, ie. using the BASS_ENCODE_PCM flag with BASS_Encode_Start. If the WAV file is unaffected then check what options you're using with the OGG encoder. A common cause of noise at the start of an encoding is when the encoder's options tell it to expect raw PCM data but the BASS_ENCODE_NOHEAD flag isn't used to tell BASSenc that.

mkllc

  • Posts: 17
After some tests definitely should be something related with buffering or mixing. I did the tests and the glitch/stuttering is still there. Even happens if I pause/unpause the recording. Should be any rule I had to follow to set the recording buffer from a device that can interfere in the behavior of a mixer or encoder? thanks

Ian @ un4seen

  • Administrator
  • Posts: 23305
Is the problem in the loopback or microphone recording, or both? If you're unsure, you could mute each in turn by setting its BASS_ATTRIB_VOL to 0 (via BASS_ChannelSetAttribute). Please also show your BASS_Mixer_StreamCreate and BASS_Mixer_StreamAddChannel calls.

mkllc

  • Posts: 17
At least for sure on the loopback as the microphone input starts stopped in the mixer at the start point, you have to push the "talk" button to set the BASS_ChannelPlay(mchan, FALSE) and  BASS_ChannelSetAttribute(mchan, BASS_ATTRIB_VOL, 1);

The current code:

Code: [Select]
BASS_SetConfig(BASS_CONFIG_REC_BUFFER, 2000);
BASS_SetConfig(BASS_CONFIG_BUFFER, 2000);
BASS_RecordSetDevice(loopback);
rchan = BASS_RecordStart(44100, 2, BASS_RECORD_PAUSE | BASS_SAMPLE_FLOAT, NULL, NULL);
BASS_RecordSetDevice(mic);
mchan = BASS_RecordStart(44100, 1, BASS_RECORD_PAUSE | BASS_SAMPLE_FLOAT, NULL, NULL);
mixer = BASS_Mixer_StreamCreate(44100, 2, BASS_MIXER_NONSTOP | BASS_MIXER_CHAN_BUFFER | BASS_SAMPLE_FLOAT);
BASS_ChannelSetAttribute(mixer, BASS_ATTRIB_BUFFER, 1); // 1 second
BASS_SetConfig(BASS_CONFIG_MIXER_BUFFER, 1000);
BASS_Mixer_StreamAddChannel(mixer, rchan, BASS_MIXER_CHAN_BUFFER);
BASS_Mixer_StreamAddChannel(mixer, mchan, BASS_MIXER_CHAN_BUFFER);
BASS_Encode_OGG_Start(mixer, command_string, BASS_ENCODE_AUTOFREE, encode_proc_cb, output_file_ptr);
BASS_ChannelSetAttribute(mixer, BASS_ATTRIB_VOL, 0); // avoid mixer output to speakers
BASS_ChannelPlay(rchan, FALSE);
BASS_ChannelPlay(mixer, FALSE);
BASS_ChannelSetAttribute(rchan, BASS_ATTRIB_VOL, 1);

Loopback can also be an input from USB card and I'm 100% sure the problem will be there, but could be wrong.

Do you see anything wrong? in theory its a simple code, just mix two sources with enough buffer (1 to 2 seconds) to avoid any sound problem even in slow computers

note: there is a IF to check if devices accept float or not and choose the flag or not

Ian @ un4seen

  • Administrator
  • Posts: 23305
Is there actually a noise introduced, or is the recording just stuttering in the mixer output? If it's stuttering, that will be caused by the recording not having enough data buffered for the mixer. It should be possible to prevent it by setting the BASS_MIXER_CHAN_LIMIT flag on the recording (in its BASS_Mixer_StreamAddChannel call) and removing the BASS_MIXER_NONSTOP flag from the mixer. Please see the BASS_Mixer_StreamAddChannel documentation for details.

Btw, BASS_MIXER_CHAN_BUFFER isn't a valid flag for BASS_Mixer_StreamCreate - you will actually be setting BASS_MIXER_POSEX, which has the same 0x2000 value. A list of valid flags can be found in the documentation of each function.