summaryrefslogtreecommitdiff
path: root/libs/ardour/mp3filesource.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-12-06 18:18:33 +0100
committerRobin Gareus <robin@gareus.org>2019-12-06 18:18:54 +0100
commitd0b6c437ce0c4e2d1eb41cf3d41f0834a752f302 (patch)
tree9e5e41982179f6d520fdd66a13360a46af935f67 /libs/ardour/mp3filesource.cc
parentbef74c267ef50c93aa726b2f60e63259b2c3799c (diff)
Implement mp3 import, using minimp3
Diffstat (limited to 'libs/ardour/mp3filesource.cc')
-rw-r--r--libs/ardour/mp3filesource.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/libs/ardour/mp3filesource.cc b/libs/ardour/mp3filesource.cc
new file mode 100644
index 0000000000..7b90e93f3d
--- /dev/null
+++ b/libs/ardour/mp3filesource.cc
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "pbd/error.h"
+#include "pbd/compose.h"
+#include "ardour/mp3filesource.h"
+
+#include "pbd/i18n.h"
+
+using namespace ARDOUR;
+using namespace PBD;
+
+/** Constructor to be called for existing external-to-session files
+ * Sources created with this method are never writable or removable.
+ */
+
+Mp3FileSource::Mp3FileSource (Session& s, const string& path, int chn, Flag flags)
+ : Source (s, DataType::AUDIO, path,
+ Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
+ , AudioFileSource (s, path,
+ Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
+ , _mp3 (path)
+ , _channel (chn)
+{
+ _length = _mp3.length ();
+
+ if (_channel >= (int) _mp3.channels ()) {
+ error << string_compose("Mp3FileSource: file only contains %1 channels; %2 is invalid as a channel number (%3)", _mp3.channels (), _channel, name()) << endmsg;
+ throw failed_constructor();
+ }
+}
+
+Mp3FileSource::~Mp3FileSource ()
+{
+}
+
+void
+Mp3FileSource::close ()
+{
+}
+
+samplecnt_t
+Mp3FileSource::read_unlocked (Sample* dst, samplepos_t start, samplecnt_t cnt) const
+{
+ return _mp3.read_unlocked (dst, start, cnt, _channel);
+}
+
+int
+Mp3FileSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
+{
+ try {
+ Mp3FileImportableSource mp3 (path);
+ _info.samplerate = mp3.samplerate ();
+ _info.channels = mp3.channels ();
+ _info.length = mp3.length ();
+ _info.format_name = string_compose (_("MPEG Layer %1 (%2 kbps)"), mp3.layer (), mp3.bitrate ());
+ _info.timecode = 0;
+ _info.seekable = false;
+ return 0;
+ } catch (...) {}
+ return -1;
+}