1 #ifndef AUDIOGRAPHER_SILENCE_TRIMMER_H
2 #define AUDIOGRAPHER_SILENCE_TRIMMER_H
23 threshold = dB > -318.8f ? pow (10.0f, dB * 0.05f) : 0.0f;
26 return fabsf (d) <= threshold;
34 template<
typename T = DefaultSampleType>
49 reset (silence_buffer_size_);
67 "Silence trimmer constructor and reset() must be called with a non-zero parameter!");
94 throw Exception(*
this,
"Tried to add silence to beginning after processing started");
106 throw Exception(*
this,
"Tried to add silence to end after processing started");
118 throw Exception(*
this,
"Tried to set beginning trim after processing started");
130 throw Exception(*
this,
"Tried to set end trim after processing started");
144 "::process()" << std::endl;
150 throw Exception(*
this,
"process() after reaching end of input");
178 output_start_index = first_non_silent_sample_index;
179 output_sample_count = c.
samples() - first_non_silent_sample_index;
210 assert (samples_before_silence + silent_end_samples == c.
samples ());
213 output_sample_count = samples_before_silence - output_start_index;
221 output_sample_count = 0;
259 result_sample -= result_sample % c.
channels();
278 for (
samplecnt_t i = last_sample_index; i >= 0; --i) {
282 result_sample -= result_sample % c.
channels();
295 while (total_samples > 0) {
302 total_samples -= samples;
A wrapper for a const ProcesContext which can be created from const data.
std::ostream & debug_stream()
bool debug_level(DebugLevel level)
A debugging class for nodes that support a certain set of flags.
void check_flags(SelfType &self, ProcessContext< ContextType > context)
Prints debug output if context contains flags that are not supported by this class.
void add_supported_flag(Flag flag)
Adds a flag to the set of flags supported.
An generic Source that uses a std::list for managing outputs.
void output(ProcessContext< T > const &c)
Helper for derived classes.
ChannelCount const & channels() const
bool has_flag(Flag flag) const
T const * data() const
data points to the array of data to process
samplecnt_t const & samples() const
samples tells how many samples the array pointed by data contains
void set_flag(Flag flag) const
void remove_flag(Flag flag) const
Removes and adds silent samples to beginning and/or end of stream.
void add_silence_to_end(samplecnt_t samples_per_channel)
samplecnt_t add_to_beginning
samplecnt_t silence_samples
void set_trim_beginning(bool yn)
void set_trim_end(bool yn)
samplecnt_t max_output_frames
void add_silence_to_beginning(samplecnt_t samples_per_channel)
bool find_last_silent_sample_reverse(ProcessContext< T > const &c, samplecnt_t &result_sample)
void reset(samplecnt_t silence_buffer_size_=1024)
void output_silence_samples(ProcessContext< T > const &c, samplecnt_t &total_samples)
bool find_first_non_silent_sample(ProcessContext< T > const &c, samplecnt_t &result_sample)
SilenceTrimmer(samplecnt_t silence_buffer_size_=1024, float thresh_dB=-INFINITY)
Constructor,.
SilenceTester< T > tester
void process(ProcessContext< T > const &c)
samplecnt_t silence_buffer_size
bool throw_level(ThrowLevel level)
static void zero_fill(T *buffer, samplecnt_t samples)
@ ThrowObject
Object level stuff, ctors, initalizers etc.
@ ThrowStrict
Stricter checks than ThrowProcess, less than ThrowSample.
@ DebugVerbose
Lots of output, not on sample level.
static std::string demangled_name(T const &obj)
Returns the demangled name of the object passed as the parameter.
bool is_silent(const float d)
SilenceTester(const float dB)