summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/ardour/ardour/audiofilesource.h1
-rw-r--r--libs/ardour/ardour/file_source.h6
-rw-r--r--libs/ardour/audiofilesource.cc19
-rw-r--r--libs/ardour/file_source.cc9
-rw-r--r--libs/ardour/sndfilesource.cc18
5 files changed, 48 insertions, 5 deletions
diff --git a/libs/ardour/ardour/audiofilesource.h b/libs/ardour/ardour/audiofilesource.h
index d91280284d..49b62116fc 100644
--- a/libs/ardour/ardour/audiofilesource.h
+++ b/libs/ardour/ardour/audiofilesource.h
@@ -63,6 +63,7 @@ public:
void mark_streaming_write_completed (const Lock& lock);
int setup_peakfile ();
+ void set_gain (float g, bool temporarily = false);
XMLNode& get_state ();
int set_state (const XMLNode&, int version);
diff --git a/libs/ardour/ardour/file_source.h b/libs/ardour/ardour/file_source.h
index 9b4c2ccffc..0f3b9bce66 100644
--- a/libs/ardour/ardour/file_source.h
+++ b/libs/ardour/ardour/file_source.h
@@ -56,9 +56,12 @@ public:
void mark_immutable_except_write();
void mark_nonremovable ();
- const std::string& take_id () const { return _take_id; }
+ const std::string& take_id () const { return _take_id; }
bool within_session () const { return _within_session; }
uint16_t channel() const { return _channel; }
+ float gain() const { return _gain; }
+
+ virtual void set_gain (float g, bool temporarily = false) { _gain = g; }
int set_state (const XMLNode&, int version);
@@ -111,6 +114,7 @@ public:
uint16_t _channel;
bool _within_session;
std::string _origin;
+ float _gain;
};
} // namespace ARDOUR
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index 3bf252af3d..2edd06282b 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -207,11 +207,14 @@ AudioFileSource::get_soundfile_info (const string& path, SoundFileInfo& _info, s
XMLNode&
AudioFileSource::get_state ()
{
+ LocaleGuard lg;
XMLNode& root (AudioSource::get_state());
char buf[32];
snprintf (buf, sizeof (buf), "%u", _channel);
root.add_property (X_("channel"), buf);
- root.add_property (X_("origin"), _origin);
+ root.add_property (X_("origin"), _origin);
+ snprintf (buf, sizeof (buf), "%f", _gain);
+ root.add_property (X_("gain"), buf);
return root;
}
@@ -283,6 +286,20 @@ AudioFileSource::setup_peakfile ()
}
}
+void
+AudioFileSource::set_gain (float g, bool temporarily)
+{
+ if (_gain == g) {
+ return;
+ }
+ _gain = g;
+ if (temporarily) {
+ return;
+ }
+ close_peakfile();
+ setup_peakfile ();
+}
+
bool
AudioFileSource::safe_audio_file_extension(const string& file)
{
diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc
index 8b503d4894..f313fde7ba 100644
--- a/libs/ardour/file_source.cc
+++ b/libs/ardour/file_source.cc
@@ -61,6 +61,7 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
, _file_is_new (!origin.empty()) // if origin is left unspecified (empty string) then file must exist
, _channel (0)
, _origin (origin)
+ , _gain (1.f)
{
set_within_session_from_path (path);
}
@@ -69,6 +70,7 @@ FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist
: Source (session, node)
, _file_is_new (false)
, _channel (0)
+ , _gain (1.f)
{
/* this setting of _path is temporary - we expect derived classes
to call ::init() which will actually locate the file
@@ -142,6 +144,7 @@ FileSource::init (const string& pathstr, bool must_exist)
int
FileSource::set_state (const XMLNode& node, int /*version*/)
{
+ LocaleGuard lg;
XMLProperty const * prop;
if ((prop = node.property (X_("channel"))) != 0) {
@@ -154,6 +157,12 @@ FileSource::set_state (const XMLNode& node, int /*version*/)
_origin = prop->value();
}
+ if ((prop = node.property (X_("gain"))) != 0) {
+ _gain = atof (prop->value());
+ } else {
+ _gain = 1.f;
+ }
+
return 0;
}
diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc
index 54b9a0135c..2e7df7f918 100644
--- a/libs/ardour/sndfilesource.cc
+++ b/libs/ardour/sndfilesource.cc
@@ -523,6 +523,11 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
error << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5, ret was %6)"), start, file_cnt, _name.val().substr (1), errbuf, _length, ret) << endl;
}
+ if (_gain != 1.f) {
+ for (framecnt_t i = 0; i < ret; ++i) {
+ dst[i] *= _gain;
+ }
+ }
return ret;
}
}
@@ -537,9 +542,16 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
/* stride through the interleaved data */
- for (framecnt_t n = 0; n < nread; ++n) {
- dst[n] = *ptr;
- ptr += _info.channels;
+ if (_gain != 1.f) {
+ for (framecnt_t n = 0; n < nread; ++n) {
+ dst[n] = *ptr * _gain;
+ ptr += _info.channels;
+ }
+ } else {
+ for (framecnt_t n = 0; n < nread; ++n) {
+ dst[n] = *ptr;
+ ptr += _info.channels;
+ }
}
return nread;