diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2017-09-18 12:39:17 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2017-09-18 12:39:17 -0400 |
commit | 30b087ab3d28f1585987fa3f6ae006562ae192e3 (patch) | |
tree | 620ae0250b5d77f90a18f8c2b83be61e4fe7b0b5 /libs/audiographer | |
parent | cb956e3e480716a3efd280a5287bdd7bee1cedc5 (diff) |
globally change all use of "frame" to refer to audio into "sample".
Generated by tools/f2s. Some hand-editing will be required in a few places to fix up comments related to timecode
and video in order to keep the legible
Diffstat (limited to 'libs/audiographer')
38 files changed, 724 insertions, 724 deletions
diff --git a/libs/audiographer/audiographer/general/analyser.h b/libs/audiographer/audiographer/general/analyser.h index 9bd49b33c8..c912664cf0 100644 --- a/libs/audiographer/audiographer/general/analyser.h +++ b/libs/audiographer/audiographer/general/analyser.h @@ -29,7 +29,7 @@ namespace AudioGrapher class LIBAUDIOGRAPHER_API Analyser : public LoudnessReader { public: - Analyser (float sample_rate, unsigned int channels, framecnt_t bufsize, framecnt_t n_samples); + Analyser (float sample_rate, unsigned int channels, samplecnt_t bufsize, samplecnt_t n_samples); ~Analyser (); void process (ProcessContext<float> const & c); ARDOUR::ExportAnalysisPtr result (); @@ -48,10 +48,10 @@ class LIBAUDIOGRAPHER_API Analyser : public LoudnessReader ARDOUR::ExportAnalysis _result; - framecnt_t _n_samples; - framecnt_t _pos; - framecnt_t _spp; - framecnt_t _fpp; + samplecnt_t _n_samples; + samplecnt_t _pos; + samplecnt_t _spp; + samplecnt_t _fpp; float* _hann_window; uint32_t _fft_data_size; diff --git a/libs/audiographer/audiographer/general/chunker.h b/libs/audiographer/audiographer/general/chunker.h index 466a333655..28ac79b603 100644 --- a/libs/audiographer/audiographer/general/chunker.h +++ b/libs/audiographer/audiographer/general/chunker.h @@ -10,7 +10,7 @@ namespace AudioGrapher { -/// A class that chunks process cycles into equal sized frames +/// A class that chunks process cycles into equal sized samples template<typename T = DefaultSampleType> class /*LIBAUDIOGRAPHER_API*/ Chunker : public ListedSource<T> @@ -21,7 +21,7 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker /** Constructs a new Chunker with a constant chunk size. * \n NOT RT safe */ - Chunker (framecnt_t chunk_size) + Chunker (samplecnt_t chunk_size) : chunk_size (chunk_size) , position (0) { @@ -42,29 +42,29 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker { check_flags (*this, context); - framecnt_t frames_left = context.frames(); - framecnt_t input_position = 0; + samplecnt_t samples_left = context.samples(); + samplecnt_t input_position = 0; - while (position + frames_left >= chunk_size) { + while (position + samples_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); + samplecnt_t const samples_to_copy = chunk_size - position; + TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], samples_to_copy); // Update counters position = 0; - input_position += frames_to_copy; - frames_left -= frames_to_copy; + input_position += samples_to_copy; + samples_left -= samples_to_copy; // Output whole buffer ProcessContext<T> c_out (context, buffer, chunk_size); - if (frames_left) { c_out.remove_flag(ProcessContext<T>::EndOfInput); } + if (samples_left) { c_out.remove_flag(ProcessContext<T>::EndOfInput); } ListedSource<T>::output (c_out); } - if (frames_left) { + if (samples_left) { // Copy the rest of the data - TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], frames_left); - position += frames_left; + TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], samples_left); + position += samples_left; } if (context.has_flag (ProcessContext<T>::EndOfInput) && position > 0) { @@ -75,8 +75,8 @@ class /*LIBAUDIOGRAPHER_API*/ Chunker using Sink<T>::process; private: - framecnt_t chunk_size; - framecnt_t position; + samplecnt_t chunk_size; + samplecnt_t position; T * buffer; }; diff --git a/libs/audiographer/audiographer/general/deinterleaver.h b/libs/audiographer/audiographer/general/deinterleaver.h index 63b6c95589..491c07fcb6 100644 --- a/libs/audiographer/audiographer/general/deinterleaver.h +++ b/libs/audiographer/audiographer/general/deinterleaver.h @@ -26,7 +26,7 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver /// Constructor. \n RT safe DeInterleaver() : channels (0) - , max_frames (0) + , max_samples (0) , buffer (0) {} @@ -35,12 +35,12 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver 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) + void init (unsigned int num_channels, samplecnt_t max_samples_per_channel) { reset(); channels = num_channels; - max_frames = max_frames_per_channel; - buffer = new T[max_frames]; + max_samples = max_samples_per_channel; + buffer = new T[max_samples]; for (unsigned int i = 0; i < channels; ++i) { outputs.push_back (OutputPtr (new IdentityVertex<T>)); @@ -60,28 +60,28 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver /// Deinterleaves data and outputs it to the outputs. \n RT safe void process (ProcessContext<T> const & c) { - framecnt_t frames = c.frames(); + samplecnt_t samples = c.samples(); T const * data = c.data(); - framecnt_t const frames_per_channel = frames / channels; + samplecnt_t const samples_per_channel = samples / 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()"); + if (throw_level (ThrowProcess) && samples_per_channel > max_samples) { + throw Exception (*this, "too many samples 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) { + for (unsigned int i = 0; i < samples_per_channel; ++i) { buffer[i] = data[channel + (channels * i)]; } - ProcessContext<T> c_out (c, buffer, frames_per_channel, 1); + ProcessContext<T> c_out (c, buffer, samples_per_channel, 1); (*it)->process (c_out); } } @@ -96,12 +96,12 @@ class /*LIBAUDIOGRAPHER_API*/ DeInterleaver delete [] buffer; buffer = 0; channels = 0; - max_frames = 0; + max_samples = 0; } std::vector<OutputPtr> outputs; unsigned int channels; - framecnt_t max_frames; + samplecnt_t max_samples; T * buffer; }; diff --git a/libs/audiographer/audiographer/general/interleaver.h b/libs/audiographer/audiographer/general/interleaver.h index c1b5e92cfe..7ea1be1ab8 100644 --- a/libs/audiographer/audiographer/general/interleaver.h +++ b/libs/audiographer/audiographer/general/interleaver.h @@ -25,20 +25,20 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver /// Constructs an interleaver \n RT safe Interleaver() : channels (0) - , max_frames (0) + , max_samples (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) + void init (unsigned int num_channels, samplecnt_t max_samples_per_channel) { reset(); channels = num_channels; - max_frames = max_frames_per_channel; + max_samples = max_samples_per_channel; - buffer = new T[channels * max_frames]; + buffer = new T[channels * max_samples]; for (unsigned int i = 0; i < channels; ++i) { inputs.push_back (InputPtr (new Input (*this, i))); @@ -63,27 +63,27 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver { public: Input (Interleaver & parent, unsigned int channel) - : frames_written (0), parent (parent), channel (channel) {} + : samples_written (0), parent (parent), channel (channel) {} void process (ProcessContext<T> const & c) { if (parent.throw_level (ThrowProcess) && c.channels() > 1) { throw Exception (*this, "Data input has more than on channel"); } - if (parent.throw_level (ThrowStrict) && frames_written) { + if (parent.throw_level (ThrowStrict) && samples_written) { throw Exception (*this, "Input channels out of sync"); } - frames_written = c.frames(); + samples_written = c.samples(); parent.write_channel (c, channel); } using Sink<T>::process; - framecnt_t frames() { return frames_written; } - void reset() { frames_written = 0; } + samplecnt_t samples() { return samples_written; } + void reset() { samples_written = 0; } private: - framecnt_t frames_written; + samplecnt_t samples_written; Interleaver & parent; unsigned int channel; }; @@ -94,7 +94,7 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver delete [] buffer; buffer = 0; channels = 0; - max_frames = 0; + max_samples = 0; } void reset_channels () @@ -107,44 +107,44 @@ class /*LIBAUDIOGRAPHER_API*/ Interleaver void write_channel (ProcessContext<T> const & c, unsigned int channel) { - if (throw_level (ThrowProcess) && c.frames() > max_frames) { + if (throw_level (ThrowProcess) && c.samples() > max_samples) { reset_channels(); - throw Exception (*this, "Too many frames given to an input"); + throw Exception (*this, "Too many samples given to an input"); } - for (unsigned int i = 0; i < c.frames(); ++i) { + for (unsigned int i = 0; i < c.samples(); ++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); + samplecnt_t const ready_samples = ready_to_output(); + if (ready_samples) { + ProcessContext<T> c_out (c, buffer, ready_samples, channels); ListedSource<T>::output (c_out); reset_channels (); } } - framecnt_t ready_to_output() + samplecnt_t ready_to_output() { - framecnt_t ready_frames = inputs[0]->frames(); - if (!ready_frames) { return 0; } + samplecnt_t ready_samples = inputs[0]->samples(); + if (!ready_samples) { return 0; } for (unsigned int i = 1; i < channels; ++i) { - framecnt_t const frames = inputs[i]->frames(); - if (!frames) { return 0; } - if (throw_level (ThrowProcess) && frames != ready_frames) { - init (channels, max_frames); - throw Exception (*this, "Frames count out of sync"); + samplecnt_t const samples = inputs[i]->samples(); + if (!samples) { return 0; } + if (throw_level (ThrowProcess) && samples != ready_samples) { + init (channels, max_samples); + throw Exception (*this, "Samples count out of sync"); } } - return ready_frames * channels; + return ready_samples * channels; } typedef boost::shared_ptr<Input> InputPtr; std::vector<InputPtr> inputs; unsigned int channels; - framecnt_t max_frames; + samplecnt_t max_samples; T * buffer; }; diff --git a/libs/audiographer/audiographer/general/loudness_reader.h b/libs/audiographer/audiographer/general/loudness_reader.h index c86fd521da..8c9ccb4149 100644 --- a/libs/audiographer/audiographer/general/loudness_reader.h +++ b/libs/audiographer/audiographer/general/loudness_reader.h @@ -32,7 +32,7 @@ namespace AudioGrapher class LIBAUDIOGRAPHER_API LoudnessReader : public ListedSource<float>, public Sink<float> { public: - LoudnessReader (float sample_rate, unsigned int channels, framecnt_t bufsize); + LoudnessReader (float sample_rate, unsigned int channels, samplecnt_t bufsize); ~LoudnessReader (); void reset (); @@ -52,8 +52,8 @@ class LIBAUDIOGRAPHER_API LoudnessReader : public ListedSource<float>, public Si float _sample_rate; unsigned int _channels; - framecnt_t _bufsize; - framecnt_t _pos; + samplecnt_t _bufsize; + samplecnt_t _pos; float* _bufs[2]; }; diff --git a/libs/audiographer/audiographer/general/normalizer.h b/libs/audiographer/audiographer/general/normalizer.h index e5f73a0f08..cd4e375db2 100644 --- a/libs/audiographer/audiographer/general/normalizer.h +++ b/libs/audiographer/audiographer/general/normalizer.h @@ -28,7 +28,7 @@ public: * non-const ProcessContexts are given to \a process() . * \n Not RT safe */ - void alloc_buffer(framecnt_t frames); + void alloc_buffer(samplecnt_t samples); /// Process a const ProcessContext \see alloc_buffer() \n RT safe void process (ProcessContext<float> const & c); @@ -42,7 +42,7 @@ private: float gain; float * buffer; - framecnt_t buffer_size; + samplecnt_t buffer_size; }; diff --git a/libs/audiographer/audiographer/general/peak_reader.h b/libs/audiographer/audiographer/general/peak_reader.h index 8bf0faa792..bb04239544 100644 --- a/libs/audiographer/audiographer/general/peak_reader.h +++ b/libs/audiographer/audiographer/general/peak_reader.h @@ -25,7 +25,7 @@ class /*LIBAUDIOGRAPHER_API*/ PeakReader : public ListedSource<float>, public Si /// Finds peaks from the data \n RT safe void process (ProcessContext<float> const & c) { - peak = Routines::compute_peak (c.data(), c.frames(), peak); + peak = Routines::compute_peak (c.data(), c.samples(), peak); ListedSource<float>::output(c); } diff --git a/libs/audiographer/audiographer/general/sample_format_converter.h b/libs/audiographer/audiographer/general/sample_format_converter.h index 96dd6aa72a..9a79fc927c 100644 --- a/libs/audiographer/audiographer/general/sample_format_converter.h +++ b/libs/audiographer/audiographer/general/sample_format_converter.h @@ -35,13 +35,13 @@ class LIBAUDIOGRAPHER_API SampleFormatConverter ~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 max_samples maximum number of samples that is allowed to be used in calls to \a process() * \param type dither type from \a DitherType * \param data_width data with in bits * \note If the non-const version of process() is used with floats, * there is no need to call this function. */ - void init (framecnt_t max_frames, int type, int data_width); + void init (samplecnt_t max_samples, int type, int data_width); /// 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; } @@ -54,12 +54,12 @@ class LIBAUDIOGRAPHER_API SampleFormatConverter private: void reset(); - void init_common (framecnt_t max_frames); // not-template-specialized part of init - void check_frame_and_channel_count (framecnt_t frames, ChannelCount channels_); + void init_common (samplecnt_t max_samples); // not-template-specialized part of init + void check_sample_and_channel_count (samplecnt_t samples, ChannelCount channels_); ChannelCount channels; GDither dither; - framecnt_t data_out_size; + samplecnt_t data_out_size; TOut * data_out; bool clip_floats; diff --git a/libs/audiographer/audiographer/general/silence_trimmer.h b/libs/audiographer/audiographer/general/silence_trimmer.h index 7cfa0658f1..e09c348c52 100644 --- a/libs/audiographer/audiographer/general/silence_trimmer.h +++ b/libs/audiographer/audiographer/general/silence_trimmer.h @@ -30,7 +30,7 @@ struct SilenceTester<float> { }; -/// Removes and adds silent frames to beginning and/or end of stream +/// Removes and adds silent samples to beginning and/or end of stream template<typename T = DefaultSampleType> class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer : public ListedSource<T> @@ -41,7 +41,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer public: /// Constructor, \see reset() \n Not RT safe - SilenceTrimmer(framecnt_t silence_buffer_size_ = 1024, float thresh_dB = -INFINITY) + SilenceTrimmer(samplecnt_t silence_buffer_size_ = 1024, float thresh_dB = -INFINITY) : silence_buffer_size (0) , silence_buffer (0) , tester (thresh_dB) @@ -60,7 +60,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer * This also defines the maximum length of output process context * which can be output during long intermediate silence. */ - void reset (framecnt_t silence_buffer_size_ = 1024) + void reset (samplecnt_t silence_buffer_size_ = 1024) { if (throw_level (ThrowObject) && silence_buffer_size_ == 0) { throw Exception (*this, @@ -78,34 +78,34 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer processing_finished = false; trim_beginning = false; trim_end = false; - silence_frames = 0; + silence_samples = 0; max_output_frames = 0; add_to_beginning = 0; add_to_end = 0; } - /** Tells that \a frames_per_channel frames of silence per channel should be added to beginning + /** Tells that \a samples_per_channel samples of silence per channel should be added to beginning * Needs to be called before starting processing. * \n RT safe */ - void add_silence_to_beginning (framecnt_t frames_per_channel) + void add_silence_to_beginning (samplecnt_t samples_per_channel) { if (throw_level (ThrowObject) && processed_data) { throw Exception(*this, "Tried to add silence to beginning after processing started"); } - add_to_beginning = frames_per_channel; + add_to_beginning = samples_per_channel; } - /** Tells that \a frames_per_channel frames of silence per channel should be added to end + /** Tells that \a samples_per_channel samples of silence per channel should be added to end * Needs to be called before end is reached. * \n RT safe */ - void add_silence_to_end (framecnt_t frames_per_channel) + void add_silence_to_end (samplecnt_t samples_per_channel) { if (throw_level (ThrowObject) && processed_data) { throw Exception(*this, "Tried to add silence to end after processing started"); } - add_to_end = frames_per_channel; + add_to_end = samples_per_channel; } /** Tells whether ot nor silence should be trimmed from the beginning @@ -166,17 +166,17 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer * may lend itself for some inspiration. */ - framecnt_t output_start_index = 0; - framecnt_t output_sample_count = c.frames(); + samplecnt_t output_start_index = 0; + samplecnt_t output_sample_count = c.samples(); if (!processed_data) { if (trim_beginning) { - framecnt_t first_non_silent_frame_index = 0; - if (find_first_non_silent_frame (c, first_non_silent_frame_index)) { + samplecnt_t first_non_silent_sample_index = 0; + if (find_first_non_silent_sample (c, first_non_silent_sample_index)) { // output from start of non-silent data until end of buffer // output_sample_count may also be altered in trim end - output_start_index = first_non_silent_frame_index; - output_sample_count = c.frames() - first_non_silent_frame_index; + output_start_index = first_non_silent_sample_index; + output_sample_count = c.samples() - first_non_silent_sample_index; processed_data = true; } else { // keep entering this block until non-silence is found to trim @@ -189,35 +189,35 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer // This block won't be called again so add silence to beginning if (processed_data && add_to_beginning) { add_to_beginning *= c.channels (); - output_silence_frames (c, add_to_beginning); + output_silence_samples (c, add_to_beginning); } } if (processed_data) { if (trim_end) { - framecnt_t first_non_silent_frame_index = 0; - if (find_first_non_silent_frame (c, first_non_silent_frame_index)) { + samplecnt_t first_non_silent_sample_index = 0; + if (find_first_non_silent_sample (c, first_non_silent_sample_index)) { // context buffer contains non-silent data, flush any intermediate silence - output_silence_frames (c, silence_frames); + output_silence_samples (c, silence_samples); - framecnt_t silent_frame_index = 0; - find_last_silent_frame_reverse (c, silent_frame_index); + samplecnt_t silent_sample_index = 0; + find_last_silent_sample_reverse (c, silent_sample_index); // Count of samples at end of block that are "silent", may be zero. - framecnt_t silent_end_samples = c.frames () - silent_frame_index; - framecnt_t samples_before_silence = c.frames() - silent_end_samples; + samplecnt_t silent_end_samples = c.samples () - silent_sample_index; + samplecnt_t samples_before_silence = c.samples() - silent_end_samples; - assert (samples_before_silence + silent_end_samples == c.frames ()); + assert (samples_before_silence + silent_end_samples == c.samples ()); // output_start_index may be non-zero if start trim occurred above output_sample_count = samples_before_silence - output_start_index; // keep track of any silent samples not output - silence_frames = silent_end_samples; + silence_samples = silent_end_samples; } else { // whole context buffer is silent output nothing - silence_frames += c.frames (); + silence_samples += c.samples (); output_sample_count = 0; } } @@ -230,7 +230,7 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer // Finally, if in last process call, add silence to end if (processing_finished && processed_data && add_to_end) { add_to_end *= c.channels(); - output_silence_frames (c, add_to_end); + output_silence_samples (c, add_to_end); } if (processing_finished) { @@ -250,13 +250,13 @@ class /*LIBAUDIOGRAPHER_API*/ SilenceTrimmer private: - bool find_first_non_silent_frame (ProcessContext<T> const & c, framecnt_t & result_frame) + bool find_first_non_silent_sample (ProcessContext<T> const & c, samplecnt_t & result_sample) { - for (framecnt_t i = 0; i < c.frames(); ++i) { + for (samplecnt_t i = 0; i < c.samples(); ++i) { if (!tester.is_silent (c.data()[i])) { - result_frame = i; + result_sample = i; // Round down to nearest interleaved "frame" beginning - result_frame -= result_frame % c.channels(); + result_sample -= result_sample % c.channels(); return true; } } @@ -264,43 +264,43 @@ private: } /** - * Reverse find the last silent frame index. If the last sample in the + * Reverse find the last silent sample index. If the last sample in the * buffer is non-silent the index will be one past the end of the buffer and - * equal to c.frames(). e.g silent_end_samples = c.frames() - result_frame + * equal to c.samples(). e.g silent_end_samples = c.samples() - result_sample * - * @return true if result_frame index is valid, false if there were only + * @return true if result_sample index is valid, false if there were only * silent samples in the context buffer */ - bool find_last_silent_frame_reverse (ProcessContext<T> const & c, framecnt_t & result_frame) + bool find_last_silent_sample_reverse (ProcessContext<T> const & c, samplecnt_t & result_sample) { - framecnt_t last_sample_index = c.frames() - 1; + samplecnt_t last_sample_index = c.samples() - 1; - for (framecnt_t i = last_sample_index; i >= 0; --i) { + for (samplecnt_t i = last_sample_index; i >= 0; --i) { if (!tester.is_silent (c.data()[i])) { - result_frame = i; + result_sample = i; // Round down to nearest interleaved "frame" beginning - result_frame -= result_frame % c.channels(); - // Round up to return the "last" silent interleaved frame - result_frame += c.channels(); + result_sample -= result_sample % c.channels(); + // Round up to return the "last" silent interleaved sample + result_sample += c.channels(); return true; } } return false; } - void output_silence_frames (ProcessContext<T> const & c, framecnt_t & total_frames) + void output_silence_samples (ProcessContext<T> const & c, samplecnt_t & total_samples) { assert (!c.has_flag (ProcessContext<T>::EndOfInput)); - while (total_frames > 0) { - framecnt_t frames = std::min (silence_buffer_size, total_frames); + while (total_samples > 0) { + samplecnt_t samples = std::min (silence_buffer_size, total_samples); if (max_output_frames) { - frames = std::min (frames, max_output_frames); + samples = std::min (samples, max_output_frames); } - frames -= frames % c.channels(); + samples -= samples % c.channels(); - total_frames -= frames; - ConstProcessContext<T> c_out (c, silence_buffer, frames); + total_samples -= samples; + ConstProcessContext<T> c_out (c, silence_buffer, samples); ListedSource<T>::output (c_out); } } @@ -311,13 +311,13 @@ private: bool trim_beginning; bool trim_end; - framecnt_t silence_frames; - framecnt_t max_output_frames; + samplecnt_t silence_samples; + samplecnt_t max_output_frames; - framecnt_t add_to_beginning; - framecnt_t add_to_end; + samplecnt_t add_to_beginning; + samplecnt_t add_to_end; - framecnt_t silence_buffer_size; + samplecnt_t silence_buffer_size; T * silence_buffer; SilenceTester<T> tester; diff --git a/libs/audiographer/audiographer/general/sr_converter.h b/libs/audiographer/audiographer/general/sr_converter.h index a2e94d9bc0..8edc4b8c99 100644 --- a/libs/audiographer/audiographer/general/sr_converter.h +++ b/libs/audiographer/audiographer/general/sr_converter.h @@ -26,10 +26,10 @@ class LIBAUDIOGRAPHER_API SampleRateConverter ~SampleRateConverter (); /// Init converter \n Not RT safe - void init (framecnt_t in_rate, framecnt_t out_rate, int quality = 0); + void init (samplecnt_t in_rate, samplecnt_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); + /// Returns max amount of samples that will be output \n RT safe + samplecnt_t allocate_buffers (samplecnt_t max_samples); /** Does sample rate conversion. * Note that outpt size may vary a lot. @@ -47,14 +47,14 @@ class LIBAUDIOGRAPHER_API SampleRateConverter bool active; uint32_t channels; - framecnt_t max_frames_in; + samplecnt_t max_samples_in; float * leftover_data; - framecnt_t leftover_frames; - framecnt_t max_leftover_frames; + samplecnt_t leftover_samples; + samplecnt_t max_leftover_samples; float * data_out; - framecnt_t data_out_size; + samplecnt_t data_out_size; SRC_DATA src_data; SRC_STATE* src_state; diff --git a/libs/audiographer/audiographer/process_context.h b/libs/audiographer/audiographer/process_context.h index 16e637b85c..3b54accc06 100644 --- a/libs/audiographer/audiographer/process_context.h +++ b/libs/audiographer/audiographer/process_context.h @@ -41,45 +41,45 @@ public: public: - /// Basic constructor with data, frame and channel count - ProcessContext (T * data, framecnt_t frames, ChannelCount channels) - : _data (data), _frames (frames), _channels (channels) + /// Basic constructor with data, sample and channel count + ProcessContext (T * data, samplecnt_t samples, ChannelCount channels) + : _data (data), _samples (samples), _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) + : Throwing<throwLevel>(), _data (other._data), _samples (other._samples), _channels (other._channels), _flags (other._flags) { /* No need to validate data */ } - /// "Copy constructor" with unique data, frame and channel count, but copies flags + /// "Copy constructor" with unique data, sample 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()) + ProcessContext (ProcessContext<Y> const & other, T * data, samplecnt_t samples, ChannelCount channels) + : Throwing<throwLevel>(), _data (data), _samples (samples), _channels (channels), _flags (other.flags()) { validate_data(); } - /// "Copy constructor" with unique data and frame count, but copies channel count and flags + /// "Copy constructor" with unique data and sample 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()) + ProcessContext (ProcessContext<Y> const & other, T * data, samplecnt_t samples) + : Throwing<throwLevel>(), _data (data), _samples (samples), _channels (other.channels()), _flags (other.flags()) { validate_data(); } - /// "Copy constructor" with unique data, but copies frame and channel count + flags + /// "Copy constructor" with unique data, but copies sample 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()) + : Throwing<throwLevel>(), _data (data), _samples (other.samples()), _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) + ProcessContext beginning (samplecnt_t samples) { - if (throw_level (ThrowProcess) && frames > _frames) { + if (throw_level (ThrowProcess) && samples > _samples) { throw Exception (*this, boost::str (boost::format - ("Trying to use too many frames of %1% for a new Context: %2% instead of %3%") - % DebugUtils::demangled_name (*this) % frames % _frames)); + ("Trying to use too many samples of %1% for a new Context: %2% instead of %3%") + % DebugUtils::demangled_name (*this) % samples % _samples)); } validate_data (); - return ProcessContext (*this, _data, frames); + return ProcessContext (*this, _data, samples); } virtual ~ProcessContext () {} @@ -88,16 +88,16 @@ public: 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 samples tells how many samples the array pointed by data contains + inline samplecnt_t const & samples() const { return _samples; } /** \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 + * If \a channels is greater than 1, each channel contains \a samples / \a channels samples 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; } + /// Returns the amount of samples per channel + inline samplecnt_t samples_per_channel() const { return _samples / _channels; } /* Flags */ @@ -108,7 +108,7 @@ public: protected: T * const _data; - framecnt_t _frames; + samplecnt_t _samples; ChannelCount _channels; mutable FlagField _flags; @@ -116,10 +116,10 @@ protected: private: inline void validate_data() { - if (throw_level (ThrowProcess) && (_frames % _channels != 0)) { + if (throw_level (ThrowProcess) && (_samples % _channels != 0)) { throw Exception (*this, boost::str (boost::format - ("Number of frames given to %1% was not a multiple of channels: %2% frames with %3% channels") - % DebugUtils::demangled_name (*this) % _frames % _channels)); + ("Number of samples given to %1% was not a multiple of channels: %2% samples with %3% channels") + % DebugUtils::demangled_name (*this) % _samples % _channels)); } } }; @@ -130,33 +130,33 @@ class /*LIBAUDIOGRAPHER_API*/ AllocatingProcessContext : public ProcessContext<T { public: /// Allocates uninitialized memory - AllocatingProcessContext (framecnt_t frames, ChannelCount channels) - : ProcessContext<T> (new T[frames], frames, channels) {} + AllocatingProcessContext (samplecnt_t samples, ChannelCount channels) + : ProcessContext<T> (new T[samples], samples, 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); } + AllocatingProcessContext (T const * data, samplecnt_t samples, ChannelCount channels) + : ProcessContext<T> (new T[samples], samples, channels) + { TypeUtils<float>::copy (data, ProcessContext<T>::_data, samples); } /// 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); } + : ProcessContext<T> (other, new T[other._samples]) + { TypeUtils<float>::copy (ProcessContext<T>::_data, other._data, other._samples); } - /// "Copy constructor" with uninitialized data, unique frame and channel count, but copies flags + /// "Copy constructor" with uninitialized data, unique sample 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) {} + AllocatingProcessContext (ProcessContext<Y> const & other, samplecnt_t samples, ChannelCount channels) + : ProcessContext<T> (other, new T[samples], samples, channels) {} - /// "Copy constructor" with uninitialized data, unique frame count, but copies channel count and flags + /// "Copy constructor" with uninitialized data, unique sample 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()) {} + AllocatingProcessContext (ProcessContext<Y> const & other, samplecnt_t samples) + : ProcessContext<T> (other, new T[samples], samples, other.channels()) {} - /// "Copy constructor" uninitialized data, that copies frame and channel count + flags + /// "Copy constructor" uninitialized data, that copies sample and channel count + flags template<typename Y> AllocatingProcessContext (ProcessContext<Y> const & other) - : ProcessContext<T> (other, new T[other._frames]) {} + : ProcessContext<T> (other, new T[other._samples]) {} ~AllocatingProcessContext () { delete [] ProcessContext<T>::_data; } }; @@ -166,25 +166,25 @@ template <typename T = DefaultSampleType> class /*LIBAUDIOGRAPHER_API*/ ConstProcessContext { public: - /// Basic constructor with data, frame and channel count - ConstProcessContext (T const * data, framecnt_t frames, ChannelCount channels) - : context (const_cast<T *>(data), frames, channels) {} + /// Basic constructor with data, sample and channel count + ConstProcessContext (T const * data, samplecnt_t samples, ChannelCount channels) + : context (const_cast<T *>(data), samples, 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 + /// "Copy constructor", with unique data, sample 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) {} + ConstProcessContext (ProcessContext const & other, T const * data, samplecnt_t samples, ChannelCount channels) + : context (other, const_cast<T *>(data), samples, channels) {} - /// "Copy constructor", with unique data and frame count, but copies channel count and flags + /// "Copy constructor", with unique data and sample 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) {} + ConstProcessContext (ProcessContext const & other, T const * data, samplecnt_t samples) + : context (other, const_cast<T *>(data), samples) {} - /// "Copy constructor", with unique data, but copies frame and channel count + flags + /// "Copy constructor", with unique data, but copies sample and channel count + flags template<typename ProcessContext> ConstProcessContext (ProcessContext const & other, T const * data) : context (other, const_cast<T *>(data)) {} diff --git a/libs/audiographer/audiographer/routines.h b/libs/audiographer/audiographer/routines.h index d78fa602b6..468580807d 100644 --- a/libs/audiographer/audiographer/routines.h +++ b/libs/audiographer/audiographer/routines.h @@ -25,39 +25,39 @@ class LIBAUDIOGRAPHER_API Routines /** Computes peak in float buffer * \n RT safe * \param data buffer from which the peak is computed - * \param frames length of the portion of \a buffer that is checked + * \param samples length of the portion of \a buffer that is checked * \param current_peak current peak of buffer, if calculated in several passes - * \return maximum of values in [\a data, \a data + \a frames) and \a current_peak + * \return maximum of values in [\a data, \a data + \a samples) and \a current_peak */ - static inline float compute_peak (float const * data, uint_type frames, float current_peak) + static inline float compute_peak (float const * data, uint_type samples, float current_peak) { - return (*_compute_peak) (data, frames, current_peak); + return (*_compute_peak) (data, samples, current_peak); } /** Applies constant gain to buffer * \n RT safe * \param data data to which the gain is applied - * \param frames length of data + * \param samples length of data * \param gain gain that is applied */ - static inline void apply_gain_to_buffer (float * data, uint_type frames, float gain) + static inline void apply_gain_to_buffer (float * data, uint_type samples, float gain) { - (*_apply_gain_to_buffer) (data, frames, gain); + (*_apply_gain_to_buffer) (data, samples, gain); } private: - static inline float default_compute_peak (float const * data, uint_type frames, float current_peak) + static inline float default_compute_peak (float const * data, uint_type samples, float current_peak) { - for (uint_type i = 0; i < frames; ++i) { + for (uint_type i = 0; i < samples; ++i) { float abs = std::fabs(data[i]); if (abs > current_peak) { current_peak = abs; } } return current_peak; } - static inline void default_apply_gain_to_buffer (float * data, uint_type frames, float gain) + static inline void default_apply_gain_to_buffer (float * data, uint_type samples, float gain) { - for (uint_type i = 0; i < frames; ++i) { + for (uint_type i = 0; i < samples; ++i) { data[i] *= gain; } } diff --git a/libs/audiographer/audiographer/sndfile/sndfile.h b/libs/audiographer/audiographer/sndfile/sndfile.h index c48a0331ab..2fccfc458e 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile.h +++ b/libs/audiographer/audiographer/sndfile/sndfile.h @@ -16,7 +16,7 @@ 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) + ChannelCount channels = 0, samplecnt_t samplerate = 0) : SndfileHandle (filename, mode, format, channels, samplerate) {} diff --git a/libs/audiographer/audiographer/sndfile/sndfile_reader.h b/libs/audiographer/audiographer/sndfile/sndfile_reader.h index ea27470d77..b3e84ac40a 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_reader.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_reader.h @@ -25,11 +25,11 @@ class 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) + /** Read data into buffer in \a context, only the data is modified (not sample count) * Note that the data read is output to the outputs, as well as read into the context - * \return number of frames read + * \return number of samples read */ - framecnt_t read (ProcessContext<T> & context) + samplecnt_t read (ProcessContext<T> & context) { if (throw_level (ThrowStrict) && context.channels() != channels() ) { throw Exception (*this, boost::str (boost::format @@ -37,14 +37,14 @@ class SndfileReader % context.channels() % channels())); } - framecnt_t const frames_read = SndfileHandle::read (context.data(), context.frames()); - ProcessContext<T> c_out = context.beginning (frames_read); + samplecnt_t const samples_read = SndfileHandle::read (context.data(), context.samples()); + ProcessContext<T> c_out = context.beginning (samples_read); - if (frames_read < context.frames()) { + if (samples_read < context.samples()) { c_out.set_flag (ProcessContext<T>::EndOfInput); } this->output (c_out); - return frames_read; + return samples_read; } protected: diff --git a/libs/audiographer/audiographer/sndfile/sndfile_writer.h b/libs/audiographer/audiographer/sndfile/sndfile_writer.h index 81f0ddb497..d0049360d2 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_writer.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_writer.h @@ -27,7 +27,7 @@ class SndfileWriter , public FlagDebuggable<> { public: - SndfileWriter (std::string const & path, int format, ChannelCount channels, framecnt_t samplerate, boost::shared_ptr<BroadcastInfo> broadcast_info) + SndfileWriter (std::string const & path, int format, ChannelCount channels, samplecnt_t samplerate, boost::shared_ptr<BroadcastInfo> broadcast_info) : SndfileHandle (path, Write, format, channels, samplerate) , path (path) { @@ -42,8 +42,8 @@ class SndfileWriter using SndfileHandle::operator=; - framecnt_t get_frames_written() const { return frames_written; } - void reset_frames_written_count() { frames_written = 0; } + samplecnt_t get_samples_written() const { return samples_written; } + void reset_samples_written_count() { samples_written = 0; } /// Writes data to file virtual void process (ProcessContext<T> const & c) @@ -56,10 +56,10 @@ class SndfileWriter % c.channels() % channels())); } - framecnt_t const written = write (c.data(), c.frames()); - frames_written += written; + samplecnt_t const written = write (c.data(), c.samples()); + samples_written += written; - if (throw_level (ThrowProcess) && written != c.frames()) { + if (throw_level (ThrowProcess) && written != c.samples()) { throw Exception (*this, boost::str (boost::format ("Could not write data to output file (%1%)") % strError())); @@ -84,13 +84,13 @@ class SndfileWriter virtual void init() { - frames_written = 0; + samples_written = 0; add_supported_flag (ProcessContext<T>::EndOfInput); } protected: std::string path; - framecnt_t frames_written; + samplecnt_t samples_written; private: SndfileWriter (SndfileWriter const & other) {} diff --git a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h index 4207d3da75..1e2786252b 100644 --- a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h +++ b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h @@ -17,7 +17,7 @@ namespace AudioGrapher { - static const framecnt_t rb_chunksize = 8192; // samples + static const samplecnt_t rb_chunksize = 8192; // samples /** A temporary file deleted after this class is destructed * with realtime safe background thread writer. @@ -29,7 +29,7 @@ class TmpFileRt public: /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX" - TmpFileRt (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate) + TmpFileRt (char * filename_template, int format, ChannelCount channels, samplecnt_t samplerate) : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate) , filename (filename_template) , _chunksize (rb_chunksize * channels) @@ -65,13 +65,13 @@ class TmpFileRt % c.channels() % SndfileHandle::channels())); } - if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < c.frames()) { + if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < c.samples()) { throw Exception (*this, boost::str (boost::format ("Could not write data to ringbuffer/output file (%1%)") % SndfileHandle::strError())); } - _rb.write (c.data(), c.frames()); + _rb.write (c.data(), c.samples()); if (c.has_flag(ProcessContext<T>::EndOfInput)) { _capture = false; @@ -93,11 +93,11 @@ class TmpFileRt pthread_mutex_lock (&_disk_thread_lock); while (_capture) { - if ((framecnt_t)_rb.read_space () >= _chunksize) { + if ((samplecnt_t)_rb.read_space () >= _chunksize) { _rb.read (framebuf, _chunksize); - framecnt_t const written = SndfileBase::write (framebuf, _chunksize); + samplecnt_t const written = SndfileBase::write (framebuf, _chunksize); assert (written == _chunksize); - SndfileWriter<T>::frames_written += written; + SndfileWriter<T>::samples_written += written; } if (!_capture) { break; @@ -107,10 +107,10 @@ class TmpFileRt // flush ringbuffer while (_rb.read_space () > 0) { - size_t remain = std::min ((framecnt_t)_rb.read_space (), _chunksize); + size_t remain = std::min ((samplecnt_t)_rb.read_space (), _chunksize); _rb.read (framebuf, remain); - framecnt_t const written = SndfileBase::write (framebuf, remain); - SndfileWriter<T>::frames_written += written; + samplecnt_t const written = SndfileBase::write (framebuf, remain); + SndfileWriter<T>::samples_written += written; } SndfileWriter<T>::writeSync(); @@ -123,7 +123,7 @@ class TmpFileRt std::string filename; bool _capture; - framecnt_t _chunksize; + samplecnt_t _chunksize; PBD::RingBuffer<T> _rb; pthread_mutex_t _disk_thread_lock; @@ -148,7 +148,7 @@ class TmpFileRt void init() { - SndfileWriter<T>::frames_written = 0; + SndfileWriter<T>::samples_written = 0; _capture = true; SndfileWriter<T>::add_supported_flag (ProcessContext<T>::EndOfInput); pthread_mutex_init (&_disk_thread_lock, 0); diff --git a/libs/audiographer/audiographer/sndfile/tmp_file_sync.h b/libs/audiographer/audiographer/sndfile/tmp_file_sync.h index 7807346935..8eab56a3a6 100644 --- a/libs/audiographer/audiographer/sndfile/tmp_file_sync.h +++ b/libs/audiographer/audiographer/sndfile/tmp_file_sync.h @@ -22,12 +22,12 @@ class TmpFileSync public: /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX" - TmpFileSync (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate) + TmpFileSync (char * filename_template, int format, ChannelCount channels, samplecnt_t samplerate) : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate) , filename (filename_template) {} - TmpFileSync (int format, ChannelCount channels, framecnt_t samplerate) + TmpFileSync (int format, ChannelCount channels, samplecnt_t samplerate) : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate) {} diff --git a/libs/audiographer/audiographer/type_utils.h b/libs/audiographer/audiographer/type_utils.h index 4e12937165..c16b0f942a 100644 --- a/libs/audiographer/audiographer/type_utils.h +++ b/libs/audiographer/audiographer/type_utils.h @@ -19,12 +19,12 @@ 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()); } + static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::integral_constant<bool, b>&) + { std::uninitialized_fill_n (buffer, samples, T()); } template<typename T> - static void do_zero_fill(T * buffer, framecnt_t frames, const boost::true_type&) - { memset (buffer, 0, frames * sizeof(T)); } + static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::true_type&) + { memset (buffer, 0, samples * sizeof(T)); } }; /// Utilities for initializing, copying, moving, etc. data @@ -42,26 +42,26 @@ class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase * if T is not a floating point or signed integer type * \n RT safe */ - inline static void zero_fill (T * buffer, framecnt_t frames) - { do_zero_fill(buffer, frames, zero_fillable()); } + inline static void zero_fill (T * buffer, samplecnt_t samples) + { do_zero_fill(buffer, samples, zero_fillable()); } - /** Copies \a frames frames of data from \a source to \a destination + /** Copies \a samples 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); } + inline static void copy (T const * source, T * destination, samplecnt_t samples) + { std::uninitialized_copy (source, &source[samples], destination); } - /** Moves \a frames frames of data from \a source to \a destination + /** Moves \a samples frames of data from \a source to \a destination * The source and destination may overlap in any way. * \n RT safe */ - inline static void move (T const * source, T * destination, framecnt_t frames) + inline static void move (T const * source, T * destination, samplecnt_t samples) { if (destination < source) { - std::copy (source, &source[frames], destination); + std::copy (source, &source[samples], destination); } else if (destination > source) { - std::copy_backward (source, &source[frames], destination + frames); + std::copy_backward (source, &source[samples], destination + samples); } } }; diff --git a/libs/audiographer/audiographer/types.h b/libs/audiographer/audiographer/types.h index 1ecf6360a0..faa3ad4f31 100644 --- a/libs/audiographer/audiographer/types.h +++ b/libs/audiographer/audiographer/types.h @@ -8,7 +8,7 @@ namespace AudioGrapher { /* XXX: copied from libardour */ -typedef int64_t framecnt_t; +typedef int64_t samplecnt_t; typedef uint8_t ChannelCount; diff --git a/libs/audiographer/src/general/analyser.cc b/libs/audiographer/src/general/analyser.cc index 84120b6f53..05491c9da0 100644 --- a/libs/audiographer/src/general/analyser.cc +++ b/libs/audiographer/src/general/analyser.cc @@ -23,7 +23,7 @@ using namespace AudioGrapher; const float Analyser::fft_range_db (120); // dB -Analyser::Analyser (float sample_rate, unsigned int channels, framecnt_t bufsize, framecnt_t n_samples) +Analyser::Analyser (float sample_rate, unsigned int channels, samplecnt_t bufsize, samplecnt_t n_samples) : LoudnessReader (sample_rate, channels, bufsize) , _n_samples (n_samples) , _pos (0) @@ -104,11 +104,11 @@ Analyser::~Analyser () void Analyser::process (ProcessContext<float> const & ctx) { - const framecnt_t n_samples = ctx.frames () / ctx.channels (); + const samplecnt_t n_samples = ctx.samples () / ctx.channels (); assert (ctx.channels () == _channels); - assert (ctx.frames () % ctx.channels () == 0); + assert (ctx.samples () % ctx.channels () == 0); assert (n_samples <= _bufsize); - //printf ("PROC %p @%ld F: %ld, S: %ld C:%d\n", this, _pos, ctx.frames (), n_samples, ctx.channels ()); + //printf ("PROC %p @%ld F: %ld, S: %ld C:%d\n", this, _pos, ctx.samples (), n_samples, ctx.channels ()); // allow 1 sample slack for resampling if (_pos + n_samples > _n_samples + 1) { @@ -118,11 +118,11 @@ Analyser::process (ProcessContext<float> const & ctx) } float const * d = ctx.data (); - framecnt_t s; + samplecnt_t s; const unsigned cmask = _result.n_channels - 1; // [0, 1] for (s = 0; s < n_samples; ++s) { _fft_data_in[s] = 0; - const framecnt_t pbin = (_pos + s) / _spp; + const samplecnt_t pbin = (_pos + s) / _spp; for (unsigned int c = 0; c < _channels; ++c) { const float v = *d; if (fabsf(v) > _result.peak) { _result.peak = fabsf(v); } @@ -169,8 +169,8 @@ Analyser::process (ProcessContext<float> const & ctx) #undef FIm const size_t height = sizeof (_result.spectrum[0]) / sizeof (float); - const framecnt_t x0 = _pos / _fpp; - framecnt_t x1 = (_pos + n_samples) / _fpp; + const samplecnt_t x0 = _pos / _fpp; + samplecnt_t x1 = (_pos + n_samples) / _fpp; if (x0 == x1) x1 = x0 + 1; for (uint32_t i = 0; i < _fft_data_size - 1; ++i) { @@ -212,9 +212,9 @@ Analyser::result () if (_pos + 1 < _n_samples) { // crude re-bin (silence stripped version) const size_t peaks = sizeof (_result.peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4; - for (framecnt_t b = peaks - 1; b > 0; --b) { + for (samplecnt_t b = peaks - 1; b > 0; --b) { for (unsigned int c = 0; c < _result.n_channels; ++c) { - const framecnt_t sb = b * _pos / _n_samples; + const samplecnt_t sb = b * _pos / _n_samples; _result.peaks[c][b].min = _result.peaks[c][sb].min; _result.peaks[c][b].max = _result.peaks[c][sb].max; } @@ -223,9 +223,9 @@ Analyser::result () const size_t swh = sizeof (_result.spectrum) / sizeof (float); const size_t height = sizeof (_result.spectrum[0]) / sizeof (float); const size_t width = swh / height; - for (framecnt_t b = width - 1; b > 0; --b) { + for (samplecnt_t b = width - 1; b > 0; --b) { // TODO round down to prev _fft_data_size bin - const framecnt_t sb = b * _pos / _n_samples; + const samplecnt_t sb = b * _pos / _n_samples; for (unsigned int y = 0; y < height; ++y) { _result.spectrum[b][y] = _result.spectrum[sb][y]; } @@ -258,7 +258,7 @@ Analyser::result () for (std::vector<float>::const_iterator i = features[1][0].values.begin(); i != features[1][0].values.end(); ++i) { - const framecnt_t pk = (*i) / _spp; + const samplecnt_t pk = (*i) / _spp; const unsigned int cc = c & cmask; _result.truepeakpos[cc].insert (pk); } diff --git a/libs/audiographer/src/general/loudness_reader.cc b/libs/audiographer/src/general/loudness_reader.cc index 0c2e361fde..924a047561 100644 --- a/libs/audiographer/src/general/loudness_reader.cc +++ b/libs/audiographer/src/general/loudness_reader.cc @@ -21,7 +21,7 @@ using namespace AudioGrapher; -LoudnessReader::LoudnessReader (float sample_rate, unsigned int channels, framecnt_t bufsize) +LoudnessReader::LoudnessReader (float sample_rate, unsigned int channels, samplecnt_t bufsize) : _ebur_plugin (0) , _dbtp_plugin (0) , _sample_rate (sample_rate) @@ -91,17 +91,17 @@ LoudnessReader::reset () void LoudnessReader::process (ProcessContext<float> const & ctx) { - const framecnt_t n_samples = ctx.frames () / ctx.channels (); + const samplecnt_t n_samples = ctx.samples () / ctx.channels (); assert (ctx.channels () == _channels); - assert (ctx.frames () % ctx.channels () == 0); + assert (ctx.samples () % ctx.channels () == 0); assert (n_samples <= _bufsize); - //printf ("PROC %p @%ld F: %ld, S: %ld C:%d\n", this, _pos, ctx.frames (), n_samples, ctx.channels ()); + //printf ("PROC %p @%ld F: %ld, S: %ld C:%d\n", this, _pos, ctx.samples (), n_samples, ctx.channels ()); unsigned processed_channels = 0; if (_ebur_plugin) { assert (_channels <= 2); processed_channels = _channels; - framecnt_t s; + samplecnt_t s; float const * d = ctx.data (); for (s = 0; s < n_samples; ++s) { for (unsigned int c = 0; c < _channels; ++c, ++d) { @@ -126,7 +126,7 @@ LoudnessReader::process (ProcessContext<float> const & ctx) if (!_dbtp_plugin[c]) { continue; } - framecnt_t s; + samplecnt_t s; float const * const d = ctx.data (); for (s = 0; s < n_samples; ++s) { _bufs[0][s] = d[s * _channels + c]; diff --git a/libs/audiographer/src/general/normalizer.cc b/libs/audiographer/src/general/normalizer.cc index a10382031a..ae603ef946 100644 --- a/libs/audiographer/src/general/normalizer.cc +++ b/libs/audiographer/src/general/normalizer.cc @@ -54,23 +54,23 @@ float Normalizer::set_peak (float peak) * non-const ProcessContexts are given to \a process() . * \n Not RT safe */ -void Normalizer::alloc_buffer(framecnt_t frames) +void Normalizer::alloc_buffer(samplecnt_t samples) { delete [] buffer; - buffer = new float[frames]; - buffer_size = frames; + buffer = new float[samples]; + buffer_size = samples; } /// Process a const ProcessContext \see alloc_buffer() \n RT safe 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 (throw_level (ThrowProcess) && c.samples() > buffer_size) { + throw Exception (*this, "Too many samples given to process()"); } if (enabled) { - memcpy (buffer, c.data(), c.frames() * sizeof(float)); - Routines::apply_gain_to_buffer (buffer, c.frames(), gain); + memcpy (buffer, c.data(), c.samples() * sizeof(float)); + Routines::apply_gain_to_buffer (buffer, c.samples(), gain); } ProcessContext<float> c_out (c, buffer); @@ -81,7 +81,7 @@ void Normalizer::process (ProcessContext<float> const & c) void Normalizer::process (ProcessContext<float> & c) { if (enabled) { - Routines::apply_gain_to_buffer (c.data(), c.frames(), gain); + Routines::apply_gain_to_buffer (c.data(), c.samples(), gain); } ListedSource<float>::output(c); } diff --git a/libs/audiographer/src/general/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index 1f79818a8b..fbe509fca5 100644 --- a/libs/audiographer/src/general/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -41,18 +41,18 @@ SampleFormatConverter<TOut>::SampleFormatConverter (ChannelCount channels) : template <> void -SampleFormatConverter<float>::init (framecnt_t max_frames, int /* type */, int data_width) +SampleFormatConverter<float>::init (samplecnt_t max_samples, int /* type */, int data_width) { if (throw_level (ThrowObject) && data_width != 32) { throw Exception (*this, "Unsupported data width"); } - init_common (max_frames); + init_common (max_samples); dither = gdither_new (GDitherNone, channels, GDitherFloat, data_width); } template <> void -SampleFormatConverter<int32_t>::init (framecnt_t max_frames, int type, int data_width) +SampleFormatConverter<int32_t>::init (samplecnt_t max_samples, int type, int data_width) { if(throw_level (ThrowObject) && data_width > 32) { throw Exception (*this, "Trying to use SampleFormatConverter<int32_t> with a data width > 32"); @@ -62,47 +62,47 @@ SampleFormatConverter<int32_t>::init (framecnt_t max_frames, int type, int data_ // And since floats only have 24 bits of data, we are fine with this. data_width = std::min(data_width, 24); - init_common (max_frames); + init_common (max_samples); dither = gdither_new ((GDitherType) type, channels, GDither32bit, data_width); } template <> void -SampleFormatConverter<int16_t>::init (framecnt_t max_frames, int type, int data_width) +SampleFormatConverter<int16_t>::init (samplecnt_t max_samples, int type, int data_width) { if (throw_level (ThrowObject) && data_width > 16) { throw Exception (*this, boost::str(boost::format ("Data width (%1%) too large for int16_t") % data_width)); } - init_common (max_frames); + init_common (max_samples); dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width); } template <> void -SampleFormatConverter<uint8_t>::init (framecnt_t max_frames, int type, int data_width) +SampleFormatConverter<uint8_t>::init (samplecnt_t max_samples, int type, int data_width) { if (throw_level (ThrowObject) && data_width > 8) { throw Exception (*this, boost::str(boost::format ("Data width (%1%) too large for uint8_t") % data_width)); } - init_common (max_frames); + init_common (max_samples); dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width); } template <typename TOut> void -SampleFormatConverter<TOut>::init_common (framecnt_t max_frames) +SampleFormatConverter<TOut>::init_common (samplecnt_t max_samples) { reset(); - if (max_frames > data_out_size) { + if (max_samples > data_out_size) { delete[] data_out; - data_out = new TOut[max_frames]; - data_out_size = max_frames; + data_out = new TOut[max_samples]; + data_out_size = max_samples; } } @@ -135,12 +135,12 @@ 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 ()); + check_sample_and_channel_count (c_in.samples (), c_in.channels ()); /* Do conversion */ for (uint32_t chn = 0; chn < c_in.channels(); ++chn) { - gdither_runf (dither, chn, c_in.frames_per_channel (), data, data_out); + gdither_runf (dither, chn, c_in.samples_per_channel (), data, data_out); } /* Write forward */ @@ -162,11 +162,11 @@ template<> void SampleFormatConverter<float>::process (ProcessContext<float> & c_in) { - framecnt_t frames = c_in.frames(); + samplecnt_t samples = c_in.samples(); float * data = c_in.data(); if (clip_floats) { - for (framecnt_t x = 0; x < frames; ++x) { + for (samplecnt_t x = 0; x < samples; ++x) { if (data[x] > 1.0f) { data[x] = 1.0f; } else if (data[x] < -1.0f) { @@ -184,8 +184,8 @@ void 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()); + check_sample_and_channel_count (c_in.samples(), c_in.channels()); + TypeUtils<float>::copy (c_in.data(), data_out, c_in.samples()); ProcessContext<float> c (c_in, data_out); process (c); @@ -193,7 +193,7 @@ SampleFormatConverter<float>::process (ProcessContext<float> const & c_in) template<typename TOut> void -SampleFormatConverter<TOut>::check_frame_and_channel_count (framecnt_t frames, ChannelCount channels_) +SampleFormatConverter<TOut>::check_sample_and_channel_count (samplecnt_t samples, ChannelCount channels_) { if (throw_level (ThrowStrict) && channels_ != channels) { throw Exception (*this, boost::str (boost::format @@ -201,10 +201,10 @@ SampleFormatConverter<TOut>::check_frame_and_channel_count (framecnt_t frames, C % channels_ % channels)); } - if (throw_level (ThrowProcess) && frames > data_out_size) { + if (throw_level (ThrowProcess) && samples > data_out_size) { throw Exception (*this, boost::str (boost::format - ("Too many frames given to process(), %1% instad of %2%") - % frames % data_out_size)); + ("Too many samples given to process(), %1% instad of %2%") + % samples % data_out_size)); } } diff --git a/libs/audiographer/src/general/sr_converter.cc b/libs/audiographer/src/general/sr_converter.cc index 1468e6a734..a4d19593f0 100644 --- a/libs/audiographer/src/general/sr_converter.cc +++ b/libs/audiographer/src/general/sr_converter.cc @@ -34,10 +34,10 @@ using boost::str; SampleRateConverter::SampleRateConverter (uint32_t channels) : active (false) , channels (channels) - , max_frames_in(0) + , max_samples_in(0) , leftover_data (0) - , leftover_frames (0) - , max_leftover_frames (0) + , leftover_samples (0) + , max_leftover_samples (0) , data_out (0) , data_out_size (0) , src_state (0) @@ -46,7 +46,7 @@ SampleRateConverter::SampleRateConverter (uint32_t channels) } void -SampleRateConverter::init (framecnt_t in_rate, framecnt_t out_rate, int quality) +SampleRateConverter::init (samplecnt_t in_rate, samplecnt_t out_rate, int quality) { reset(); @@ -72,31 +72,31 @@ SampleRateConverter::~SampleRateConverter () reset(); } -framecnt_t -SampleRateConverter::allocate_buffers (framecnt_t max_frames) +samplecnt_t +SampleRateConverter::allocate_buffers (samplecnt_t max_samples) { - if (!active) { return max_frames; } + if (!active) { return max_samples; } - framecnt_t max_frames_out = (framecnt_t) ceil (max_frames * src_data.src_ratio); - max_frames_out -= max_frames_out % channels; + samplecnt_t max_samples_out = (samplecnt_t) ceil (max_samples * src_data.src_ratio); + max_samples_out -= max_samples_out % channels; - if (data_out_size < max_frames_out) { + if (data_out_size < max_samples_out) { delete[] data_out; - data_out = new float[max_frames_out]; + data_out = new float[max_samples_out]; src_data.data_out = data_out; - max_leftover_frames = 4 * max_frames; - leftover_data = (float *) realloc (leftover_data, max_leftover_frames * sizeof (float)); + max_leftover_samples = 4 * max_samples; + leftover_data = (float *) realloc (leftover_data, max_leftover_samples * sizeof (float)); if (throw_level (ThrowObject) && !leftover_data) { throw Exception (*this, "A memory allocation error occurred"); } - max_frames_in = max_frames; - data_out_size = max_frames_out; + max_samples_in = max_samples; + data_out_size = max_samples_out; } - return max_frames_out; + return max_samples_out; } void @@ -109,13 +109,13 @@ SampleRateConverter::process (ProcessContext<float> const & c) return; } - framecnt_t frames = c.frames(); + samplecnt_t samples = c.samples(); float * in = const_cast<float *> (c.data()); // TODO check if this is safe! - if (throw_level (ThrowProcess) && frames > max_frames_in) { + if (throw_level (ThrowProcess) && samples > max_samples_in) { throw Exception (*this, str (format ( - "process() called with too many frames, %1% instead of %2%") - % frames % max_frames_in)); + "process() called with too many samples, %1% instead of %2%") + % samples % max_samples_in)); } int err; @@ -125,7 +125,7 @@ SampleRateConverter::process (ProcessContext<float> const & c) src_data.output_frames = data_out_size / channels; src_data.data_out = data_out; - if (leftover_frames > 0) { + if (leftover_samples > 0) { /* input data will be in leftover_data rather than data_in */ @@ -135,8 +135,8 @@ SampleRateConverter::process (ProcessContext<float> const & c) /* first time, append new data from data_in into the leftover_data buffer */ - TypeUtils<float>::copy (in, &leftover_data [leftover_frames * channels], frames); - src_data.input_frames = frames / channels + leftover_frames; + TypeUtils<float>::copy (in, &leftover_data [leftover_samples * channels], samples); + src_data.input_frames = samples / channels + leftover_samples; } else { /* otherwise, just use whatever is still left in leftover_data; the contents @@ -144,12 +144,12 @@ SampleRateConverter::process (ProcessContext<float> const & c) below) */ - src_data.input_frames = leftover_frames; + src_data.input_frames = leftover_samples; } } else { src_data.data_in = in; - src_data.input_frames = frames / channels; + src_data.input_frames = samples / channels; } first_time = false; @@ -168,18 +168,18 @@ SampleRateConverter::process (ProcessContext<float> const & c) % src_strerror (err))); } - leftover_frames = src_data.input_frames - src_data.input_frames_used; + leftover_samples = src_data.input_frames - src_data.input_frames_used; - if (leftover_frames > 0) { - if (throw_level (ThrowProcess) && leftover_frames > max_leftover_frames) { - throw Exception(*this, "leftover frames overflowed"); + if (leftover_samples > 0) { + if (throw_level (ThrowProcess) && leftover_samples > max_leftover_samples) { + throw Exception(*this, "leftover samples overflowed"); } TypeUtils<float>::move (&src_data.data_in[src_data.input_frames_used * channels], - leftover_data, leftover_frames * channels); + leftover_data, leftover_samples * channels); } ProcessContext<float> c_out (c, data_out, src_data.output_frames_gen * channels); - if (!src_data.end_of_input || leftover_frames) { + if (!src_data.end_of_input || leftover_samples) { c_out.remove_flag (ProcessContext<float>::EndOfInput); } output (c_out); @@ -187,16 +187,16 @@ SampleRateConverter::process (ProcessContext<float> const & c) if (debug_level (DebugProcess)) { debug_stream() << "src_data.output_frames_gen: " << src_data.output_frames_gen << - ", leftover_frames: " << leftover_frames << std::endl; + ", leftover_samples: " << leftover_samples << std::endl; } - if (throw_level (ThrowProcess) && src_data.output_frames_gen == 0 && leftover_frames) { + if (throw_level (ThrowProcess) && src_data.output_frames_gen == 0 && leftover_samples) { throw Exception (*this, boost::str (boost::format - ("No output frames generated with %1% leftover frames") - % leftover_frames)); + ("No output samples generated with %1% leftover samples") + % leftover_samples)); } - } while (leftover_frames > frames); + } while (leftover_samples > samples); // 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)) { @@ -224,15 +224,15 @@ void SampleRateConverter::set_end_of_input (ProcessContext<float> const & c) void SampleRateConverter::reset () { active = false; - max_frames_in = 0; + max_samples_in = 0; src_data.end_of_input = false; if (src_state) { src_delete (src_state); } - leftover_frames = 0; - max_leftover_frames = 0; + leftover_samples = 0; + max_leftover_samples = 0; if (leftover_data) { free (leftover_data); } diff --git a/libs/audiographer/tests/general/chunker_test.cc b/libs/audiographer/tests/general/chunker_test.cc index 12b5da5dbc..b7896e23e6 100644 --- a/libs/audiographer/tests/general/chunker_test.cc +++ b/libs/audiographer/tests/general/chunker_test.cc @@ -20,10 +20,10 @@ class ChunkerTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames); + samples = 128; + random_data = TestUtils::init_random_data(samples); sink.reset (new VectorSink<float>()); - chunker.reset (new Chunker<float>(frames * 2)); + chunker.reset (new Chunker<float>(samples * 2)); } void tearDown() @@ -34,119 +34,119 @@ class ChunkerTest : public CppUnit::TestFixture void testSynchronousProcess() { chunker->add_output (sink); - framecnt_t frames_output = 0; + samplecnt_t samples_output = 0; - ProcessContext<float> const context (random_data, frames, 1); + ProcessContext<float> const context (random_data, samples, 1); chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (2 * samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[samples], samples)); sink->reset(); chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (2 * samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[samples], samples)); } void testAsynchronousProcess() { - assert (frames % 2 == 0); + assert (samples % 2 == 0); chunker->add_output (sink); - framecnt_t frames_output = 0; + samplecnt_t samples_output = 0; - ProcessContext<float> const half_context (random_data, frames / 2, 1); - ProcessContext<float> const context (random_data, frames, 1); + ProcessContext<float> const half_context (random_data, samples / 2, 1); + ProcessContext<float> const context (random_data, samples, 1); // 0.5 chunker->process (half_context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_output); // 1.5 chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_output); // 2.5 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 / 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (2 * samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), samples / 2)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[samples / 2], samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * samples / 2], samples / 2)); sink->reset(); // 3.5 chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_output); // 4.0 chunker->process (half_context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (2 * frames, frames_output); - CPPUNIT_ASSERT (TestUtils::array_equals (&random_data[frames / 2], 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (2 * samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals (&random_data[samples / 2], sink->get_array(), samples / 2)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[samples / 2], samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * samples / 2], samples / 2)); } void testChoppingProcess() { sink.reset (new AppendingVectorSink<float>()); - assert (frames % 2 == 0); - chunker.reset (new Chunker<float>(frames / 4)); + assert (samples % 2 == 0); + chunker.reset (new Chunker<float>(samples / 4)); chunker->add_output (sink); - framecnt_t frames_output = 0; + samplecnt_t samples_output = 0; - ProcessContext<float> const half_context (random_data, frames / 2, 1); - ProcessContext<float> const context (random_data, frames, 1); + ProcessContext<float> const half_context (random_data, samples / 2, 1); + ProcessContext<float> const context (random_data, samples, 1); // 0.5 chunker->process (half_context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) samples / 2, samples_output); // 1.5 chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2 * 3, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) samples / 2 * 3, samples_output); // 2.5 chunker->process (context); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames / 2 * 5, frames_output); - 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples / 2 * 5, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), samples / 2)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[samples / 2], samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * samples / 2], samples / 2)); } void testEndOfInputFlagHandling() { boost::shared_ptr<ProcessContextGrabber<float> > grabber(new ProcessContextGrabber<float>()); - assert (frames % 2 == 0); - chunker.reset (new Chunker<float>(frames)); + assert (samples % 2 == 0); + chunker.reset (new Chunker<float>(samples)); chunker->add_output (grabber); - ProcessContext<float> const half_context (random_data, frames / 2, 1); - ProcessContext<float> const context (random_data, frames, 1); + ProcessContext<float> const half_context (random_data, samples / 2, 1); + ProcessContext<float> const context (random_data, samples, 1); context.set_flag(ProcessContext<>::EndOfInput); // Process 0.5 then 1.0 @@ -158,12 +158,12 @@ class ChunkerTest : public CppUnit::TestFixture ProcessContextGrabber<float>::ContextList::iterator it = grabber->contexts.begin(); // first 1.0 not end of input - CPPUNIT_ASSERT_EQUAL(it->frames(), frames); + CPPUNIT_ASSERT_EQUAL(it->samples(), samples); CPPUNIT_ASSERT(!it->has_flag(ProcessContext<>::EndOfInput)); // Then 0.5 with end of input ++it; - CPPUNIT_ASSERT_EQUAL(it->frames(), frames / 2); + CPPUNIT_ASSERT_EQUAL(it->samples(), samples / 2); CPPUNIT_ASSERT(it->has_flag(ProcessContext<>::EndOfInput)); } @@ -172,7 +172,7 @@ class ChunkerTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (ChunkerTest); diff --git a/libs/audiographer/tests/general/deinterleaver_test.cc b/libs/audiographer/tests/general/deinterleaver_test.cc index f7e15459b3..66d5362d80 100644 --- a/libs/audiographer/tests/general/deinterleaver_test.cc +++ b/libs/audiographer/tests/general/deinterleaver_test.cc @@ -18,9 +18,9 @@ class DeInterleaverTest : public CppUnit::TestFixture void setUp() { channels = 3; - frames_per_channel = 128; - total_frames = channels * frames_per_channel; - random_data = TestUtils::init_random_data (total_frames, 1.0); + samples_per_channel = 128; + total_samples = channels * samples_per_channel; + random_data = TestUtils::init_random_data (total_samples, 1.0); deinterleaver.reset (new DeInterleaver<float>()); sink_a.reset (new VectorSink<float>()); @@ -41,74 +41,74 @@ class DeInterleaverTest : public CppUnit::TestFixture void testInvalidOutputIndex() { - deinterleaver->init (3, frames_per_channel); + deinterleaver->init (3, samples_per_channel); CPPUNIT_ASSERT_THROW (deinterleaver->output(3)->add_output (sink_a), Exception); } void testInvalidInputSize() { - deinterleaver->init (channels, frames_per_channel); + deinterleaver->init (channels, samples_per_channel); - ProcessContext<float> c (random_data, 2 * total_frames, channels); + ProcessContext<float> c (random_data, 2 * total_samples, channels); - // Too many, frames % channels == 0 - CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + channels)), Exception); + // Too many, samples % channels == 0 + CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples + channels)), Exception); - // Too many, frames % channels != 0 - CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + 1)), Exception); + // Too many, samples % channels != 0 + CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples + 1)), Exception); - // Too few, frames % channels != 0 - CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames - 1)), Exception); + // Too few, samples % channels != 0 + CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples - 1)), Exception); } - void assert_outputs (framecnt_t expected_frames) + void assert_outputs (samplecnt_t expected_samples) { - framecnt_t generated_frames = 0; + samplecnt_t generated_samples = 0; - generated_frames = sink_a->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + generated_samples = sink_a->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); - generated_frames = sink_b->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + generated_samples = sink_b->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); - generated_frames = sink_c->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + generated_samples = sink_c->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); } void testOutputSize() { - deinterleaver->init (channels, frames_per_channel); + deinterleaver->init (channels, samples_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); + // Test maximum sample input + ProcessContext<float> c (random_data, total_samples, channels); deinterleaver->process (c); - assert_outputs (frames_per_channel); + assert_outputs (samples_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); + // Now with less samples + samplecnt_t const less_samples = samples_per_channel / 4; + deinterleaver->process (c.beginning (less_samples * channels)); + assert_outputs (less_samples); } void testZeroInput() { - deinterleaver->init (channels, frames_per_channel); + deinterleaver->init (channels, samples_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); + // Input zero samples + ProcessContext<float> c (random_data, total_samples, channels); deinterleaver->process (c.beginning (0)); // ...and now test regular input deinterleaver->process (c); - assert_outputs (frames_per_channel); + assert_outputs (samples_per_channel); } @@ -120,8 +120,8 @@ class DeInterleaverTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink_c; float * random_data; - framecnt_t frames_per_channel; - framecnt_t total_frames; + samplecnt_t samples_per_channel; + samplecnt_t total_samples; unsigned int channels; }; diff --git a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc index 4f46a83492..b16a47a795 100644 --- a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc @@ -16,12 +16,12 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture void setUp() { channels = 3; - frames_per_channel = 128; - total_frames = channels * frames_per_channel; + samples_per_channel = 128; + total_samples = channels * samples_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); + random_data_a = TestUtils::init_random_data (total_samples, 1.0); + random_data_b = TestUtils::init_random_data (samples_per_channel, 1.0); + random_data_c = TestUtils::init_random_data (samples_per_channel, 1.0); deinterleaver.reset (new DeInterleaver<float>()); interleaver.reset (new Interleaver<float>()); @@ -40,8 +40,8 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture void testInterleavedInput() { - deinterleaver->init (channels, frames_per_channel); - interleaver->init (channels, frames_per_channel); + deinterleaver->init (channels, samples_per_channel); + interleaver->init (channels, samples_per_channel); deinterleaver->output (0)->add_output (interleaver->input (0)); deinterleaver->output (1)->add_output (interleaver->input (1)); @@ -50,20 +50,20 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture interleaver->add_output (sink_a); // Process and assert - ProcessContext<float> c (random_data_a, total_frames, channels); + ProcessContext<float> c (random_data_a, total_samples, channels); deinterleaver->process (c); - CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_frames)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_samples)); // 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)); + samplecnt_t less_samples = (samples_per_channel / 10) * channels; + deinterleaver->process (c.beginning (less_samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_samples)); } void testDeInterleavedInput() { - deinterleaver->init (channels, frames_per_channel); - interleaver->init (channels, frames_per_channel); + deinterleaver->init (channels, samples_per_channel); + interleaver->init (channels, samples_per_channel); interleaver->add_output (deinterleaver); @@ -71,28 +71,28 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture 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); + ProcessContext<float> c_a (random_data_a, samples_per_channel, 1); + ProcessContext<float> c_b (random_data_b, samples_per_channel, 1); + ProcessContext<float> c_c (random_data_c, samples_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)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), samples_per_channel)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), samples_per_channel)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), samples_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)); + samplecnt_t less_samples = samples_per_channel / 5; + interleaver->input (0)->process (c_a.beginning (less_samples)); + interleaver->input (1)->process (c_b.beginning (less_samples)); + interleaver->input (2)->process (c_c.beginning (less_samples)); - 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)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), less_samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), less_samples)); } @@ -108,8 +108,8 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture float * random_data_b; float * random_data_c; - framecnt_t frames_per_channel; - framecnt_t total_frames; + samplecnt_t samples_per_channel; + samplecnt_t total_samples; unsigned int channels; }; diff --git a/libs/audiographer/tests/general/interleaver_test.cc b/libs/audiographer/tests/general/interleaver_test.cc index 0b8f8b6952..7adc0387a8 100644 --- a/libs/audiographer/tests/general/interleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_test.cc @@ -19,13 +19,13 @@ class InterleaverTest : public CppUnit::TestFixture void setUp() { channels = 3; - frames = 128; - random_data = TestUtils::init_random_data (frames, 1.0); + samples = 128; + random_data = TestUtils::init_random_data (samples, 1.0); interleaver.reset (new Interleaver<float>()); sink.reset (new VectorSink<float>()); - interleaver->init (channels, frames); + interleaver->init (channels, samples); } void tearDown() @@ -36,59 +36,59 @@ class InterleaverTest : public CppUnit::TestFixture void testUninitialized() { interleaver.reset (new Interleaver<float>()); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); CPPUNIT_ASSERT_THROW (interleaver->input(0)->process (c), Exception); } void testInvalidInputIndex() { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); CPPUNIT_ASSERT_THROW (interleaver->input (3)->process (c), Exception); } void testInvalidInputSize() { - ProcessContext<float> c (random_data, frames + 1, 1); + ProcessContext<float> c (random_data, samples + 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); + interleaver->input (0)->process (c.beginning (samples)); + interleaver->input (1)->process (c.beginning (samples)); + CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (samples - 1)), Exception); - interleaver->input (0)->process (c.beginning (frames - 1)); - interleaver->input (1)->process (c.beginning (frames - 1)); - CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (frames)), Exception); + interleaver->input (0)->process (c.beginning (samples - 1)); + interleaver->input (1)->process (c.beginning (samples - 1)); + CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (samples)), Exception); } void testOutputSize() { interleaver->add_output (sink); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); interleaver->input (0)->process (c); interleaver->input (1)->process (c); interleaver->input (2)->process (c); - framecnt_t expected_frames = frames * channels; - framecnt_t generated_frames = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + samplecnt_t expected_samples = samples * channels; + samplecnt_t generated_samples = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); - framecnt_t less_frames = frames / 2; - interleaver->input (0)->process (c.beginning (less_frames)); - interleaver->input (1)->process (c.beginning (less_frames)); - interleaver->input (2)->process (c.beginning (less_frames)); + samplecnt_t less_samples = samples / 2; + interleaver->input (0)->process (c.beginning (less_samples)); + interleaver->input (1)->process (c.beginning (less_samples)); + interleaver->input (2)->process (c.beginning (less_samples)); - expected_frames = less_frames * channels; - generated_frames = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + expected_samples = less_samples * channels; + generated_samples = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); } void testZeroInput() { interleaver->add_output (sink); - // input zero frames to all inputs - ProcessContext<float> c (random_data, frames, 1); + // input zero samples to all inputs + ProcessContext<float> c (random_data, samples, 1); interleaver->input (0)->process (c.beginning (0)); interleaver->input (1)->process (c.beginning (0)); interleaver->input (2)->process (c.beginning (0)); @@ -100,15 +100,15 @@ class InterleaverTest : public CppUnit::TestFixture interleaver->input (1)->process (c); interleaver->input (2)->process (c); - framecnt_t expected_frames = frames * channels; - framecnt_t generated_frames = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); + samplecnt_t expected_samples = samples * channels; + samplecnt_t generated_samples = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples); } void testChannelSync() { interleaver->add_output (sink); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); interleaver->input (0)->process (c); CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); } @@ -119,9 +119,9 @@ class InterleaverTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink; - framecnt_t channels; + samplecnt_t channels; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (InterleaverTest); diff --git a/libs/audiographer/tests/general/normalizer_test.cc b/libs/audiographer/tests/general/normalizer_test.cc index fb8cd617c2..74df980028 100644 --- a/libs/audiographer/tests/general/normalizer_test.cc +++ b/libs/audiographer/tests/general/normalizer_test.cc @@ -14,7 +14,7 @@ class NormalizerTest : public CppUnit::TestFixture public: void setUp() { - frames = 1024; + samples = 1024; } void tearDown() @@ -25,23 +25,23 @@ class NormalizerTest : public CppUnit::TestFixture void testConstAmplify() { float target = 0.0; - random_data = TestUtils::init_random_data(frames, 0.5); + random_data = TestUtils::init_random_data(samples, 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); + ProcessContext<float> const c (random_data, samples, 1); peak_reader->process (c); float peak = peak_reader->get_peak(); - normalizer->alloc_buffer (frames); + normalizer->alloc_buffer (samples); normalizer->set_peak (peak); normalizer->add_output (sink); normalizer->process (c); peak_reader->reset(); - ConstProcessContext<float> normalized (sink->get_array(), frames, 1); + ConstProcessContext<float> normalized (sink->get_array(), samples, 1); peak_reader->process (normalized); peak = peak_reader->get_peak(); @@ -54,7 +54,7 @@ class NormalizerTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (NormalizerTest); diff --git a/libs/audiographer/tests/general/peak_reader_test.cc b/libs/audiographer/tests/general/peak_reader_test.cc index a93d28a954..b5f7a6dad1 100644 --- a/libs/audiographer/tests/general/peak_reader_test.cc +++ b/libs/audiographer/tests/general/peak_reader_test.cc @@ -13,8 +13,8 @@ class PeakReaderTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames); + samples = 128; + random_data = TestUtils::init_random_data(samples); } void tearDown() @@ -25,7 +25,7 @@ class PeakReaderTest : public CppUnit::TestFixture void testProcess() { reader.reset (new PeakReader()); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); float peak = 1.5; random_data[10] = peak; @@ -48,7 +48,7 @@ class PeakReaderTest : public CppUnit::TestFixture boost::shared_ptr<PeakReader> reader; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (PeakReaderTest); diff --git a/libs/audiographer/tests/general/sample_format_converter_test.cc b/libs/audiographer/tests/general/sample_format_converter_test.cc index 734389a427..92a559aa33 100644 --- a/libs/audiographer/tests/general/sample_format_converter_test.cc +++ b/libs/audiographer/tests/general/sample_format_converter_test.cc @@ -20,8 +20,8 @@ class SampleFormatConverterTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames, 1.0); + samples = 128; + random_data = TestUtils::init_random_data(samples, 1.0); } void tearDown() @@ -33,30 +33,30 @@ class SampleFormatConverterTest : public CppUnit::TestFixture { // Float never uses dithering and should always use full 32 bits of data boost::shared_ptr<SampleFormatConverter<float> > f_converter (new SampleFormatConverter<float>(1)); - f_converter->init (frames, D_Tri, 32); // Doesn't throw - CPPUNIT_ASSERT_THROW (f_converter->init (frames, D_Tri, 24), Exception); - CPPUNIT_ASSERT_THROW (f_converter->init (frames, D_Tri, 48), Exception); + f_converter->init (samples, D_Tri, 32); // Doesn't throw + CPPUNIT_ASSERT_THROW (f_converter->init (samples, D_Tri, 24), Exception); + CPPUNIT_ASSERT_THROW (f_converter->init (samples, D_Tri, 48), Exception); /* Test that too large data widths throw. We are fine with unnecessarily narrow data widths */ boost::shared_ptr<SampleFormatConverter<int32_t> > i_converter (new SampleFormatConverter<int32_t>(1)); - i_converter->init (frames, D_Tri, 32); // Doesn't throw - i_converter->init (frames, D_Tri, 24); // Doesn't throw - i_converter->init (frames, D_Tri, 8); // Doesn't throw - i_converter->init (frames, D_Tri, 16); // Doesn't throw - CPPUNIT_ASSERT_THROW (i_converter->init (frames, D_Tri, 48), Exception); + i_converter->init (samples, D_Tri, 32); // Doesn't throw + i_converter->init (samples, D_Tri, 24); // Doesn't throw + i_converter->init (samples, D_Tri, 8); // Doesn't throw + i_converter->init (samples, D_Tri, 16); // Doesn't throw + CPPUNIT_ASSERT_THROW (i_converter->init (samples, D_Tri, 48), Exception); boost::shared_ptr<SampleFormatConverter<int16_t> > i16_converter (new SampleFormatConverter<int16_t>(1)); - i16_converter->init (frames, D_Tri, 16); // Doesn't throw - i16_converter->init (frames, D_Tri, 8); // Doesn't throw - CPPUNIT_ASSERT_THROW (i16_converter->init (frames, D_Tri, 32), Exception); - CPPUNIT_ASSERT_THROW (i16_converter->init (frames, D_Tri, 48), Exception); + i16_converter->init (samples, D_Tri, 16); // Doesn't throw + i16_converter->init (samples, D_Tri, 8); // Doesn't throw + CPPUNIT_ASSERT_THROW (i16_converter->init (samples, D_Tri, 32), Exception); + CPPUNIT_ASSERT_THROW (i16_converter->init (samples, D_Tri, 48), Exception); boost::shared_ptr<SampleFormatConverter<uint8_t> > ui_converter (new SampleFormatConverter<uint8_t>(1)); - ui_converter->init (frames, D_Tri, 8); // Doesn't throw - ui_converter->init (frames, D_Tri, 4); // Doesn't throw - CPPUNIT_ASSERT_THROW (ui_converter->init (frames, D_Tri, 16), Exception); + ui_converter->init (samples, D_Tri, 8); // Doesn't throw + ui_converter->init (samples, D_Tri, 4); // Doesn't throw + CPPUNIT_ASSERT_THROW (ui_converter->init (samples, D_Tri, 16), Exception); } void testFrameCount() @@ -64,26 +64,26 @@ 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->init (samples, D_Tri, 32); converter->add_output (sink); - framecnt_t frames_output = 0; + samplecnt_t samples_output = 0; { - ProcessContext<float> pc(random_data, frames / 2, 1); + ProcessContext<float> pc(random_data, samples / 2, 1); converter->process (pc); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames / 2, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples / 2, samples_output); } { - ProcessContext<float> pc(random_data, frames, 1); + ProcessContext<float> pc(random_data, samples, 1); converter->process (pc); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); } { - ProcessContext<float> pc(random_data, frames + 1, 1); + ProcessContext<float> pc(random_data, samples + 1, 1); CPPUNIT_ASSERT_THROW(converter->process (pc), Exception); } } @@ -92,17 +92,17 @@ 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 32); + converter->init(samples, D_Tri, 32); converter->add_output (sink); converter->set_clip_floats (false); - ProcessContext<float> const pc(random_data, frames, 1); + ProcessContext<float> const pc(random_data, samples, 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_equals(sink->get_array(), random_data, samples)); // Make sure a few samples are < -1.0 and > 1.0 random_data[10] = -1.5; @@ -110,11 +110,11 @@ class SampleFormatConverterTest : public CppUnit::TestFixture 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), samples)); - for (framecnt_t i = 0; i < frames; ++i) { + for (samplecnt_t i = 0; i < samples; ++i) { // fp comparison needs a bit of tolerance, 1.01 << 1.5 CPPUNIT_ASSERT(sink->get_data()[i] < 1.01); CPPUNIT_ASSERT(sink->get_data()[i] > -1.01); @@ -125,89 +125,89 @@ 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 32); + converter->init(samples, D_Tri, 32); converter->add_output (sink); - ProcessContext<float> pc(random_data, frames, 1); + ProcessContext<float> pc(random_data, samples, 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), samples)); } 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 24); + converter->init(samples, D_Tri, 24); converter->add_output (sink); - ProcessContext<float> pc(random_data, frames, 1); + ProcessContext<float> pc(random_data, samples, 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), samples)); } 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 16); + converter->init(samples, D_Tri, 16); converter->add_output (sink); - ProcessContext<float> pc(random_data, frames, 1); + ProcessContext<float> pc(random_data, samples, 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), samples)); } 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 8); + converter->init(samples, D_Tri, 8); converter->add_output (sink); - ProcessContext<float> pc(random_data, frames, 1); + ProcessContext<float> pc(random_data, samples, 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)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), samples)); } 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; + samplecnt_t samples_output = 0; - converter->init(frames, D_Tri, 32); + converter->init(samples, 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(); - CPPUNIT_ASSERT_EQUAL (new_frame_count, frames_output); - CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), pc.frames())); + samplecnt_t new_sample_count = samples - (samples % 3); + converter->process (ProcessContext<float> (pc.data(), new_sample_count, 3)); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (new_sample_count, samples_output); + CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), pc.samples())); } private: float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (SampleFormatConverterTest); diff --git a/libs/audiographer/tests/general/silence_trimmer_test.cc b/libs/audiographer/tests/general/silence_trimmer_test.cc index be53c89978..c6662c92de 100644 --- a/libs/audiographer/tests/general/silence_trimmer_test.cc +++ b/libs/audiographer/tests/general/silence_trimmer_test.cc @@ -17,19 +17,19 @@ class SilenceTrimmerTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; + samples = 128; - random_data = TestUtils::init_random_data(frames); + random_data = TestUtils::init_random_data(samples); random_data[0] = 0.5; - random_data[frames - 1] = 0.5; + random_data[samples - 1] = 0.5; - zero_data = new float[frames]; - memset(zero_data, 0, frames * sizeof(float)); + zero_data = new float[samples]; + memset(zero_data, 0, samples * sizeof(float)); - half_random_data = TestUtils::init_random_data(frames); - memset(half_random_data, 0, (frames / 2) * sizeof(float)); + half_random_data = TestUtils::init_random_data(samples); + memset(half_random_data, 0, (samples / 2) * sizeof(float)); - trimmer.reset (new SilenceTrimmer<float> (frames / 2)); + trimmer.reset (new SilenceTrimmer<float> (samples / 2)); sink.reset (new AppendingVectorSink<float>()); trimmer->set_trim_beginning (true); @@ -48,73 +48,73 @@ class SilenceTrimmerTest : public CppUnit::TestFixture trimmer->add_output (sink); { - ProcessContext<float> c (zero_data, frames, 1); + ProcessContext<float> c (zero_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_processed); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL ((samplecnt_t) 0, samples_processed); } { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_processed); - CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, frames)); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_processed); + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, samples)); } { - ProcessContext<float> c (zero_data, frames, 1); + ProcessContext<float> c (zero_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_processed); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_processed); } { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (3 * frames, frames_processed); - CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, frames)); - 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)); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (3 * samples, samples_processed); + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[samples], zero_data, samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[2 * samples], random_data, samples)); } { - ProcessContext<float> c (zero_data, frames, 1); + ProcessContext<float> c (zero_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (3 * frames, frames_processed); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (3 * samples, samples_processed); } } void testPartialBuffers() { trimmer->add_output (sink); - trimmer->reset (frames / 4); + trimmer->reset (samples / 4); trimmer->set_trim_beginning (true); trimmer->set_trim_end (true); { - ProcessContext<float> c (half_random_data, frames, 1); + ProcessContext<float> c (half_random_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); - CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), &half_random_data[frames / 2], frames / 2)); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples / 2, samples_processed); + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), &half_random_data[samples / 2], samples / 2)); } { - ProcessContext<float> c (zero_data, frames, 1); + ProcessContext<float> c (zero_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples / 2, samples_processed); } { - ProcessContext<float> c (half_random_data, frames, 1); + ProcessContext<float> c (half_random_data, samples, 1); trimmer->process (c); - framecnt_t frames_processed = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (2 * frames + frames / 2, frames_processed); - CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames + frames / 2], half_random_data, frames)); + samplecnt_t samples_processed = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (2 * samples + samples / 2, samples_processed); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[samples + samples / 2], half_random_data, samples)); } } @@ -129,42 +129,42 @@ class SilenceTrimmerTest : public CppUnit::TestFixture { trimmer->add_output (sink); - framecnt_t silence = frames / 2; + samplecnt_t silence = samples / 2; trimmer->add_silence_to_beginning (silence); { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 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)); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[silence], random_data, samples)); } void testAddSilenceEnd() { trimmer->add_output (sink); - framecnt_t silence = frames / 3; + samplecnt_t silence = samples / 3; trimmer->add_silence_to_end (silence); { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); trimmer->process (c); } { - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 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); - CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, frames)); - CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames], random_data, frames)); - CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames * 2], zero_data, silence)); + samplecnt_t samples_processed = sink->get_data().size(); + samplecnt_t total_samples = 2 * samples + silence; + CPPUNIT_ASSERT_EQUAL (total_samples, samples_processed); + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[samples], random_data, samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[samples * 2], zero_data, silence)); } private: @@ -174,7 +174,7 @@ class SilenceTrimmerTest : public CppUnit::TestFixture float * random_data; float * zero_data; float * half_random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (SilenceTrimmerTest); diff --git a/libs/audiographer/tests/general/sr_converter_test.cc b/libs/audiographer/tests/general/sr_converter_test.cc index 4f5afbb620..b2b7193ff6 100644 --- a/libs/audiographer/tests/general/sr_converter_test.cc +++ b/libs/audiographer/tests/general/sr_converter_test.cc @@ -16,8 +16,8 @@ class SampleRateConverterTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames); + samples = 128; + random_data = TestUtils::init_random_data(samples); sink.reset (new AppendingVectorSink<float>()); grabber.reset (new ProcessContextGrabber<float>()); converter.reset (new SampleRateConverter (1)); @@ -30,79 +30,79 @@ class SampleRateConverterTest : public CppUnit::TestFixture void testNoConversion() { - assert (frames % 2 == 0); - framecnt_t const half_frames = frames / 2; - framecnt_t frames_output = 0; + assert (samples % 2 == 0); + samplecnt_t const half_samples = samples / 2; + samplecnt_t samples_output = 0; converter->init (44100, 44100); converter->add_output (sink); - ProcessContext<float> c (random_data, half_frames, 1); + ProcessContext<float> c (random_data, half_samples, 1); converter->process (c); - ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); + ProcessContext<float> c2 (&random_data[half_samples], half_samples, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - frames_output = sink->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_output); + samples_output = sink->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); - CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), samples)); } void testUpsampleLength() { - assert (frames % 2 == 0); - framecnt_t const half_frames = frames / 2; - framecnt_t frames_output = 0; + assert (samples % 2 == 0); + samplecnt_t const half_samples = samples / 2; + samplecnt_t samples_output = 0; converter->init (44100, 88200); - converter->allocate_buffers (half_frames); + converter->allocate_buffers (half_samples); converter->add_output (sink); - ProcessContext<float> c (random_data, half_frames, 1); + ProcessContext<float> c (random_data, half_samples, 1); converter->process (c); - ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); + ProcessContext<float> c2 (&random_data[half_samples], half_samples, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - frames_output = sink->get_data().size(); - framecnt_t tolerance = 3; - CPPUNIT_ASSERT (2 * frames - tolerance < frames_output && frames_output < 2 * frames + tolerance); + samples_output = sink->get_data().size(); + samplecnt_t tolerance = 3; + CPPUNIT_ASSERT (2 * samples - tolerance < samples_output && samples_output < 2 * samples + tolerance); } void testDownsampleLength() { - assert (frames % 2 == 0); - framecnt_t const half_frames = frames / 2; - framecnt_t frames_output = 0; + assert (samples % 2 == 0); + samplecnt_t const half_samples = samples / 2; + samplecnt_t samples_output = 0; converter->init (88200, 44100); - converter->allocate_buffers (half_frames); + converter->allocate_buffers (half_samples); converter->add_output (sink); - ProcessContext<float> c (random_data, half_frames, 1); + ProcessContext<float> c (random_data, half_samples, 1); converter->process (c); - ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); + ProcessContext<float> c2 (&random_data[half_samples], half_samples, 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); + samples_output = sink->get_data().size(); + samplecnt_t tolerance = 3; + CPPUNIT_ASSERT (half_samples - tolerance < samples_output && samples_output < half_samples + tolerance); } void testRespectsEndOfInput() { - assert (frames % 2 == 0); - framecnt_t const half_frames = frames / 2; + assert (samples % 2 == 0); + samplecnt_t const half_samples = samples / 2; converter->init (44100, 48000); - converter->allocate_buffers (half_frames); + converter->allocate_buffers (half_samples); converter->add_output (grabber); - ProcessContext<float> c (random_data, half_frames, 1); + ProcessContext<float> c (random_data, half_samples, 1); converter->process (c); - ProcessContext<float> c2 (&random_data[half_frames], half_frames / 2, 1); + ProcessContext<float> c2 (&random_data[half_samples], half_samples / 2, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); @@ -123,7 +123,7 @@ class SampleRateConverterTest : public CppUnit::TestFixture boost::shared_ptr<ProcessContextGrabber<float> > grabber; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (SampleRateConverterTest); diff --git a/libs/audiographer/tests/general/threader_test.cc b/libs/audiographer/tests/general/threader_test.cc index cdb21a375b..8662d61a30 100644 --- a/libs/audiographer/tests/general/threader_test.cc +++ b/libs/audiographer/tests/general/threader_test.cc @@ -16,11 +16,11 @@ class ThreaderTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data (frames, 1.0); + samples = 128; + random_data = TestUtils::init_random_data (samples, 1.0); - zero_data = new float[frames]; - memset (zero_data, 0, frames * sizeof(float)); + zero_data = new float[samples]; + memset (zero_data, 0, samples * sizeof(float)); thread_pool = new Glib::ThreadPool (3); threader.reset (new Threader<float> (*thread_pool)); @@ -53,15 +53,15 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_e); threader->add_output (sink_f); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 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)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_d->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_d->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), samples)); } void testRemoveOutput() @@ -73,7 +73,7 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_e); threader->add_output (sink_f); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); threader->process (c); // Remove a, b and f @@ -81,15 +81,15 @@ class ThreaderTest : public CppUnit::TestFixture threader->remove_output (sink_b); threader->remove_output (sink_f); - ProcessContext<float> zc (zero_data, frames, 1); + ProcessContext<float> zc (zero_data, samples, 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)); - CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_d->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_e->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_c->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_d->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_e->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), samples)); } void testClearOutputs() @@ -101,19 +101,19 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_e); threader->add_output (sink_f); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); threader->process (c); threader->clear_outputs(); - ProcessContext<float> zc (zero_data, frames, 1); + ProcessContext<float> zc (zero_data, samples, 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)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_d->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_d->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), samples)); } void testExceptions() @@ -125,13 +125,13 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_e); threader->add_output (throwing_sink); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 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)); - CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), samples)); } private: @@ -149,7 +149,7 @@ class ThreaderTest : public CppUnit::TestFixture float * random_data; float * zero_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (ThreaderTest); diff --git a/libs/audiographer/tests/sndfile/tmp_file_test.cc b/libs/audiographer/tests/sndfile/tmp_file_test.cc index 9748623f37..0d62796a02 100644 --- a/libs/audiographer/tests/sndfile/tmp_file_test.cc +++ b/libs/audiographer/tests/sndfile/tmp_file_test.cc @@ -12,8 +12,8 @@ class TmpFileTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames); + samples = 128; + random_data = TestUtils::init_random_data(samples); } void tearDown() @@ -25,22 +25,22 @@ class TmpFileTest : public CppUnit::TestFixture { uint32_t channels = 2; file.reset (new TmpFileSync<float>(SF_FORMAT_WAV | SF_FORMAT_FLOAT, channels, 44100)); - AllocatingProcessContext<float> c (random_data, frames, channels); + AllocatingProcessContext<float> c (random_data, samples, channels); c.set_flag (ProcessContext<float>::EndOfInput); file->process (c); - TypeUtils<float>::zero_fill (c.data (), c.frames()); + TypeUtils<float>::zero_fill (c.data (), c.samples()); file->seek (0, SEEK_SET); file->read (c); - CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.frames())); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.samples())); } private: boost::shared_ptr<TmpFileSync<float> > file; float * random_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (TmpFileTest); diff --git a/libs/audiographer/tests/type_utils_test.cc b/libs/audiographer/tests/type_utils_test.cc index 1ae7b28451..a1197246bd 100644 --- a/libs/audiographer/tests/type_utils_test.cc +++ b/libs/audiographer/tests/type_utils_test.cc @@ -27,11 +27,11 @@ class TypeUtilsTest : public CppUnit::TestFixture void testZeroFillPod() { - unsigned frames = 10; - float buf[frames]; - TypeUtils<float>::zero_fill (buf, frames); + unsigned samples = 10; + float buf[samples]; + TypeUtils<float>::zero_fill (buf, samples); float zero = 0.0; - for (unsigned i = 0; i < frames; ++i) { + for (unsigned i = 0; i < samples; ++i) { CPPUNIT_ASSERT_EQUAL (zero, buf[i]); } } @@ -39,11 +39,11 @@ class TypeUtilsTest : public CppUnit::TestFixture void testZeroFillNonPod() { /* does not compile on OS X Lion - unsigned frames = 10; - NonPodType buf[frames]; - TypeUtils<NonPodType>::zero_fill (buf, frames); + unsigned samples = 10; + NonPodType buf[samples]; + TypeUtils<NonPodType>::zero_fill (buf, samples); NonPodType zero; - for (unsigned i = 0; i < frames; ++i) { + for (unsigned i = 0; i < samples; ++i) { CPPUNIT_ASSERT (zero == buf[i]); } */ diff --git a/libs/audiographer/tests/utils.h b/libs/audiographer/tests/utils.h index b6b9e0136c..9d400f6977 100644 --- a/libs/audiographer/tests/utils.h +++ b/libs/audiographer/tests/utils.h @@ -17,14 +17,14 @@ #include <cstdlib> #include <ctime> -using AudioGrapher::framecnt_t; +using AudioGrapher::samplecnt_t; struct TestUtils { template<typename T> - static bool array_equals (T const * a, T const * b, framecnt_t frames) + static bool array_equals (T const * a, T const * b, samplecnt_t samples) { - for (framecnt_t i = 0; i < frames; ++i) { + for (samplecnt_t i = 0; i < samples; ++i) { if (a[i] != b[i]) { return false; } @@ -33,9 +33,9 @@ struct TestUtils } template<typename T> - static bool array_filled (T const * array, framecnt_t frames) + static bool array_filled (T const * array, samplecnt_t samples) { - for (framecnt_t i = 0; i < frames; ++i) { + for (samplecnt_t i = 0; i < samples; ++i) { if (array[i] == static_cast<T> (0.0)) { return false; } @@ -44,13 +44,13 @@ struct TestUtils } /// Generate random data, all samples guaranteed not to be 0.0, 1.0 or -1.0 - static float * init_random_data (framecnt_t frames, float range = 1.0) + static float * init_random_data (samplecnt_t samples, float range = 1.0) { unsigned int const granularity = 4096; - float * data = new float[frames]; + float * data = new float[samples]; srand (std::time (NULL)); - for (framecnt_t i = 0; i < frames; ++i) { + for (samplecnt_t i = 0; i < samples; ++i) { do { int biased_int = (rand() % granularity) - (granularity / 2); data[i] = (range * biased_int) / granularity; @@ -66,8 +66,8 @@ class VectorSink : public AudioGrapher::Sink<T> public: virtual void process (AudioGrapher::ProcessContext<T> const & c) { - data.resize (c.frames()); - memcpy (&data[0], c.data(), c.frames() * sizeof(T)); + data.resize (c.samples()); + memcpy (&data[0], c.data(), c.samples() * sizeof(T)); } void process (AudioGrapher::ProcessContext<T> & c) { AudioGrapher::Sink<T>::process (c); } @@ -90,20 +90,20 @@ class AppendingVectorSink : public VectorSink<T> void process (AudioGrapher::ProcessContext<T> const & c) { std::vector<T> & data (VectorSink<T>::data); - data.resize (total_frames + c.frames()); - memcpy (&data[total_frames], c.data(), c.frames() * sizeof(T)); - total_frames += c.frames(); + data.resize (total_samples + c.samples()); + memcpy (&data[total_samples], c.data(), c.samples() * sizeof(T)); + total_samples += c.samples(); } using AudioGrapher::Sink<T>::process; void reset () { - total_frames = 0; + total_samples = 0; VectorSink<T>::reset(); } private: - framecnt_t total_frames; + samplecnt_t total_samples; }; diff --git a/libs/audiographer/tests/utils/identity_vertex_test.cc b/libs/audiographer/tests/utils/identity_vertex_test.cc index 3c0fd71c70..81c4e498f2 100644 --- a/libs/audiographer/tests/utils/identity_vertex_test.cc +++ b/libs/audiographer/tests/utils/identity_vertex_test.cc @@ -15,11 +15,11 @@ class IdentityVertexTest : public CppUnit::TestFixture public: void setUp() { - frames = 128; - random_data = TestUtils::init_random_data(frames); + samples = 128; + random_data = TestUtils::init_random_data(samples); - zero_data = new float[frames]; - memset (zero_data, 0, frames * sizeof(float)); + zero_data = new float[samples]; + memset (zero_data, 0, samples * sizeof(float)); sink_a.reset (new VectorSink<float>()); sink_b.reset (new VectorSink<float>()); @@ -37,19 +37,19 @@ class IdentityVertexTest : public CppUnit::TestFixture vertex->add_output (sink_a); vertex->add_output (sink_b); - framecnt_t frames_output = 0; + samplecnt_t samples_output = 0; - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); vertex->process (c); - frames_output = sink_a->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_output); + samples_output = sink_a->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_output); - frames_output = sink_b->get_data().size(); - CPPUNIT_ASSERT_EQUAL (frames, frames_output); + samples_output = sink_b->get_data().size(); + CPPUNIT_ASSERT_EQUAL (samples, samples_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)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), samples)); } void testRemoveOutput() @@ -58,15 +58,15 @@ class IdentityVertexTest : public CppUnit::TestFixture vertex->add_output (sink_a); vertex->add_output (sink_b); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); vertex->process (c); vertex->remove_output (sink_a); - ProcessContext<float> zc (zero_data, frames, 1); + ProcessContext<float> zc (zero_data, samples, 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)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (zero_data, sink_b->get_array(), samples)); } void testClearOutputs() @@ -75,15 +75,15 @@ class IdentityVertexTest : public CppUnit::TestFixture vertex->add_output (sink_a); vertex->add_output (sink_b); - ProcessContext<float> c (random_data, frames, 1); + ProcessContext<float> c (random_data, samples, 1); vertex->process (c); vertex->clear_outputs (); - ProcessContext<float> zc (zero_data, frames, 1); + ProcessContext<float> zc (zero_data, samples, 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)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples)); + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), samples)); } private: @@ -93,7 +93,7 @@ class IdentityVertexTest : public CppUnit::TestFixture float * random_data; float * zero_data; - framecnt_t frames; + samplecnt_t samples; }; CPPUNIT_TEST_SUITE_REGISTRATION (IdentityVertexTest); |