Author Topic: Start a recording after a threshold level  (Read 1018 times)

vsibilla

  • Posts: 11
Start a recording after a threshold level
« on: 14 Dec '23 - 15:55 »
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

  • Administrator
  • Posts: 26177
Re: Start a recording after a threshold level
« Reply #1 on: 15 Dec '23 - 13:15 »
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

  • Posts: 11
Re: Start a recording after a threshold level
« Reply #2 on: 17 Dec '23 - 09:23 »
thanks Ian

vsibilla

  • Posts: 11
Re: Start a recording after a threshold level
« Reply #3 on: 21 Mar '24 - 09:53 »
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

  • Administrator
  • Posts: 26177
Re: Start a recording after a threshold level
« Reply #4 on: 21 Mar '24 - 12:37 »
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:

Code: [Select]
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

  • Posts: 11
Re: Start a recording after a threshold level
« Reply #5 on: 2 Apr '24 - 10:03 »
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

  • Administrator
  • Posts: 26177
Re: Start a recording after a threshold level
« Reply #6 on: 2 Apr '24 - 15:37 »
Perhaps the "threshold" value is too high? You could try lowering it. If the problem persists, please post your RECORDPROC function.

radio42

  • Posts: 4840
Re: Start a recording after a threshold level
« Reply #7 on: 2 Apr '24 - 17:06 »
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...
« Last Edit: 3 Apr '24 - 11:05 by radio42 »