/** @return true if the each source sample s must be clamped to -1 < s < 1 */
virtual bool clamped_at_unity () const = 0;
- static void allocate_working_buffers ();
+ static void allocate_working_buffers (framecnt_t framerate);
protected:
static bool _build_missing_peakfiles;
static std::vector<gain_t*> _gain_buffers;
static Glib::StaticMutex _level_buffer_lock;
- static void ensure_buffers_for_level (uint32_t);
+ static void ensure_buffers_for_level (uint32_t, framecnt_t);
framecnt_t _length;
std::string peakpath;
, _playlist_channel (chn)
{
AudioSource::_length = len;
- ensure_buffers_for_level (_level);
+ ensure_buffers_for_level (_level, _session.frame_rate());
}
AudioPlaylistSource::AudioPlaylistSource (Session& s, const XMLNode& node)
sscanf (prop->value().c_str(), "%" PRIu32, &_playlist_channel);
- ensure_buffers_for_level (_level);
+ ensure_buffers_for_level (_level, _session.frame_rate());
return 0;
}
}
void
-AudioSource::allocate_working_buffers()
+AudioSource::allocate_working_buffers (framecnt_t framerate)
{
- assert(AudioDiskstream::disk_io_frames() > 0);
- _working_buffers_size = AudioDiskstream::disk_io_frames();
- /* we don't need any buffers allocated until
+ uint32_t current_level;
+
+ {
+ Glib::Mutex::Lock lm (_level_buffer_lock);
+ current_level = _mixdown_buffers.size();
+ }
+
+ /* Note: we don't need any buffers allocated until
a level 1 audiosource is created, at which
time we'll call ::ensure_buffers_for_level()
with the right value and do the right thing.
*/
+
+ if (current_level) {
+ ensure_buffers_for_level (current_level, framerate);
+ }
}
void
-AudioSource::ensure_buffers_for_level (uint32_t level)
+AudioSource::ensure_buffers_for_level (uint32_t level, framecnt_t frame_rate)
{
+ framecnt_t nframes = (framecnt_t) floor (Config->get_audio_playback_buffer_seconds() * frame_rate);
+
+ cerr << "audiosource: allocate buffers for level " << level << " size = " << nframes << endl;
+
Glib::Mutex::Lock lm (_level_buffer_lock);
+ /* this will leak memory. oh well. rather complex
+ to stop it from doing that without using shared_ptrs,
+ which i might do next. paul - may 27th 2011
+ */
+
+ _mixdown_buffers.clear ();
+ _gain_buffers.clear ();
+
while (_mixdown_buffers.size() < level) {
- _mixdown_buffers.push_back (new Sample[_working_buffers_size]);
- _gain_buffers.push_back (new gain_t[_working_buffers_size]);
+ _mixdown_buffers.push_back (new Sample[nframes]);
+ _gain_buffers.push_back (new gain_t[nframes]);
}
}
_speakers.reset (new Speakers);
AudioDiskstream::allocate_working_buffers();
- AudioSource::allocate_working_buffers ();
/* default short fade = 15ms */
solo_control_mode_changed ();
} else if (p == "timecode-offset" || p == "timecode-offset-negative") {
last_timecode_valid = false;
+ } else if (p == "playback-buffer-seconds") {
+ AudioSource::allocate_working_buffers (frame_rate());
}
set_dirty ();