reintroduce use of optimized functions for gain into buffer code, and cleanup the way they are declared to avoid depending on Session

git-svn-id: svn://localhost/ardour2/branches/midi@1775 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis
2007-05-02 15:21:51 +00:00
parent a612857eb6
commit c3e666867c
14 changed files with 118 additions and 108 deletions

View File

@@ -2835,7 +2835,7 @@ Editor::cut_copy_regions (CutCopyOp op)
case Copy:
/* copy region before adding, so we're not putting same object into two different playlists */
npl->add_region (RegionFactory::create (r, r->position() - first_position);
npl->add_region (RegionFactory::create (r), r->position() - first_position);
break;
case Clear:

View File

@@ -24,6 +24,7 @@
#include <iostream>
#include <ardour/types.h>
#include <ardour/data_type.h>
#include <ardour/runtime_functions.h>
namespace ARDOUR {
@@ -142,21 +143,13 @@ public:
Sample* const dst_raw = _data + offset;
const Sample* const src_raw = src.data(len);
for (jack_nframes_t n = 0; n < len; ++n) {
dst_raw[n] += src_raw[n] * gain_coeff;
}
mix_buffers_with_gain (dst_raw, src_raw, len, gain_coeff);
_silent = ( (src.silent() && _silent) || (_silent && gain_coeff == 0) );
}
void apply_gain(gain_t gain, jack_nframes_t len, jack_nframes_t offset=0) {
Sample* const buf = _data + offset;
for (jack_nframes_t n = 0; n < len; ++n) {
buf[n] *= gain;
}
_silent = (_silent || gain == 0);
apply_gain_to_buffer (_data + offset, len, gain);
}
/** Set the data contained by this buffer manually (for setting directly to jack buffer).

View File

@@ -27,53 +27,39 @@
extern "C" {
/* SSE functions */
float x86_sse_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current);
void x86_sse_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain);
void x86_sse_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain);
void x86_sse_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes);
float x86_sse_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current);
void x86_sse_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain);
void x86_sse_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain);
void x86_sse_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes);
}
void x86_sse_find_peaks (ARDOUR::Sample *buf, nframes_t nsamples, float *min, float *max);
void x86_sse_find_peaks (const ARDOUR::Sample * buf, nframes_t nsamples, float *min, float *max);
/* debug wrappers for SSE functions */
float debug_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current);
void debug_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain);
void debug_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain);
void debug_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes);
float debug_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current);
void debug_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain);
void debug_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain);
void debug_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes);
#endif
#if defined (__APPLE__)
float veclib_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current);
void veclib_find_peaks (ARDOUR::Sample *buf, nframes_t nsamples, float *min, float *max);
void veclib_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain);
void veclib_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain);
void veclib_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes);
float veclib_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current);
void veclib_find_peaks (const ARDOUR::Sample * buf, nframes_t nsamples, float *min, float *max);
void veclib_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain);
void veclib_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain);
void veclib_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes);
#endif
/* non-optimized functions */
float compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current);
void find_peaks (ARDOUR::Sample *buf, nframes_t nsamples, float *min, float *max);
void apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain);
void mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain);
void mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes);
float default_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current);
void default_find_peaks (const ARDOUR::Sample * buf, nframes_t nsamples, float *min, float *max);
void default_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain);
void default_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain);
void default_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes);
#endif /* __ardour_mix_h__ */

View File

