mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-30 08:53:08 +01:00
Allow gain factor for audio sources.
In preparation for archiving files as .flac (fixed point), normalized with gain factor.
This commit is contained in:
parent
5bada6d533
commit
54a79639df
5 changed files with 48 additions and 5 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue