diff options
Diffstat (limited to 'libs/audiographer/audiographer/general')
9 files changed, 109 insertions, 109 deletions
diff --git a/libs/audiographer/audiographer/general/chunker.h b/libs/audiographer/audiographer/general/chunker.h index d61c68dee4..466a333655 100644 --- a/libs/audiographer/audiographer/general/chunker.h +++ b/libs/audiographer/audiographer/general/chunker.h @@ -28,12 +28,12 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker buffer = new T[chunk_size]; add_supported_flag (ProcessContext<T>::EndOfInput); } - + ~Chunker() { delete [] buffer; } - + /** Outputs data in \a context in chunks with the size specified in the constructor. * Note that some calls might not produce any output, while others may produce several. * \n RT safe @@ -41,15 +41,15 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker void process (ProcessContext<T> const & context) { check_flags (*this, context); - + framecnt_t frames_left = context.frames(); framecnt_t input_position = 0; - + while (position + frames_left >= chunk_size) { // Copy from context to buffer framecnt_t const frames_to_copy = chunk_size - position; TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], frames_to_copy); - + // Update counters position = 0; input_position += frames_to_copy; @@ -60,25 +60,25 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker if (frames_left) { c_out.remove_flag(ProcessContext<T>::EndOfInput); } ListedSource<T>::output (c_out); } - + if (frames_left) { // Copy the rest of the data TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], frames_left); position += frames_left; } - + if (context.has_flag (ProcessContext<T>::EndOfInput) && position > 0) { ProcessContext<T> c_out (context, buffer, position); ListedSource<T>::output (c_out); } } using Sink<T>::process; - + private: framecnt_t chunk_size; framecnt_t position; T * buffer; - + }; } // namespace diff --git a/libs/audiographer/audiographer/general/deinterleaver.h b/libs/audiographer/audiographer/general/deinterleaver.h index fac38912d7..63b6c95589 100644 --- a/libs/audiographer/audiographer/general/deinterleaver.h +++ b/libs/audiographer/audiographer/general/deinterleaver.h @@ -21,7 +21,7 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver { private: typedef boost::shared_ptr<IdentityVertex<T> > OutputPtr; - + public: /// Constructor. \n RT safe DeInterleaver() @@ -29,11 +29,11 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver , max_frames (0) , buffer (0) {} - + ~DeInterleaver() { reset(); } - + typedef boost::shared_ptr<Source<T> > SourcePtr; - + /// Inits the deinterleaver. Must be called before using. \n Not RT safe void init (unsigned int num_channels, framecnt_t max_frames_per_channel) { @@ -41,53 +41,53 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver channels = num_channels; max_frames = max_frames_per_channel; buffer = new T[max_frames]; - + for (unsigned int i = 0; i < channels; ++i) { outputs.push_back (OutputPtr (new IdentityVertex<T>)); } } - + /// Returns an output indexed by \a channel \n RT safe SourcePtr output (unsigned int channel) { if (throw_level (ThrowObject) && channel >= channels) { throw Exception (*this, "channel out of range"); } - + return outputs[channel]; } - + /// Deinterleaves data and outputs it to the outputs. \n RT safe void process (ProcessContext<T> const & c) { framecnt_t frames = c.frames(); T const * data = c.data(); - + framecnt_t const frames_per_channel = frames / channels; - + if (throw_level (ThrowProcess) && c.channels() != channels) { throw Exception (*this, "wrong amount of channels given to process()"); } - + if (throw_level (ThrowProcess) && frames_per_channel > max_frames) { throw Exception (*this, "too many frames given to process()"); } - + unsigned int channel = 0; for (typename std::vector<OutputPtr>::iterator it = outputs.begin(); it != outputs.end(); ++it, ++channel) { if (!*it) { continue; } - + for (unsigned int i = 0; i < frames_per_channel; ++i) { buffer[i] = data[channel + (channels * i)]; } - + ProcessContext<T> c_out (c, buffer, frames_per_channel, 1); (*it)->process (c_out); } } - + using Sink<T>::process; - + private: void reset () @@ -98,7 +98,7 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver channels = 0; max_frames = 0; } - + std::vector<OutputPtr> outputs; unsigned int channels; framecnt_t max_frames; diff --git a/libs/audiographer/audiographer/general/interleaver.h b/libs/audiographer/audiographer/general/interleaver.h index 2bc62e5443..c1b5e92cfe 100644 --- a/libs/audiographer/audiographer/general/interleaver.h +++ b/libs/audiographer/audiographer/general/interleaver.h @@ -21,30 +21,30 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver , public Throwing<> { public: - + /// Constructs an interleaver \n RT safe Interleaver() : channels (0) , max_frames (0) , buffer (0) {} - + ~Interleaver() { reset(); } - + /// Inits the interleaver. Must be called before using. \n Not RT safe void init (unsigned int num_channels, framecnt_t max_frames_per_channel) { reset(); channels = num_channels; max_frames = max_frames_per_channel; - + buffer = new T[channels * max_frames]; - + for (unsigned int i = 0; i < channels; ++i) { inputs.push_back (InputPtr (new Input (*this, i))); } } - + /** Returns the input indexed by \a channel \n RT safe * \n The \a process function of returned Sinks are also RT Safe */ @@ -53,10 +53,10 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver if (throw_level (ThrowObject) && channel >= channels) { throw Exception (*this, "Channel out of range"); } - + return boost::static_pointer_cast<Sink<T> > (inputs[channel]); } - + private: class Input : public Sink<T> @@ -64,7 +64,7 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver public: Input (Interleaver & parent, unsigned int channel) : frames_written (0), parent (parent), channel (channel) {} - + void process (ProcessContext<T> const & c) { if (parent.throw_level (ThrowProcess) && c.channels() > 1) { @@ -76,18 +76,18 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver frames_written = c.frames(); parent.write_channel (c, channel); } - + using Sink<T>::process; - + framecnt_t frames() { return frames_written; } void reset() { frames_written = 0; } - + private: framecnt_t frames_written; Interleaver & parent; unsigned int channel; }; - + void reset () { inputs.clear(); @@ -96,7 +96,7 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver channels = 0; max_frames = 0; } - + void reset_channels () { for (unsigned int i = 0; i < channels; ++i) { @@ -104,18 +104,18 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver } } - + void write_channel (ProcessContext<T> const & c, unsigned int channel) { if (throw_level (ThrowProcess) && c.frames() > max_frames) { reset_channels(); throw Exception (*this, "Too many frames given to an input"); } - + for (unsigned int i = 0; i < c.frames(); ++i) { buffer[channel + (channels * i)] = c.data()[i]; } - + framecnt_t const ready_frames = ready_to_output(); if (ready_frames) { ProcessContext<T> c_out (c, buffer, ready_frames, channels); @@ -142,7 +142,7 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver typedef boost::shared_ptr<Input> InputPtr; std::vector<InputPtr> inputs; - + unsigned int channels; framecnt_t max_frames; T * buffer; diff --git a/libs/audiographer/audiographer/general/normalizer.h b/libs/audiographer/audiographer/general/normalizer.h index e95f0e3852..025131022e 100644 --- a/libs/audiographer/audiographer/general/normalizer.h +++ b/libs/audiographer/audiographer/general/normalizer.h @@ -32,7 +32,7 @@ public: /// Process a const ProcessContext \see alloc_buffer() \n RT safe void process (ProcessContext<float> const & c); - + /// Process a non-const ProcsesContext in-place \n RT safe void process (ProcessContext<float> & c); @@ -40,7 +40,7 @@ private: bool enabled; float target; float gain; - + float * buffer; framecnt_t buffer_size; }; diff --git a/libs/audiographer/audiographer/general/peak_reader.h b/libs/audiographer/audiographer/general/peak_reader.h index dd5d65491c..8bf0faa792 100644 --- a/libs/audiographer/audiographer/general/peak_reader.h +++ b/libs/audiographer/audiographer/general/peak_reader.h @@ -15,10 +15,10 @@ class /*LIBAUDIOGRAPHER_API*/ PeakReader : public ListedSource<float>, public Si public: /// Constructor \n RT safe PeakReader() : peak (0.0) {} - + /// Returns the highest absolute of the values found so far. \n RT safe float get_peak() { return peak; } - + /// Resets the peak to 0 \n RT safe void reset() { peak = 0.0; } @@ -28,9 +28,9 @@ class /*LIBAUDIOGRAPHER_API*/ PeakReader : public ListedSource<float>, public Si peak = Routines::compute_peak (c.data(), c.frames(), peak); ListedSource<float>::output(c); } - + using Sink<float>::process; - + private: float peak; }; diff --git a/libs/audiographer/audiographer/general/sample_format_converter.h b/libs/audiographer/audiographer/general/sample_format_converter.h index af30ac1605..96dd6aa72a 100644 --- a/libs/audiographer/audiographer/general/sample_format_converter.h +++ b/libs/audiographer/audiographer/general/sample_format_converter.h @@ -17,7 +17,7 @@ enum /*LIBAUDIOGRAPHER_API*/ DitherType D_Tri = GDitherTri, ///< Triangular dithering D_Shaped = GDitherShaped ///< Actually noise shaping, only works for 46kHzish signals }; - + /** Sample format converter that does dithering. * This class can only convert floats to either \a float, \a int32_t, \a int16_t, or \a uint8_t */ @@ -33,7 +33,7 @@ class LIBAUDIOGRAPHER_API SampleFormatConverter */ SampleFormatConverter (ChannelCount channels); ~SampleFormatConverter (); - + /** Initialize and allocate buffers for processing. * \param max_frames maximum number of frames that is allowed to be used in calls to \a process() * \param type dither type from \a DitherType @@ -45,10 +45,10 @@ class LIBAUDIOGRAPHER_API SampleFormatConverter /// Set whether or not clipping to [-1.0, 1.0] should occur when TOut = float. Clipping is off by default void set_clip_floats (bool yn) { clip_floats = yn; } - + /// Processes data without modifying it void process (ProcessContext<float> const & c_in); - + /// This version is only different in the case when \a TOut = float, and float clipping is on. void process (ProcessContext<float> & c_in); 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; }; diff --git a/libs/audiographer/audiographer/general/sr_converter.h b/libs/audiographer/audiographer/general/sr_converter.h index 0cbe3bd294..a2e94d9bc0 100644 --- a/libs/audiographer/audiographer/general/sr_converter.h +++ b/libs/audiographer/audiographer/general/sr_converter.h @@ -27,10 +27,10 @@ class LIBAUDIOGRAPHER_API SampleRateConverter /// Init converter \n Not RT safe void init (framecnt_t in_rate, framecnt_t out_rate, int quality = 0); - + /// Returns max amount of frames that will be output \n RT safe framecnt_t allocate_buffers (framecnt_t max_frames); - + /** Does sample rate conversion. * Note that outpt size may vary a lot. * May or may not output several contexts of data. @@ -48,7 +48,7 @@ class LIBAUDIOGRAPHER_API SampleRateConverter bool active; uint32_t channels; framecnt_t max_frames_in; - + float * leftover_data; framecnt_t leftover_frames; framecnt_t max_leftover_frames; diff --git a/libs/audiographer/audiographer/general/threader.h b/libs/audiographer/audiographer/general/threader.h index e9a953ce44..2ef4099efe 100644 --- a/libs/audiographer/audiographer/general/threader.h +++ b/libs/audiographer/audiographer/general/threader.h @@ -39,7 +39,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T> typedef std::vector<typename Source<T>::SinkPtr> OutputVec; public: - + /** Constructor * \n RT safe * \param thread_pool a thread pool from which all tasks are scheduled @@ -50,39 +50,39 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T> , readers (0) , wait_timeout (wait_timeout_milliseconds) { } - + virtual ~Threader () {} - + /// Adds output \n RT safe void add_output (typename Source<T>::SinkPtr output) { outputs.push_back (output); } - + /// Clears outputs \n RT safe void clear_outputs () { outputs.clear (); } - + /// Removes a specific output \n RT safe void remove_output (typename Source<T>::SinkPtr output) { typename OutputVec::iterator new_end = std::remove(outputs.begin(), outputs.end(), output); outputs.erase (new_end, outputs.end()); } - + /// Processes context concurrently by scheduling each output separately to the given thread pool void process (ProcessContext<T> const & c) { wait_mutex.lock(); - + exception.reset(); - + unsigned int outs = outputs.size(); g_atomic_int_add (&readers, outs); for (unsigned int i = 0; i < outs; ++i) { thread_pool.push (sigc::bind (sigc::mem_fun (this, &Threader::process_output), c, i)); } - + wait(); } - + using Sink<T>::process; - + private: void wait() @@ -93,12 +93,12 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T> } wait_mutex.unlock(); - + if (exception) { throw *exception; } } - + void process_output(ProcessContext<T> const & c, unsigned int output) { try { @@ -109,7 +109,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T> if(!exception) { exception.reset (new ThreaderException (*this, e)); } exception_mutex.unlock(); } - + if (g_atomic_int_dec_and_test (&readers)) { wait_cond.signal(); } @@ -122,7 +122,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T> Glib::Threads::Cond wait_cond; gint readers; long wait_timeout; - + Glib::Threads::Mutex exception_mutex; boost::shared_ptr<ThreaderException> exception; |