diff options
author | Robin Gareus <robin@gareus.org> | 2015-10-05 16:17:49 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-10-05 16:17:49 +0200 |
commit | 22b07e0233a29d9633ffa825a79503befaf2e16e (patch) | |
tree | 1d8b06056f8e12197158f5d906319767d3dedda5 /libs/audiographer | |
parent | e11ba7b79d68bc1070b170236c22123966d7bcc3 (diff) |
NOOP, remove trailing tabs/whitespace.
Diffstat (limited to 'libs/audiographer')
42 files changed, 393 insertions, 393 deletions
diff --git a/libs/audiographer/audiographer/broadcast_info.h b/libs/audiographer/audiographer/broadcast_info.h index dd776d17af..82641e6c00 100644 --- a/libs/audiographer/audiographer/broadcast_info.h +++ b/libs/audiographer/audiographer/broadcast_info.h @@ -33,7 +33,7 @@ namespace AudioGrapher { -class SndfileHandle; +class SndfileHandle; class LIBAUDIOGRAPHER_API BroadcastInfo { diff --git a/libs/audiographer/audiographer/debug_utils.h b/libs/audiographer/audiographer/debug_utils.h index a8c63e85b6..410567d51b 100644 --- a/libs/audiographer/audiographer/debug_utils.h +++ b/libs/audiographer/audiographer/debug_utils.h @@ -34,7 +34,7 @@ struct LIBAUDIOGRAPHER_API DebugUtils #endif return typeid(obj).name(); } - + /// Returns name of ProcessContext::Flag static std::string process_context_flag_name (FlagField::Flag flag); }; diff --git a/libs/audiographer/audiographer/flag_debuggable.h b/libs/audiographer/audiographer/flag_debuggable.h index 7ff6a79ed1..f5d4fbf6ed 100644 --- a/libs/audiographer/audiographer/flag_debuggable.h +++ b/libs/audiographer/audiographer/flag_debuggable.h @@ -26,14 +26,14 @@ class /*LIBAUDIOGRAPHER_API*/ FlagDebuggable : public Debuggable<L> { flags.set (flag); } - + /// Prints debug output if \a context contains flags that are not supported by this class template<typename SelfType, typename ContextType> void check_flags (SelfType & self, ProcessContext<ContextType> context) { if (!Debuggable<L>::debug_level (DebugFlags)) { return; } FlagField unsupported = flags.unsupported_flags_of (context.flags()); - + for (FlagField::iterator it = unsupported.begin(); it != unsupported.end(); ++it) { Debuggable<L>::debug_stream() << boost::str (boost::format ("%1% does not support flag %2%") diff --git a/libs/audiographer/audiographer/flag_field.h b/libs/audiographer/audiographer/flag_field.h index 34ab5efdd6..989478f808 100644 --- a/libs/audiographer/audiographer/flag_field.h +++ b/libs/audiographer/audiographer/flag_field.h @@ -20,10 +20,10 @@ class LIBAUDIOGRAPHER_API FlagField , boost::equality_comparable<FlagField> { public: - + typedef uint8_t Flag; typedef uint32_t storage_type; - + /// Bi-directional iterator for flag set. Iterates over flags that are set in this field. class iterator : public std::iterator<std::bidirectional_iterator_tag, Flag> @@ -34,10 +34,10 @@ class LIBAUDIOGRAPHER_API FlagField public: iterator (FlagField const & parent, Flag position) : parent (parent), position (position) {} iterator (iterator const & other) : parent (other.parent), position (other.position) {} - + value_type operator*() const { return position; } value_type const * operator->() const { return &position; } - + iterator & operator++() { do { @@ -46,7 +46,7 @@ class LIBAUDIOGRAPHER_API FlagField return *this; } iterator operator++(int) { iterator copy (*this); ++(*this); return copy; } - + iterator & operator--() { do { @@ -55,19 +55,19 @@ class LIBAUDIOGRAPHER_API FlagField return *this; } iterator operator--(int) { iterator copy (*this); --(*this); return copy; } - + bool operator< (iterator const & other) const { return position < other.position; } - + private: FlagField const & parent; Flag position; }; - + public: - + FlagField() : _flags (0) {} FlagField(FlagField const & other) : _flags (other._flags) {} - + inline bool has (Flag flag) const { return _flags & (1 << flag); } inline storage_type flags () const { return _flags; } inline operator bool() const { return _flags; } @@ -77,10 +77,10 @@ class LIBAUDIOGRAPHER_API FlagField /// Returns the flags in \a other that are not set in this field inline FlagField unsupported_flags_of (FlagField const & other) const { return ~(_flags | ~other._flags); } - + /// Set all flags that are set in \a other inline FlagField & operator+= (FlagField const & other) { _flags |= other._flags; return *this; } - + /** Checks whether this field has all the flags set that are set in \a other * NOTE: Can NOT be used for strict weak ordering! * \return \a true if \a other has flags set that this field does not @@ -99,7 +99,7 @@ class LIBAUDIOGRAPHER_API FlagField private: FlagField(storage_type flags) : _flags (flags) {} static Flag max() { return CHAR_BIT * sizeof (storage_type) + 1; } - + storage_type _flags; }; 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; diff --git a/libs/audiographer/audiographer/process_context.h b/libs/audiographer/audiographer/process_context.h index 36abd4fba0..16e637b85c 100644 --- a/libs/audiographer/audiographer/process_context.h +++ b/libs/audiographer/audiographer/process_context.h @@ -45,30 +45,30 @@ public: ProcessContext (T * data, framecnt_t frames, ChannelCount channels) : _data (data), _frames (frames), _channels (channels) { validate_data(); } - + /// Normal copy constructor ProcessContext (ProcessContext<T> const & other) : Throwing<throwLevel>(), _data (other._data), _frames (other._frames), _channels (other._channels), _flags (other._flags) { /* No need to validate data */ } - + /// "Copy constructor" with unique data, frame and channel count, but copies flags template<typename Y> ProcessContext (ProcessContext<Y> const & other, T * data, framecnt_t frames, ChannelCount channels) : Throwing<throwLevel>(), _data (data), _frames (frames), _channels (channels), _flags (other.flags()) { validate_data(); } - + /// "Copy constructor" with unique data and frame count, but copies channel count and flags template<typename Y> ProcessContext (ProcessContext<Y> const & other, T * data, framecnt_t frames) : Throwing<throwLevel>(), _data (data), _frames (frames), _channels (other.channels()), _flags (other.flags()) { validate_data(); } - + /// "Copy constructor" with unique data, but copies frame and channel count + flags template<typename Y> ProcessContext (ProcessContext<Y> const & other, T * data) : Throwing<throwLevel>(), _data (data), _frames (other.frames()), _channels (other.channels()), _flags (other.flags()) { /* No need to validate data */ } - + /// Make new Context out of the beginning of this context ProcessContext beginning (framecnt_t frames) { @@ -78,39 +78,39 @@ public: % DebugUtils::demangled_name (*this) % frames % _frames)); } validate_data (); - + return ProcessContext (*this, _data, frames); } - + virtual ~ProcessContext () {} - + /// \a data points to the array of data to process inline T const * data() const { return _data; } inline T * data() { return _data; } - + /// \a frames tells how many frames the array pointed by data contains inline framecnt_t const & frames() const { return _frames; } - + /** \a channels tells how many interleaved channels \a data contains * If \a channels is greater than 1, each channel contains \a frames / \a channels frames of data */ inline ChannelCount const & channels() const { return _channels; } - + /// Returns the amount of frames per channel inline framecnt_t frames_per_channel() const { return _frames / _channels; } /* Flags */ - + inline bool has_flag (Flag flag) const { return _flags.has (flag); } inline void set_flag (Flag flag) const { _flags.set (flag); } inline void remove_flag (Flag flag) const { _flags.remove (flag); } inline FlagField const & flags () const { return _flags; } - + protected: T * const _data; framecnt_t _frames; ChannelCount _channels; - + mutable FlagField _flags; private: @@ -132,32 +132,32 @@ public: /// Allocates uninitialized memory AllocatingProcessContext (framecnt_t frames, ChannelCount channels) : ProcessContext<T> (new T[frames], frames, channels) {} - + /// Allocates and copies data from raw buffer AllocatingProcessContext (T const * data, framecnt_t frames, ChannelCount channels) : ProcessContext<T> (new T[frames], frames, channels) { TypeUtils<float>::copy (data, ProcessContext<T>::_data, frames); } - + /// Copy constructor, copies data from other ProcessContext AllocatingProcessContext (ProcessContext<T> const & other) : ProcessContext<T> (other, new T[other._frames]) { TypeUtils<float>::copy (ProcessContext<T>::_data, other._data, other._frames); } - + /// "Copy constructor" with uninitialized data, unique frame and channel count, but copies flags template<typename Y> AllocatingProcessContext (ProcessContext<Y> const & other, framecnt_t frames, ChannelCount channels) : ProcessContext<T> (other, new T[frames], frames, channels) {} - + /// "Copy constructor" with uninitialized data, unique frame count, but copies channel count and flags template<typename Y> AllocatingProcessContext (ProcessContext<Y> const & other, framecnt_t frames) : ProcessContext<T> (other, new T[frames], frames, other.channels()) {} - + /// "Copy constructor" uninitialized data, that copies frame and channel count + flags template<typename Y> AllocatingProcessContext (ProcessContext<Y> const & other) : ProcessContext<T> (other, new T[other._frames]) {} - + ~AllocatingProcessContext () { delete [] ProcessContext<T>::_data; } }; @@ -169,21 +169,21 @@ class /*LIBAUDIOGRAPHER_API*/ ConstProcessContext /// Basic constructor with data, frame and channel count ConstProcessContext (T const * data, framecnt_t frames, ChannelCount channels) : context (const_cast<T *>(data), frames, channels) {} - + /// Copy constructor from const ProcessContext ConstProcessContext (ProcessContext<T> const & other) : context (const_cast<ProcessContext<T> &> (other)) {} - + /// "Copy constructor", with unique data, frame and channel count, but copies flags template<typename ProcessContext> ConstProcessContext (ProcessContext const & other, T const * data, framecnt_t frames, ChannelCount channels) : context (other, const_cast<T *>(data), frames, channels) {} - + /// "Copy constructor", with unique data and frame count, but copies channel count and flags template<typename ProcessContext> ConstProcessContext (ProcessContext const & other, T const * data, framecnt_t frames) : context (other, const_cast<T *>(data), frames) {} - + /// "Copy constructor", with unique data, but copies frame and channel count + flags template<typename ProcessContext> ConstProcessContext (ProcessContext const & other, T const * data) diff --git a/libs/audiographer/audiographer/routines.h b/libs/audiographer/audiographer/routines.h index 4ab3bc5fb5..d78fa602b6 100644 --- a/libs/audiographer/audiographer/routines.h +++ b/libs/audiographer/audiographer/routines.h @@ -15,13 +15,13 @@ class LIBAUDIOGRAPHER_API Routines { public: typedef uint32_t uint_type; - + typedef float (*compute_peak_t) (float const *, uint_type, float); typedef void (*apply_gain_to_buffer_t) (float *, uint_type, float); - + static void override_compute_peak (compute_peak_t func) { _compute_peak = func; } static void override_apply_gain_to_buffer (apply_gain_to_buffer_t func) { _apply_gain_to_buffer = func; } - + /** Computes peak in float buffer * \n RT safe * \param data buffer from which the peak is computed @@ -61,7 +61,7 @@ class LIBAUDIOGRAPHER_API Routines data[i] *= gain; } } - + static compute_peak_t _compute_peak; static apply_gain_to_buffer_t _apply_gain_to_buffer; }; diff --git a/libs/audiographer/audiographer/sink.h b/libs/audiographer/audiographer/sink.h index b1e5605206..da9e7350ee 100644 --- a/libs/audiographer/audiographer/sink.h +++ b/libs/audiographer/audiographer/sink.h @@ -17,13 +17,13 @@ template <typename T> class /*LIBAUDIOGRAPHER_API*/ Sink { public: virtual ~Sink () {} - + /** Process given data. * The data can not be modified, so in-place processing is not allowed. * At least this function must be implemented by deriving classes */ virtual void process (ProcessContext<T> const & context) = 0; - + /** Process given data * Data may be modified, so in place processing is allowed. * The default implementation calls the non-modifying version, diff --git a/libs/audiographer/audiographer/sndfile/sndfile.h b/libs/audiographer/audiographer/sndfile/sndfile.h index 939e5f8a2c..c48a0331ab 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile.h +++ b/libs/audiographer/audiographer/sndfile/sndfile.h @@ -14,15 +14,15 @@ template<typename T = DefaultSampleType> class Sndfile : public SndfileWriter<T>, public SndfileReader<T> { public: - + Sndfile (std::string const & filename, SndfileBase::Mode mode = SndfileBase::ReadWrite, int format = 0, ChannelCount channels = 0, framecnt_t samplerate = 0) : SndfileHandle (filename, mode, format, channels, samplerate) {} - + Sndfile (Sndfile const & other) : SndfileHandle (other) {} using SndfileHandle::operator=; - + }; } // namespace diff --git a/libs/audiographer/audiographer/sndfile/sndfile_base.h b/libs/audiographer/audiographer/sndfile/sndfile_base.h index 02d5a7f6ea..67a34d484e 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_base.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_base.h @@ -18,7 +18,7 @@ class SndfileBase : public virtual AudioGrapher::SndfileHandle Write = SFM_WRITE, ReadWrite = SFM_RDWR }; - + protected: SndfileBase () {} }; diff --git a/libs/audiographer/audiographer/sndfile/sndfile_reader.h b/libs/audiographer/audiographer/sndfile/sndfile_reader.h index aa3c0cc899..ea27470d77 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_reader.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_reader.h @@ -18,13 +18,13 @@ class SndfileReader , public Throwing<> { public: - + SndfileReader (std::string const & path) : SndfileHandle (path) {} virtual ~SndfileReader () {} SndfileReader (SndfileReader const & other) : SndfileHandle (other) {} using SndfileHandle::operator=; - + /** Read data into buffer in \a context, only the data is modified (not frame count) * Note that the data read is output to the outputs, as well as read into the context * \return number of frames read @@ -36,17 +36,17 @@ class SndfileReader ("Wrong number of channels given to process(), %1% instead of %2%") % context.channels() % channels())); } - + framecnt_t const frames_read = SndfileHandle::read (context.data(), context.frames()); ProcessContext<T> c_out = context.beginning (frames_read); - + if (frames_read < context.frames()) { c_out.set_flag (ProcessContext<T>::EndOfInput); } this->output (c_out); return frames_read; } - + protected: /// SndfileHandle has to be constructed directly by deriving classes SndfileReader () {} diff --git a/libs/audiographer/audiographer/sndfile/sndfile_writer.h b/libs/audiographer/audiographer/sndfile/sndfile_writer.h index 984ec01d41..57ad968dc5 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_writer.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_writer.h @@ -37,9 +37,9 @@ class SndfileWriter broadcast_info->write_to_file (this); } } - + virtual ~SndfileWriter () {} - + SndfileWriter (SndfileWriter const & other) : SndfileHandle (other) { @@ -50,18 +50,18 @@ class SndfileWriter framecnt_t get_frames_written() const { return frames_written; } void reset_frames_written_count() { frames_written = 0; } - + /// Writes data to file void process (ProcessContext<T> const & c) { check_flags (*this, c); - + if (throw_level (ThrowStrict) && c.channels() != channels()) { throw Exception (*this, boost::str (boost::format ("Wrong number of channels given to process(), %1% instead of %2%") % c.channels() % channels())); } - + framecnt_t const written = write (c.data(), c.frames()); frames_written += written; @@ -76,9 +76,9 @@ class SndfileWriter FileWritten (path); } } - + using Sink<T>::process; - + PBD::Signal1<void, std::string> FileWritten; protected: diff --git a/libs/audiographer/audiographer/source.h b/libs/audiographer/audiographer/source.h index 945cb13298..2d80345b9b 100644 --- a/libs/audiographer/audiographer/source.h +++ b/libs/audiographer/audiographer/source.h @@ -19,15 +19,15 @@ class /*LIBAUDIOGRAPHER_API*/ Source { public: virtual ~Source () { } - + typedef boost::shared_ptr<Sink<T> > SinkPtr; - + /// Adds an output to this source. All data generated is forwarded to \a output virtual void add_output (SinkPtr output) = 0; - + /// Removes all outputs added virtual void clear_outputs () = 0; - + /// Removes a specific output from this source virtual void remove_output (SinkPtr output) = 0; }; diff --git a/libs/audiographer/audiographer/type_utils.h b/libs/audiographer/audiographer/type_utils.h index e86fbcc282..4e12937165 100644 --- a/libs/audiographer/audiographer/type_utils.h +++ b/libs/audiographer/audiographer/type_utils.h @@ -17,7 +17,7 @@ namespace AudioGrapher class LIBAUDIOGRAPHER_API TypeUtilsBase { protected: - + template<typename T, bool b> static void do_zero_fill(T * buffer, framecnt_t frames, const boost::integral_constant<bool, b>&) { std::uninitialized_fill_n (buffer, frames, T()); } @@ -32,7 +32,7 @@ template<typename T = DefaultSampleType> class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase { BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value); - + typedef boost::integral_constant<bool, boost::is_floating_point<T>::value || boost::is_signed<T>::value> zero_fillable; @@ -44,14 +44,14 @@ class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase */ inline static void zero_fill (T * buffer, framecnt_t frames) { do_zero_fill(buffer, frames, zero_fillable()); } - + /** Copies \a frames frames of data from \a source to \a destination * The source and destination may NOT overlap. * \n RT safe */ inline static void copy (T const * source, T * destination, framecnt_t frames) { std::uninitialized_copy (source, &source[frames], destination); } - + /** Moves \a frames frames of data from \a source to \a destination * The source and destination may overlap in any way. * \n RT safe diff --git a/libs/audiographer/audiographer/types.h b/libs/audiographer/audiographer/types.h index 4288dce0c6..1ecf6360a0 100644 --- a/libs/audiographer/audiographer/types.h +++ b/libs/audiographer/audiographer/types.h @@ -7,9 +7,9 @@ namespace AudioGrapher { -/* XXX: copied from libardour */ +/* XXX: copied from libardour */ typedef int64_t framecnt_t; - + typedef uint8_t ChannelCount; typedef float DefaultSampleType; diff --git a/libs/audiographer/audiographer/utils/listed_source.h b/libs/audiographer/audiographer/utils/listed_source.h index b9bfbc65f8..7069f13c72 100644 --- a/libs/audiographer/audiographer/utils/listed_source.h +++ b/libs/audiographer/audiographer/utils/listed_source.h @@ -19,11 +19,11 @@ class /*LIBAUDIOGRAPHER_API*/ ListedSource : public Source<T> void add_output (typename Source<T>::SinkPtr output) { outputs.push_back(output); } void clear_outputs () { outputs.clear(); } void remove_output (typename Source<T>::SinkPtr output) { outputs.remove(output); } - + protected: - + typedef std::list<typename Source<T>::SinkPtr> SinkList; - + /// Helper for derived classes void output (ProcessContext<T> const & c) { diff --git a/libs/audiographer/src/debug_utils.cc b/libs/audiographer/src/debug_utils.cc index c243164f58..4113ad7841 100644 --- a/libs/audiographer/src/debug_utils.cc +++ b/libs/audiographer/src/debug_utils.cc @@ -30,7 +30,7 @@ std::string DebugUtils::process_context_flag_name (FlagField::Flag flag) { std::ostringstream ret; - + switch (flag) { case ProcessContext<>::EndOfInput: ret << "EndOfInput"; @@ -39,7 +39,7 @@ DebugUtils::process_context_flag_name (FlagField::Flag flag) ret << flag; break; } - + return ret.str(); } diff --git a/libs/audiographer/src/general/normalizer.cc b/libs/audiographer/src/general/normalizer.cc index 5497c2ab14..d241d71892 100644 --- a/libs/audiographer/src/general/normalizer.cc +++ b/libs/audiographer/src/general/normalizer.cc @@ -30,7 +30,7 @@ Normalizer::Normalizer (float target_dB) { target = pow (10.0f, target_dB * 0.05f); } - + Normalizer::~Normalizer() { delete [] buffer; @@ -66,12 +66,12 @@ void Normalizer::process (ProcessContext<float> const & c) if (throw_level (ThrowProcess) && c.frames() > buffer_size) { throw Exception (*this, "Too many frames given to process()"); } - + if (enabled) { memcpy (buffer, c.data(), c.frames() * sizeof(float)); Routines::apply_gain_to_buffer (buffer, c.frames(), gain); } - + ProcessContext<float> c_out (c, buffer); ListedSource<float>::output (c_out); } diff --git a/libs/audiographer/src/general/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index a04ebfc25c..1f79818a8b 100644 --- a/libs/audiographer/src/general/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -120,11 +120,11 @@ SampleFormatConverter<TOut>::reset() gdither_free (dither); dither = 0; } - + delete[] data_out; data_out_size = 0; data_out = 0; - + clip_floats = false; } @@ -134,7 +134,7 @@ void SampleFormatConverter<TOut>::process (ProcessContext<float> const & c_in) { float const * const data = c_in.data(); - + check_frame_and_channel_count (c_in.frames (), c_in.channels ()); /* Do conversion */ @@ -164,7 +164,7 @@ SampleFormatConverter<float>::process (ProcessContext<float> & c_in) { framecnt_t frames = c_in.frames(); float * data = c_in.data(); - + if (clip_floats) { for (framecnt_t x = 0; x < frames; ++x) { if (data[x] > 1.0f) { @@ -186,7 +186,7 @@ SampleFormatConverter<float>::process (ProcessContext<float> const & c_in) // Make copy of data and pass it to non-const version check_frame_and_channel_count (c_in.frames(), c_in.channels()); TypeUtils<float>::copy (c_in.data(), data_out, c_in.frames()); - + ProcessContext<float> c (c_in, data_out); process (c); } @@ -200,7 +200,7 @@ SampleFormatConverter<TOut>::check_frame_and_channel_count (framecnt_t frames, C ("Wrong channel count given to process(), %1% instead of %2%") % channels_ % channels)); } - + if (throw_level (ThrowProcess) && frames > data_out_size) { throw Exception (*this, boost::str (boost::format ("Too many frames given to process(), %1% instad of %2%") diff --git a/libs/audiographer/src/general/sr_converter.cc b/libs/audiographer/src/general/sr_converter.cc index 512e57a743..90de3e58d7 100644 --- a/libs/audiographer/src/general/sr_converter.cc +++ b/libs/audiographer/src/general/sr_converter.cc @@ -49,7 +49,7 @@ void SampleRateConverter::init (framecnt_t in_rate, framecnt_t out_rate, int quality) { reset(); - + if (in_rate == out_rate) { src_data.src_ratio = 1; return; @@ -76,7 +76,7 @@ framecnt_t SampleRateConverter::allocate_buffers (framecnt_t max_frames) { if (!active) { return max_frames; } - + framecnt_t max_frames_out = (framecnt_t) ceil (max_frames * src_data.src_ratio); if (data_out_size < max_frames_out) { @@ -93,7 +93,7 @@ SampleRateConverter::allocate_buffers (framecnt_t max_frames) max_frames_in = max_frames; data_out_size = max_frames_out; } - + return max_frames_out; } @@ -101,7 +101,7 @@ void SampleRateConverter::process (ProcessContext<float> const & c) { check_flags (*this, c); - + if (!active) { output (c); return; @@ -158,7 +158,7 @@ SampleRateConverter::process (ProcessContext<float> const & c) ", data_out: " << src_data.data_out << ", output_frames: " << src_data.output_frames << std::endl; } - + err = src_process (src_state, &src_data); if (throw_level (ThrowProcess) && err) { throw Exception (*this, str (format @@ -193,9 +193,9 @@ SampleRateConverter::process (ProcessContext<float> const & c) ("No output frames genereated with %1% leftover frames") % leftover_frames)); } - + } while (leftover_frames > frames); - + // src_data.end_of_input has to be checked to prevent infinite recursion if (!src_data.end_of_input && c.has_flag(ProcessContext<float>::EndOfInput)) { set_end_of_input (c); @@ -205,10 +205,10 @@ SampleRateConverter::process (ProcessContext<float> const & c) void SampleRateConverter::set_end_of_input (ProcessContext<float> const & c) { src_data.end_of_input = true; - + float f; ProcessContext<float> const dummy (c, &f, 0, channels); - + /* No idea why this has to be done twice for all data to be written, * but that just seems to be the way it is... */ @@ -224,17 +224,17 @@ void SampleRateConverter::reset () active = false; max_frames_in = 0; src_data.end_of_input = false; - + if (src_state) { src_delete (src_state); } - + leftover_frames = 0; max_leftover_frames = 0; if (leftover_data) { free (leftover_data); } - + data_out_size = 0; delete [] data_out; data_out = 0; diff --git a/libs/audiographer/tests/general/chunker_test.cc b/libs/audiographer/tests/general/chunker_test.cc index d3adab3691..12b5da5dbc 100644 --- a/libs/audiographer/tests/general/chunker_test.cc +++ b/libs/audiographer/tests/general/chunker_test.cc @@ -35,52 +35,52 @@ class ChunkerTest : public CppUnit::TestFixture { chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const context (random_data, frames, 1); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (2 * frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames], frames)); - + sink->reset(); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (2 * frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames], frames)); } - + void testAsynchronousProcess() { assert (frames % 2 == 0); - + chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); - + // 0.5 chunker->process (half_context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 1.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 2.5 chunker->process (context); frames_output = sink->get_data().size(); @@ -88,14 +88,14 @@ class ChunkerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames / 2)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames / 2], frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * frames / 2], frames / 2)); - + sink->reset(); - + // 3.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 4.0 chunker->process (half_context); frames_output = sink->get_data().size(); @@ -104,30 +104,30 @@ class ChunkerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames / 2], frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * frames / 2], frames / 2)); } - + void testChoppingProcess() { sink.reset (new AppendingVectorSink<float>()); - + assert (frames % 2 == 0); chunker.reset (new Chunker<float>(frames / 4)); - + chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); - + // 0.5 chunker->process (half_context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2, frames_output); - + // 1.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2 * 3, frames_output); - + // 2.5 chunker->process (context); frames_output = sink->get_data().size(); @@ -140,15 +140,15 @@ class ChunkerTest : public CppUnit::TestFixture void testEndOfInputFlagHandling() { boost::shared_ptr<ProcessContextGrabber<float> > grabber(new ProcessContextGrabber<float>()); - + assert (frames % 2 == 0); chunker.reset (new Chunker<float>(frames)); chunker->add_output (grabber); - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); context.set_flag(ProcessContext<>::EndOfInput); - + // Process 0.5 then 1.0 chunker->process (half_context); chunker->process (context); diff --git a/libs/audiographer/tests/general/deinterleaver_test.cc b/libs/audiographer/tests/general/deinterleaver_test.cc index 3260045b11..f7e15459b3 100644 --- a/libs/audiographer/tests/general/deinterleaver_test.cc +++ b/libs/audiographer/tests/general/deinterleaver_test.cc @@ -48,15 +48,15 @@ class DeInterleaverTest : public CppUnit::TestFixture void testInvalidInputSize() { deinterleaver->init (channels, frames_per_channel); - + ProcessContext<float> c (random_data, 2 * total_frames, channels); - + // Too many, frames % channels == 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + channels)), Exception); - + // Too many, frames % channels != 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + 1)), Exception); - + // Too few, frames % channels != 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames - 1)), Exception); } @@ -64,13 +64,13 @@ class DeInterleaverTest : public CppUnit::TestFixture void assert_outputs (framecnt_t expected_frames) { framecnt_t generated_frames = 0; - + generated_frames = sink_a->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); - + generated_frames = sink_b->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); - + generated_frames = sink_c->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); } @@ -78,34 +78,34 @@ class DeInterleaverTest : public CppUnit::TestFixture void testOutputSize() { deinterleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + // Test maximum frame input ProcessContext<float> c (random_data, total_frames, channels); deinterleaver->process (c); assert_outputs (frames_per_channel); - + // Now with less frames framecnt_t const less_frames = frames_per_channel / 4; deinterleaver->process (c.beginning (less_frames * channels)); assert_outputs (less_frames); } - + void testZeroInput() { deinterleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + // Input zero frames ProcessContext<float> c (random_data, total_frames, channels); deinterleaver->process (c.beginning (0)); - + // ...and now test regular input deinterleaver->process (c); assert_outputs (frames_per_channel); diff --git a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc index da042b9494..4f46a83492 100644 --- a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc @@ -18,14 +18,14 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture channels = 3; frames_per_channel = 128; total_frames = channels * frames_per_channel; - + random_data_a = TestUtils::init_random_data (total_frames, 1.0); random_data_b = TestUtils::init_random_data (frames_per_channel, 1.0); random_data_c = TestUtils::init_random_data (frames_per_channel, 1.0); deinterleaver.reset (new DeInterleaver<float>()); interleaver.reset (new Interleaver<float>()); - + sink_a.reset (new VectorSink<float>()); sink_b.reset (new VectorSink<float>()); sink_c.reset (new VectorSink<float>()); @@ -42,64 +42,64 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture { deinterleaver->init (channels, frames_per_channel); interleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (interleaver->input (0)); deinterleaver->output (1)->add_output (interleaver->input (1)); deinterleaver->output (2)->add_output (interleaver->input (2)); - + interleaver->add_output (sink_a); - + // Process and assert ProcessContext<float> c (random_data_a, total_frames, channels); deinterleaver->process (c); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_frames)); - + // And a second round... framecnt_t less_frames = (frames_per_channel / 10) * channels; deinterleaver->process (c.beginning (less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames)); } - + void testDeInterleavedInput() { deinterleaver->init (channels, frames_per_channel); interleaver->init (channels, frames_per_channel); - + interleaver->add_output (deinterleaver); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + ProcessContext<float> c_a (random_data_a, frames_per_channel, 1); ProcessContext<float> c_b (random_data_b, frames_per_channel, 1); ProcessContext<float> c_c (random_data_c, frames_per_channel, 1); - + // Process and assert interleaver->input (0)->process (c_a); interleaver->input (1)->process (c_b); interleaver->input (2)->process (c_c); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), frames_per_channel)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), frames_per_channel)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), frames_per_channel)); - + // And a second round... framecnt_t less_frames = frames_per_channel / 5; interleaver->input (0)->process (c_a.beginning (less_frames)); interleaver->input (1)->process (c_b.beginning (less_frames)); interleaver->input (2)->process (c_c.beginning (less_frames)); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), less_frames)); - + } private: boost::shared_ptr<Interleaver<float> > interleaver; boost::shared_ptr<DeInterleaver<float> > deinterleaver; - + boost::shared_ptr<VectorSink<float> > sink_a; boost::shared_ptr<VectorSink<float> > sink_b; boost::shared_ptr<VectorSink<float> > sink_c; @@ -107,7 +107,7 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture float * random_data_a; float * random_data_b; float * random_data_c; - + framecnt_t frames_per_channel; framecnt_t total_frames; unsigned int channels; diff --git a/libs/audiographer/tests/general/interleaver_test.cc b/libs/audiographer/tests/general/interleaver_test.cc index b82aac74bb..0b8f8b6952 100644 --- a/libs/audiographer/tests/general/interleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_test.cc @@ -24,7 +24,7 @@ class InterleaverTest : public CppUnit::TestFixture interleaver.reset (new Interleaver<float>()); sink.reset (new VectorSink<float>()); - + interleaver->init (channels, frames); } @@ -50,7 +50,7 @@ class InterleaverTest : public CppUnit::TestFixture { ProcessContext<float> c (random_data, frames + 1, 1); CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); - + interleaver->input (0)->process (c.beginning (frames)); interleaver->input (1)->process (c.beginning (frames)); CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (frames - 1)), Exception); @@ -92,9 +92,9 @@ class InterleaverTest : public CppUnit::TestFixture interleaver->input (0)->process (c.beginning (0)); interleaver->input (1)->process (c.beginning (0)); interleaver->input (2)->process (c.beginning (0)); - + // NOTE zero input is allowed to be a NOP - + // ...now test regular input interleaver->input (0)->process (c); interleaver->input (1)->process (c); @@ -110,7 +110,7 @@ class InterleaverTest : public CppUnit::TestFixture interleaver->add_output (sink); ProcessContext<float> c (random_data, frames, 1); interleaver->input (0)->process (c); - CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); + CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); } diff --git a/libs/audiographer/tests/general/normalizer_test.cc b/libs/audiographer/tests/general/normalizer_test.cc index be23680202..fb8cd617c2 100644 --- a/libs/audiographer/tests/general/normalizer_test.cc +++ b/libs/audiographer/tests/general/normalizer_test.cc @@ -26,24 +26,24 @@ class NormalizerTest : public CppUnit::TestFixture { float target = 0.0; random_data = TestUtils::init_random_data(frames, 0.5); - + normalizer.reset (new Normalizer(target)); peak_reader.reset (new PeakReader()); sink.reset (new VectorSink<float>()); - + ProcessContext<float> const c (random_data, frames, 1); peak_reader->process (c); - + float peak = peak_reader->get_peak(); normalizer->alloc_buffer (frames); normalizer->set_peak (peak); normalizer->add_output (sink); normalizer->process (c); - + peak_reader->reset(); ConstProcessContext<float> normalized (sink->get_array(), frames, 1); peak_reader->process (normalized); - + peak = peak_reader->get_peak(); CPPUNIT_ASSERT (-FLT_EPSILON <= (peak - 1.0) && (peak - 1.0) <= 0.0); } diff --git a/libs/audiographer/tests/general/peak_reader_test.cc b/libs/audiographer/tests/general/peak_reader_test.cc index 6b60598a2e..a93d28a954 100644 --- a/libs/audiographer/tests/general/peak_reader_test.cc +++ b/libs/audiographer/tests/general/peak_reader_test.cc @@ -26,17 +26,17 @@ class PeakReaderTest : public CppUnit::TestFixture { reader.reset (new PeakReader()); ProcessContext<float> c (random_data, frames, 1); - + float peak = 1.5; random_data[10] = peak; reader->process (c); CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak()); - + peak = 2.0; random_data[10] = peak; reader->process (c); CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak()); - + peak = -2.1; random_data[10] = peak; reader->process (c); diff --git a/libs/audiographer/tests/general/sample_format_converter_test.cc b/libs/audiographer/tests/general/sample_format_converter_test.cc index 977e2b390a..734389a427 100644 --- a/libs/audiographer/tests/general/sample_format_converter_test.cc +++ b/libs/audiographer/tests/general/sample_format_converter_test.cc @@ -63,25 +63,25 @@ class SampleFormatConverterTest : public CppUnit::TestFixture { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); - + converter->init (frames, D_Tri, 32); converter->add_output (sink); framecnt_t frames_output = 0; - + { ProcessContext<float> pc(random_data, frames / 2, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames / 2, frames_output); } - + { ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); } - + { ProcessContext<float> pc(random_data, frames + 1, 1); CPPUNIT_ASSERT_THROW(converter->process (pc), Exception); @@ -93,27 +93,27 @@ class SampleFormatConverterTest : public CppUnit::TestFixture boost::shared_ptr<SampleFormatConverter<float> > converter (new SampleFormatConverter<float>(1)); boost::shared_ptr<VectorSink<float> > sink (new VectorSink<float>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + converter->set_clip_floats (false); ProcessContext<float> const pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals(sink->get_array(), random_data, frames)); - + // Make sure a few samples are < -1.0 and > 1.0 random_data[10] = -1.5; random_data[20] = 1.5; - + converter->set_clip_floats (true); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); - + for (framecnt_t i = 0; i < frames; ++i) { // fp comparison needs a bit of tolerance, 1.01 << 1.5 CPPUNIT_ASSERT(sink->get_data()[i] < 1.01); @@ -126,77 +126,77 @@ class SampleFormatConverterTest : public CppUnit::TestFixture boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testInt24() { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 24); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testInt16() { boost::shared_ptr<SampleFormatConverter<int16_t> > converter (new SampleFormatConverter<int16_t>(1)); boost::shared_ptr<VectorSink<int16_t> > sink (new VectorSink<int16_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 16); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testUint8() { boost::shared_ptr<SampleFormatConverter<uint8_t> > converter (new SampleFormatConverter<uint8_t>(1)); boost::shared_ptr<VectorSink<uint8_t> > sink (new VectorSink<uint8_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 8); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testChannelCount() { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(3)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + ProcessContext<float> pc(random_data, 4, 1); CPPUNIT_ASSERT_THROW (converter->process (pc), Exception); - + framecnt_t new_frame_count = frames - (frames % 3); converter->process (ProcessContext<float> (pc.data(), new_frame_count, 3)); frames_output = sink->get_data().size(); diff --git a/libs/audiographer/tests/general/silence_trimmer_test.cc b/libs/audiographer/tests/general/silence_trimmer_test.cc index dfcf3c7ca2..be53c89978 100644 --- a/libs/audiographer/tests/general/silence_trimmer_test.cc +++ b/libs/audiographer/tests/general/silence_trimmer_test.cc @@ -18,20 +18,20 @@ class SilenceTrimmerTest : public CppUnit::TestFixture void setUp() { frames = 128; - + random_data = TestUtils::init_random_data(frames); random_data[0] = 0.5; random_data[frames - 1] = 0.5; - + zero_data = new float[frames]; memset(zero_data, 0, frames * sizeof(float)); - + half_random_data = TestUtils::init_random_data(frames); memset(half_random_data, 0, (frames / 2) * sizeof(float)); - + trimmer.reset (new SilenceTrimmer<float> (frames / 2)); sink.reset (new AppendingVectorSink<float>()); - + trimmer->set_trim_beginning (true); trimmer->set_trim_end (true); } @@ -46,14 +46,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture void testFullBuffers() { trimmer->add_output (sink); - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_processed); } - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); @@ -61,14 +61,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (frames, frames_processed); CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, frames)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_processed); } - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); @@ -78,7 +78,7 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames], zero_data, frames)); CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[2 * frames], random_data, frames)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); @@ -86,14 +86,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (3 * frames, frames_processed); } } - + void testPartialBuffers() { trimmer->add_output (sink); trimmer->reset (frames / 4); trimmer->set_trim_beginning (true); trimmer->set_trim_end (true); - + { ProcessContext<float> c (half_random_data, frames, 1); trimmer->process (c); @@ -101,14 +101,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), &half_random_data[frames / 2], frames / 2)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); } - + { ProcessContext<float> c (half_random_data, frames, 1); trimmer->process (c); @@ -117,48 +117,48 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames + frames / 2], half_random_data, frames)); } } - + void testExceptions() { { CPPUNIT_ASSERT_THROW (trimmer->reset (0), Exception); } } - + void testAddSilenceBeginning() { trimmer->add_output (sink); - + framecnt_t silence = frames / 2; trimmer->add_silence_to_beginning (silence); - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); } - + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), zero_data, silence)); CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[silence], random_data, frames)); } - + void testAddSilenceEnd() { trimmer->add_output (sink); - + framecnt_t silence = frames / 3; trimmer->add_silence_to_end (silence); - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); } - + { ProcessContext<float> c (random_data, frames, 1); c.set_flag (ProcessContext<float>::EndOfInput); trimmer->process (c); } - + framecnt_t frames_processed = sink->get_data().size(); framecnt_t total_frames = 2 * frames + silence; CPPUNIT_ASSERT_EQUAL (total_frames, frames_processed); diff --git a/libs/audiographer/tests/general/sr_converter_test.cc b/libs/audiographer/tests/general/sr_converter_test.cc index 75834127f5..4f5afbb620 100644 --- a/libs/audiographer/tests/general/sr_converter_test.cc +++ b/libs/audiographer/tests/general/sr_converter_test.cc @@ -33,19 +33,19 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (44100, 44100); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); } @@ -54,11 +54,11 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (44100, 88200); converter->allocate_buffers (half_frames); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); @@ -75,37 +75,37 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (88200, 44100); converter->allocate_buffers (half_frames); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + frames_output = sink->get_data().size(); framecnt_t tolerance = 3; CPPUNIT_ASSERT (half_frames - tolerance < frames_output && frames_output < half_frames + tolerance); } - + void testRespectsEndOfInput() { assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; - + converter->init (44100, 48000); converter->allocate_buffers (half_frames); converter->add_output (grabber); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames / 2, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + for (std::list<ProcessContext<float> >::iterator it = grabber->contexts.begin(); it != grabber->contexts.end(); ++it) { std::list<ProcessContext<float> >::iterator next = it; ++next; if (next == grabber->contexts.end()) { @@ -115,7 +115,7 @@ class SampleRateConverterTest : public CppUnit::TestFixture } } } - + private: boost::shared_ptr<SampleRateConverter > converter; diff --git a/libs/audiographer/tests/general/threader_test.cc b/libs/audiographer/tests/general/threader_test.cc index 1e87c8d34d..cdb21a375b 100644 --- a/libs/audiographer/tests/general/threader_test.cc +++ b/libs/audiographer/tests/general/threader_test.cc @@ -18,20 +18,20 @@ class ThreaderTest : public CppUnit::TestFixture { frames = 128; random_data = TestUtils::init_random_data (frames, 1.0); - + zero_data = new float[frames]; memset (zero_data, 0, frames * sizeof(float)); - + thread_pool = new Glib::ThreadPool (3); threader.reset (new Threader<float> (*thread_pool)); - + sink_a.reset (new VectorSink<float>()); sink_b.reset (new VectorSink<float>()); sink_c.reset (new VectorSink<float>()); sink_d.reset (new VectorSink<float>()); sink_e.reset (new VectorSink<float>()); sink_f.reset (new VectorSink<float>()); - + throwing_sink.reset (new ThrowingSink<float>()); } @@ -39,7 +39,7 @@ class ThreaderTest : public CppUnit::TestFixture { delete [] random_data; delete [] zero_data; - + thread_pool->shutdown(); delete thread_pool; } @@ -52,10 +52,10 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -63,7 +63,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testRemoveOutput() { threader->add_output (sink_a); @@ -72,18 +72,18 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + // Remove a, b and f threader->remove_output (sink_a); threader->remove_output (sink_b); threader->remove_output (sink_f); - + ProcessContext<float> zc (zero_data, frames, 1); threader->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_c->get_array(), frames)); @@ -91,7 +91,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testClearOutputs() { threader->add_output (sink_a); @@ -100,14 +100,14 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + threader->clear_outputs(); ProcessContext<float> zc (zero_data, frames, 1); threader->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -115,7 +115,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testExceptions() { threader->add_output (sink_a); @@ -124,10 +124,10 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (throwing_sink); threader->add_output (sink_e); threader->add_output (throwing_sink); - + ProcessContext<float> c (random_data, frames, 1); CPPUNIT_ASSERT_THROW (threader->process (c), Exception); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -136,7 +136,7 @@ class ThreaderTest : public CppUnit::TestFixture private: Glib::ThreadPool * thread_pool; - + boost::shared_ptr<Threader<float> > threader; boost::shared_ptr<VectorSink<float> > sink_a; boost::shared_ptr<VectorSink<float> > sink_b; @@ -144,7 +144,7 @@ class ThreaderTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink_d; boost::shared_ptr<VectorSink<float> > sink_e; boost::shared_ptr<VectorSink<float> > sink_f; - + boost::shared_ptr<ThrowingSink<float> > throwing_sink; float * random_data; diff --git a/libs/audiographer/tests/sndfile/tmp_file_test.cc b/libs/audiographer/tests/sndfile/tmp_file_test.cc index 9ce8af7a5c..32e39135ec 100644 --- a/libs/audiographer/tests/sndfile/tmp_file_test.cc +++ b/libs/audiographer/tests/sndfile/tmp_file_test.cc @@ -28,9 +28,9 @@ class TmpFileTest : public CppUnit::TestFixture AllocatingProcessContext<float> c (random_data, frames, channels); c.set_flag (ProcessContext<float>::EndOfInput); file->process (c); - + TypeUtils<float>::zero_fill (c.data (), c.frames()); - + file->seek (0, SEEK_SET); file->read (c); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.frames())); diff --git a/libs/audiographer/tests/type_utils_test.cc b/libs/audiographer/tests/type_utils_test.cc index a2b2c96f11..1ae7b28451 100644 --- a/libs/audiographer/tests/type_utils_test.cc +++ b/libs/audiographer/tests/type_utils_test.cc @@ -17,12 +17,12 @@ class TypeUtilsTest : public CppUnit::TestFixture public: void setUp() { - + } void tearDown() { - + } void testZeroFillPod() @@ -35,7 +35,7 @@ class TypeUtilsTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (zero, buf[i]); } } - + void testZeroFillNonPod() { /* does not compile on OS X Lion @@ -48,26 +48,26 @@ class TypeUtilsTest : public CppUnit::TestFixture } */ } - + void testMoveBackward() { int seq[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - + TypeUtils<int>::move (&seq[4], &seq[2], 4); - + for (int i = 2; i < 2 + 4; ++i) { CPPUNIT_ASSERT_EQUAL (i + 2, seq[i]); } } - + void testMoveForward() { int seq[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - + TypeUtils<int>::move (&seq[2], &seq[4], 4); - + for (int i = 4; i < 4 + 4; ++i) { CPPUNIT_ASSERT_EQUAL (i - 2, seq[i]); } @@ -79,16 +79,16 @@ class TypeUtilsTest : public CppUnit::TestFixture int const seq2[4] = { 5, 6, 7, 8 }; int seq3[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - + TypeUtils<int>::copy (seq1, seq3, 4); for (int i = 0; i < 4; ++i) { CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]); } - + for (int i = 4; i < 8; ++i) { CPPUNIT_ASSERT_EQUAL (0, seq3[i]); } - + TypeUtils<int>::copy (seq2, &seq3[4], 4); for (int i = 0; i < 4; ++i) { CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]); @@ -99,14 +99,14 @@ class TypeUtilsTest : public CppUnit::TestFixture } private: - + struct NonPodType { NonPodType() : data (42) {} bool operator== (NonPodType const & other) const { return data == other.data; } int data; }; - + }; diff --git a/libs/audiographer/tests/utils.h b/libs/audiographer/tests/utils.h index 2955f51102..b6b9e0136c 100644 --- a/libs/audiographer/tests/utils.h +++ b/libs/audiographer/tests/utils.h @@ -49,7 +49,7 @@ struct TestUtils unsigned int const granularity = 4096; float * data = new float[frames]; srand (std::time (NULL)); - + for (framecnt_t i = 0; i < frames; ++i) { do { int biased_int = (rand() % granularity) - (granularity / 2); @@ -127,10 +127,10 @@ class ProcessContextGrabber : public AudioGrapher::Sink<T> contexts.push_back (c); } using AudioGrapher::Sink<T>::process; - + typedef std::list<AudioGrapher::ProcessContext<T> > ContextList; ContextList contexts; - + }; #endif // AUDIOGRAPHER_TESTS_UTILS_H diff --git a/libs/audiographer/tests/utils/identity_vertex_test.cc b/libs/audiographer/tests/utils/identity_vertex_test.cc index 799dcca386..3c0fd71c70 100644 --- a/libs/audiographer/tests/utils/identity_vertex_test.cc +++ b/libs/audiographer/tests/utils/identity_vertex_test.cc @@ -17,7 +17,7 @@ class IdentityVertexTest : public CppUnit::TestFixture { frames = 128; random_data = TestUtils::init_random_data(frames); - + zero_data = new float[frames]; memset (zero_data, 0, frames * sizeof(float)); @@ -36,52 +36,52 @@ class IdentityVertexTest : public CppUnit::TestFixture vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + framecnt_t frames_output = 0; - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + frames_output = sink_a->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + frames_output = sink_b->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), frames)); } - + void testRemoveOutput() { vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + vertex->remove_output (sink_a); ProcessContext<float> zc (zero_data, frames, 1); vertex->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (zero_data, sink_b->get_array(), frames)); } - + void testClearOutputs() { vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + vertex->clear_outputs (); ProcessContext<float> zc (zero_data, frames, 1); vertex->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), frames)); } |