@@ -25,7 +25,7 @@
#include <ardour/utils.h>
static inline float
compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
default_compute_peak (const ARDOUR::Sample * const buf, nframes_t nsamples, float current)
{
for (nframes_t i = 0; i < nsamples; ++i) {
current = f_max (current, fabsf (buf[i]));

View File

@@ -0,0 +1,40 @@
/*
Copyright (C) 2007 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ardour_runtime_functions_h__
#define __ardour_runtime_functions_h__
#include <ardour/types.h>
namespace ARDOUR {
typedef float (*compute_peak_t) (const ARDOUR::Sample *, nframes_t, float);
typedef void (*find_peaks_t) (const ARDOUR::Sample *, nframes_t, float *, float*);
typedef void (*apply_gain_to_buffer_t) (ARDOUR::Sample *, nframes_t, float);
typedef void (*mix_buffers_with_gain_t) (ARDOUR::Sample *, const ARDOUR::Sample *, nframes_t, float);
typedef void (*mix_buffers_no_gain_t) (ARDOUR::Sample *, const ARDOUR::Sample *, nframes_t);
extern compute_peak_t compute_peak;
extern find_peaks_t find_peaks;
extern apply_gain_to_buffer_t apply_gain_to_buffer;
extern mix_buffers_with_gain_t mix_buffers_with_gain;
extern mix_buffers_no_gain_t mix_buffers_no_gain;
}
#endif /* __ardour_runtime_functions_h__ */

View File

@@ -932,18 +932,6 @@ class Session : public PBD::StatefulDestructible
void* ptr,
float opt);
typedef float (*compute_peak_t) (Sample *, nframes_t, float);
typedef void (*find_peaks_t) (Sample *, nframes_t, float *, float*);
typedef void (*apply_gain_to_buffer_t) (Sample *, nframes_t, float);
typedef void (*mix_buffers_with_gain_t) (Sample *, Sample *, nframes_t, float);
typedef void (*mix_buffers_no_gain_t) (Sample *, Sample *, nframes_t);
static compute_peak_t compute_peak;
static find_peaks_t find_peaks;
static apply_gain_to_buffer_t apply_gain_to_buffer;
static mix_buffers_with_gain_t mix_buffers_with_gain;
static mix_buffers_no_gain_t mix_buffers_no_gain;
static sigc::signal<void> SendFeedback;
/* Controllables */

View File

@@ -41,6 +41,7 @@
#include <ardour/audiofilter.h>
#include <ardour/audiofilesource.h>
#include <ardour/region_factory.h>
#include <ardour/runtime_functions.h>
#include "i18n.h"
#include <locale.h>
@@ -467,7 +468,7 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff
}
}
} else if (_scale_amplitude != 1.0f) {
Session::apply_gain_to_buffer (mixdown_buffer, to_read, _scale_amplitude);
apply_gain_to_buffer (mixdown_buffer, to_read, _scale_amplitude);
}
merge:
@@ -1099,7 +1100,7 @@ AudioRegion::normalize_to (float target_dB)
return;
}
maxamp = Session::compute_peak (buf, to_read, maxamp);
maxamp = compute_peak (buf, to_read, maxamp);
}
fpos += to_read;

View File

@@ -35,7 +35,7 @@
#include <ardour/audiosource.h>
#include <ardour/cycle_timer.h>
#include <ardour/session.h>
#include <ardour/runtime_functions.h>
#include "i18n.h"
@@ -696,7 +696,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframe
x.min = peak_leftovers[0];
x.max = peak_leftovers[0];
Session::find_peaks (peak_leftovers + 1, peak_leftover_cnt - 1, &x.min, &x.max);
find_peaks (peak_leftovers + 1, peak_leftover_cnt - 1, &x.min, &x.max);
off_t byte = (peak_leftover_frame / frames_per_peak) * sizeof (PeakData);
@@ -779,7 +779,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframe
peakbuf[peaks_computed].max = buf[0];
peakbuf[peaks_computed].min = buf[0];
Session::find_peaks (buf+1, this_time-1, &peakbuf[peaks_computed].min, &peakbuf[peaks_computed].max);
find_peaks (buf+1, this_time-1, &peakbuf[peaks_computed].min, &peakbuf[peaks_computed].max);
peaks_computed++;
buf += this_time;

View File

