1 #ifndef AUDIOGRAPHER_SILENCE_TRIMMER_H
2 #define AUDIOGRAPHER_SILENCE_TRIMMER_H
26 threshold = dB > -318.8f ? pow (10.0f, dB * 0.05f) : 0.0f;
29 return fabsf (d) <= threshold;
37 template<
typename T = DefaultSampleType>
52 reset (silence_buffer_size_);
70 "Silence trimmer constructor and reset() must be called with a non-zero parameter!");
97 throw Exception(*
this,
"Tried to add silence to beginning after processing started");
109 throw Exception(*
this,
"Tried to add silence to end after processing started");
121 throw Exception(*
this,
"Tried to set beginning trim after processing started");
133 throw Exception(*
this,
"Tried to set end trim after processing started");
147 "::process()" << std::endl;
153 throw Exception(*
this,
"process() after reaching end of input");
181 output_start_index = first_non_silent_sample_index;
182 output_sample_count = c.
samples() - first_non_silent_sample_index;
213 assert (samples_before_silence + silent_end_samples == c.
samples ());
216 output_sample_count = samples_before_silence - output_start_index;
224 output_sample_count = 0;
262 result_sample -= result_sample % c.
channels();
281 for (
samplecnt_t i = last_sample_index; i >= 0; --i) {
285 result_sample -= result_sample % c.
channels();
298 while (total_samples > 0) {
305 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)