diff options
author | Carl Hetherington <carl@carlh.net> | 2011-02-17 20:25:17 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-02-17 20:25:17 +0000 |
commit | e9e0251af62ca0138f65e55349249a52dae7078a (patch) | |
tree | 24794d6e8faf8c241a7b4f6820cd9c506d3adbca | |
parent | ff102f4cacb9208cd6d400186d7fe93bdb028e27 (diff) |
Cope with stereo click files by mixing them down to mono before playback. Kind-of fixes #1893.
git-svn-id: svn://localhost/ardour2/branches/3.0@8894 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/ardour/session_click.cc | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 2a1b4122e4..cd8ee5ce1e 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -157,16 +157,35 @@ Session::setup_click_sounds (Sample** data, Sample const * default_data, framecn return; } - *data = new Sample[info.frames]; - *length = info.frames; + /* read the (possibly multi-channel) click data into a temporary buffer */ - if (sf_read_float (sndfile, *data, info.frames) != info.frames) { + sf_count_t const samples = info.frames * info.channels; + + Sample* tmp = new Sample[samples]; + + if (sf_readf_float (sndfile, tmp, info.frames) != info.frames) { + warning << _("cannot read data from click soundfile") << endmsg; - delete *data; *data = 0; _clicking = false; + + } else { + + *data = new Sample[info.frames]; + *length = info.frames; + + /* mix down to mono */ + + for (int i = 0; i < info.frames; ++i) { + (*data)[i] = 0; + for (int j = 0; j < info.channels; ++j) { + (*data)[i] = tmp[i * info.channels + j]; + } + (*data)[i] /= info.channels; + } } - + + delete[] tmp; sf_close (sndfile); } } |