@@ -54,6 +54,7 @@
#endif
#include <ardour/mix.h>
#include <ardour/runtime_functions.h>
#if defined (__APPLE__)
#include <Carbon/Carbon.h> // For Gestalt
@@ -83,6 +84,12 @@ Change ARDOUR::PositionChanged = ARDOUR::new_change ();
Change ARDOUR::NameChanged = ARDOUR::new_change ();
Change ARDOUR::BoundsChanged = Change (0); // see init(), below
compute_peak_t ARDOUR::compute_peak = 0;
find_peaks_t ARDOUR::find_peaks = 0;
apply_gain_to_buffer_t ARDOUR::apply_gain_to_buffer = 0;
mix_buffers_with_gain_t ARDOUR::mix_buffers_with_gain = 0;
mix_buffers_no_gain_t ARDOUR::mix_buffers_no_gain = 0;
#ifdef HAVE_LIBLO
static int
setup_osc ()
@@ -236,11 +243,11 @@ setup_hardware_optimization (bool try_optimization)
info << "Using SSE optimized routines" << endmsg;
// SSE SET
Session::compute_peak = x86_sse_compute_peak;
Session::find_peaks = x86_sse_find_peaks;
Session::apply_gain_to_buffer = x86_sse_apply_gain_to_buffer;
Session::mix_buffers_with_gain = x86_sse_mix_buffers_with_gain;
Session::mix_buffers_no_gain = x86_sse_mix_buffers_no_gain;
compute_peak = x86_sse_compute_peak;
find_peaks = x86_sse_find_peaks;
apply_gain_to_buffer = x86_sse_apply_gain_to_buffer;
mix_buffers_with_gain = x86_sse_mix_buffers_with_gain;
mix_buffers_no_gain = x86_sse_mix_buffers_no_gain;
generic_mix_functions = false;
@@ -253,11 +260,11 @@ setup_hardware_optimization (bool try_optimization)
sysVersion = 0;
if (sysVersion >= 0x00001040) { // Tiger at least
Session::compute_peak = veclib_compute_peak;
Session::find_peaks = veclib_find_peaks;
Session::apply_gain_to_buffer = veclib_apply_gain_to_buffer;
Session::mix_buffers_with_gain = veclib_mix_buffers_with_gain;
Session::mix_buffers_no_gain = veclib_mix_buffers_no_gain;
compute_peak = veclib_compute_peak;
find_peaks = veclib_find_peaks;
apply_gain_to_buffer = veclib_apply_gain_to_buffer;
mix_buffers_with_gain = veclib_mix_buffers_with_gain;
mix_buffers_no_gain = veclib_mix_buffers_no_gain;
generic_mix_functions = false;
@@ -267,12 +274,12 @@ setup_hardware_optimization (bool try_optimization)
}
if (generic_mix_functions) {
Session::compute_peak = compute_peak;
Session::find_peaks = find_peaks;
Session::apply_gain_to_buffer = apply_gain_to_buffer;
Session::mix_buffers_with_gain = mix_buffers_with_gain;
Session::mix_buffers_no_gain = mix_buffers_no_gain;
compute_peak = default_compute_peak;
find_peaks = default_find_peaks;
apply_gain_to_buffer = default_apply_gain_to_buffer;
mix_buffers_with_gain = default_mix_buffers_with_gain;
mix_buffers_no_gain = default_mix_buffers_no_gain;
info << "No H/W specific optimizations in use" << endmsg;
}

View File

