diff options
Diffstat (limited to 'libs/audiographer/audiographer/general/silence_trimmer.h')
-rw-r--r-- | libs/audiographer/audiographer/general/silence_trimmer.h | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/libs/audiographer/audiographer/general/silence_trimmer.h b/libs/audiographer/audiographer/general/silence_trimmer.h index a715feb0c8..7e8d3c485c 100644 --- a/libs/audiographer/audiographer/general/silence_trimmer.h +++ b/libs/audiographer/audiographer/general/silence_trimmer.h @@ -47,14 +47,14 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer throw Exception (*this, "Silence trimmer constructor and reset() must be called with a non-zero parameter!"); } - + if (silence_buffer_size != silence_buffer_size_) { silence_buffer_size = silence_buffer_size_; delete [] silence_buffer; silence_buffer = new T[silence_buffer_size]; TypeUtils<T>::zero_fill (silence_buffer, silence_buffer_size); } - + in_beginning = true; in_end = false; trim_beginning = false; @@ -64,7 +64,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer add_to_beginning = 0; add_to_end = 0; } - + /** Tells that \a frames_per_channel frames of silence per channel should be added to beginning * Needs to be called before starting processing. * \n RT safe @@ -76,7 +76,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer } add_to_beginning = frames_per_channel; } - + /** Tells that \a frames_per_channel frames of silence per channel should be added to end * Needs to be called before end is reached. * \n RT safe @@ -88,7 +88,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer } add_to_end = frames_per_channel; } - + /** Tells whether ot nor silence should be trimmed from the beginning * Has to be called before starting processing. * \n RT safe @@ -100,7 +100,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer } trim_beginning = yn; } - + /** Tells whether ot nor silence should be trimmed from the end * Has to be called before the is reached. * \n RT safe @@ -124,9 +124,9 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer debug_stream () << DebugUtils::demangled_name (*this) << "::process()" << std::endl; } - + check_flags (*this, c); - + if (throw_level (ThrowStrict) && in_end) { throw Exception(*this, "process() after reaching end of input"); } @@ -134,27 +134,27 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer // If adding to end, delay end of input propagation if (add_to_end) { c.remove_flag(ProcessContext<T>::EndOfInput); } - + framecnt_t frame_index = 0; - + if (in_beginning) { - + bool has_data = true; - + // only check silence if doing either of these // This will set both has_data and frame_index if (add_to_beginning || trim_beginning) { has_data = find_first_non_zero_sample (c, frame_index); } - + // Added silence if there is silence to add if (add_to_beginning) { - + if (debug_level (DebugVerbose)) { debug_stream () << DebugUtils::demangled_name (*this) << " adding to beginning" << std::endl; } - + ConstProcessContext<T> c_copy (c); if (has_data) { // There will be more output, so remove flag c_copy().remove_flag (ProcessContext<T>::EndOfInput); @@ -162,54 +162,54 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer add_to_beginning *= c.channels(); output_silence_frames (c_copy, add_to_beginning); } - + // If we are not trimming the beginning, output everything // Then has_data = true and frame_index = 0 // Otherwise these reflect the silence state if (has_data) { - + if (debug_level (DebugVerbose)) { debug_stream () << DebugUtils::demangled_name (*this) << " outputting whole frame to beginning" << std::endl; } - + in_beginning = false; ConstProcessContext<T> c_out (c, &c.data()[frame_index], c.frames() - frame_index); ListedSource<T>::output (c_out); } - + } else if (trim_end) { // Only check zero samples if trimming end - + if (find_first_non_zero_sample (c, frame_index)) { - + if (debug_level (DebugVerbose)) { debug_stream () << DebugUtils::demangled_name (*this) << " flushing intermediate silence and outputting frame" << std::endl; } - + // context contains non-zero data output_silence_frames (c, silence_frames); // flush intermediate silence ListedSource<T>::output (c); // output rest of data } else { // whole context is zero - + if (debug_level (DebugVerbose)) { debug_stream () << DebugUtils::demangled_name (*this) << " no, output, adding frames to silence count" << std::endl; } - + silence_frames += c.frames(); } - + } else { // no need to do anything special - + if (debug_level (DebugVerbose)) { debug_stream () << DebugUtils::demangled_name (*this) << " outputting whole frame in middle" << std::endl; } - + ListedSource<T>::output (c); } - + // Finally, if in end, add silence to end if (in_end && add_to_end) { c.set_flag (ProcessContext<T>::EndOfInput); @@ -218,7 +218,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer debug_stream () << DebugUtils::demangled_name (*this) << " adding to end" << std::endl; } - + add_to_end *= c.channels(); output_silence_frames (c, add_to_end, true); } @@ -240,22 +240,22 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer } return false; } - + void output_silence_frames (ProcessContext<T> const & c, framecnt_t & total_frames, bool adding_to_end = false) { bool end_of_input = c.has_flag (ProcessContext<T>::EndOfInput); c.remove_flag (ProcessContext<T>::EndOfInput); - + while (total_frames > 0) { framecnt_t frames = std::min (silence_buffer_size, total_frames); if (max_output_frames) { frames = std::min (frames, max_output_frames); } frames -= frames % c.channels(); - + total_frames -= frames; ConstProcessContext<T> c_out (c, silence_buffer, frames); - + // boolean commentation :) bool const no_more_silence_will_be_added = adding_to_end || (add_to_end == 0); bool const is_last_frame_output_in_this_function = (total_frames == 0); @@ -272,16 +272,16 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer bool in_beginning; bool in_end; - + bool trim_beginning; bool trim_end; - + framecnt_t silence_frames; framecnt_t max_output_frames; - + framecnt_t add_to_beginning; framecnt_t add_to_end; - + framecnt_t silence_buffer_size; T * silence_buffer; }; |