Start a recording after a threshold level

Started by vsibilla,

vsibilla

Hi everyone,

is it possibile to start a recording after a threshold? I need to preserve the samples before this threshold.
Could you suggest the best solution to apply it?

Thanks
Valerio

Ian @ un4seen

Do you want to start writing to file when a recording reaches a certain level? If so, a simple way to do that would be to call BASS_ChannelGetLevel(Ex) in your RECORDPROC callback, and when that exceeds your threshold level then call BASS_Encode_Start to start the encoder. Note the encoder won't receive the current RECORDPROC call's data, so you should also call BASS_Encode_Write to send that to the encoder.


vsibilla

Hi Ian,
I tried to use it but I miss the first moments of the spoken word, what can I do?
thanks
Valerio

Ian @ un4seen

Did you use BASS_Encode_Write to send the first block of data to the encoder? If not, doing that will hopefully fix the problem. Something like this:

BOOL CALLBACK RecordProc(HRECORD handle, const void *buffer, DWORD length, void *user)
{
if (!encoder) { // haven't started encoding yet
float level;
BASS_ChannelGetLevelEx(handle, &level, 0.1, BASS_LEVEL_MONO); // get the level
if (level >= threshold) { // hit the threshold
encoder = BASS_Encode_Start(...); // start the encoder
BASS_Encode_Write(encoder, buffer, length); // send this block to it
}
}
return true;
}

vsibilla

Hi Ian,
 
I tried this method but I lose the first audio samples, like first 1 or 2 letters.
Could you suggest me another solution?
Thanks
Valerio

Ian @ un4seen

Perhaps the "threshold" value is too high? You could try lowering it. If the problem persists, please post your RECORDPROC function.

radio42

#7
I guess what you are looking for is to start the recording at a certain threshold, BUT effectively start the recording a few milliseconds before (as the threshold is actually reached late)?
In that case, you would need to buffer the data - as you can not really travel back in time when processing the recording in real-time. I.e. once the threshold is reached, use your buffered data to go back and use that 'historic' data for your encoding...e.g. first write the small buffered data and then write the real-time recorded data...
You can all handle this in your RecordProc (as Ian layed out). I.e. here you can keep (cache) your previous buffer and then also write that when you start your encoder...