@@ -23,6 +23,8 @@
#include <ardour/mix.h>
#include <stdint.h>
using namespace ARDOUR;
#if defined (ARCH_X86) && defined (BUILD_SSE_OPTIMIZATIONS)
// Debug wrappers
@@ -80,7 +82,7 @@ debug_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t n
float
compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
default_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current)
{
for (nframes_t i = 0; i < nsamples; ++i) {
current = f_max (current, fabsf (buf[i]));
@@ -90,7 +92,7 @@ compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
}
void
find_peaks (ARDOUR::Sample *buf, nframes_t nframes, float *min, float *max)
default_find_peaks (const ARDOUR::Sample * buf, nframes_t nframes, float *min, float *max)
{
nframes_t i;
float a, b;
@@ -109,14 +111,14 @@ find_peaks (ARDOUR::Sample *buf, nframes_t nframes, float *min, float *max)
}
void
apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
default_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain)
{
for (nframes_t i=0; i<nframes; i++)
buf[i] *= gain;
}
void
mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
default_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain)
{
for (nframes_t i = 0; i < nframes; i++) {
dst[i] += src[i] * gain;
@@ -124,7 +126,7 @@ mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nfram
}
void
mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
default_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes)
{
for (nframes_t i=0; i < nframes; i++) {
dst[i] += src[i];
@@ -135,7 +137,7 @@ mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes
#include <Accelerate/Accelerate.h>
float
veclib_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
veclib_compute_peak (const ARDOUR::Sample * buf, nframes_t nsamples, float current)
{
float tmpmax = 0.0f;
vDSP_maxmgv(buf, 1, &tmpmax, nsamples);
@@ -143,26 +145,26 @@ veclib_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
}
void
veclib_find_peaks (ARDOUR::Sample *buf, nframes_t nframes, float *min, float *max)
veclib_find_peaks (const ARDOUR::Sample * buf, nframes_t nframes, float *min, float *max)
{
vDSP_maxv (buf, 1, max, nframes);
vDSP_minv (buf, 1, min, nframes);
}
void
veclib_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
veclib_apply_gain_to_buffer (ARDOUR::Sample * buf, nframes_t nframes, float gain)
{
vDSP_vsmul(buf, 1, &gain, buf, 1, nframes);
}
void
veclib_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
veclib_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes, float gain)
{
vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
}
void
veclib_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
veclib_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, nframes_t nframes)
{
// It seems that a vector mult only operation does not exist...
float gain = 1.0f;

View File

@@ -41,7 +41,7 @@
#include <ardour/panner.h>
#include <ardour/utils.h>
#include <ardour/mix.h>
#include <ardour/runtime_functions.h>
#include <ardour/buffer_set.h>
#include "i18n.h"
@@ -304,7 +304,7 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
pan = left * gain_coeff;
Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
} else {
@@ -315,7 +315,7 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
if (pan != 0.0f) {
Session::mix_buffers_with_gain(dst,src,nframes,pan);
mix_buffers_with_gain(dst,src,nframes,pan);
/* mark that we wrote into the buffer */
@@ -325,7 +325,7 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
} else {
Session::mix_buffers_no_gain(dst,src,nframes);
mix_buffers_no_gain(dst,src,nframes);
/* mark that we wrote into the buffer */
@@ -354,7 +354,7 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
pan = right * gain_coeff;
Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
/* XXX it would be nice to mark the buffer as written to */
@@ -367,14 +367,14 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
if (pan != 0.0f) {
Session::mix_buffers_with_gain(dst,src,nframes,pan);
mix_buffers_with_gain(dst,src,nframes,pan);
/* XXX it would be nice to mark the buffer as written to */
}
} else {
Session::mix_buffers_no_gain(dst,src,nframes);
mix_buffers_no_gain(dst,src,nframes);
/* XXX it would be nice to mark the buffer as written to */
}
@@ -666,7 +666,7 @@ Multi2dPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_co
}
pan = left * gain_coeff;
Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
} else {
@@ -676,10 +676,10 @@ Multi2dPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_co
if ((pan *= gain_coeff) != 1.0f) {
if (pan != 0.0f) {
Session::mix_buffers_with_gain(dst,src,nframes,pan);
mix_buffers_with_gain(dst,src,nframes,pan);
}
} else {
Session::mix_buffers_no_gain(dst,src,nframes);
mix_buffers_no_gain(dst,src,nframes);
}
#endif
#ifdef CAN_INTERP

View File

@@ -41,7 +41,6 @@
#include <ardour/ladspa_plugin.h>
#include <ardour/panner.h>
#include <ardour/dB.h>
#include <ardour/mix.h>
#include <ardour/amp.h>
#include <ardour/meter.h>
#include <ardour/buffer_set.h>
@@ -507,7 +506,7 @@ Route::process_output_buffers (BufferSet& bufs,
for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
Sample* const sp = i->data(nframes);
Session::apply_gain_to_buffer(sp,nframes,this_gain);
apply_gain_to_buffer(sp,nframes,this_gain);
}
} else if (_gain == 0) {

View File

@@ -100,12 +100,6 @@ const char* Session::dead_sound_dir_name = X_("dead_sounds");
const char* Session::interchange_dir_name = X_("interchange");
const char* Session::export_dir_name = X_("export");
Session::compute_peak_t Session::compute_peak = 0;
Session::find_peaks_t Session::find_peaks = 0;
Session::apply_gain_to_buffer_t Session::apply_gain_to_buffer = 0;
Session::mix_buffers_with_gain_t Session::mix_buffers_with_gain = 0;
Session::mix_buffers_no_gain_t Session::mix_buffers_no_gain = 0;
sigc::signal<int> Session::AskAboutPendingState;
sigc::signal<void> Session::SendFeedback;

View File

@@ -22,7 +22,7 @@
#include <ardour/types.h>
void
x86_sse_find_peaks(float *buf, nframes_t nframes, float *min, float *max)
x86_sse_find_peaks(const ARDOUR::Sample* buf, nframes_t nframes, float *min, float *max)
{
__m128 current_max, current_min, work;