2 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2006-2008 Doug McLain <doug@nostar.net>
4 * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
5 * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
6 * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
8 * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef __sndfile_source_h__
26 #define __sndfile_source_h__
30 #include "ardour/audiofilesource.h"
31 #include "ardour/broadcast_info.h"
32 #include "ardour/progress.h"
36 class LIBARDOUR_API SndFileSource : public AudioFileSource {
38 /** Constructor to be called for existing external-to-session files */
39 SndFileSource (Session&, const std::string& path, int chn, Flag flags);
41 /* Constructor to be called for new in-session files */
42 SndFileSource (Session&, const std::string& path, const std::string& origin,
43 SampleFormat samp_format, HeaderFormat hdr_format, samplecnt_t rate,
44 Flag flags = SndFileSource::default_writable_flags);
46 /* Constructor to be called for recovering files being used for
47 * capture. They are in-session, they already exist, they should not
48 * be writable. They are an odd hybrid (from a constructor point of
49 * view) of the previous two constructors.
51 SndFileSource (Session&, const std::string& path, int chn);
53 /** Constructor to be called for existing in-session files during
56 SndFileSource (Session&, const XMLNode&);
58 /** Constructor to losslessly compress existing source */
59 SndFileSource (Session& s, const AudioFileSource& other, const std::string& path, bool use16bits = false, Progress* p = NULL);
63 float sample_rate () const;
64 int update_header (samplepos_t when, struct tm&, time_t);
68 samplepos_t last_capture_start_sample() const;
69 void mark_capture_start (samplepos_t);
70 void mark_capture_end ();
71 void clear_capture_marks();
73 bool one_of_several_channels () const;
74 uint32_t channel_count () const { return _info.channels; }
76 bool clamped_at_unity () const;
78 static void setup_standard_crossfades (Session const &, samplecnt_t sample_rate);
79 static const Source::Flag default_writable_flags;
81 static int get_soundfile_info (const std::string& path, SoundFileInfo& _info, std::string& error_msg);
86 void set_path (const std::string& p);
87 void set_header_natural_position ();
89 samplecnt_t read_unlocked (Sample *dst, samplepos_t start, samplecnt_t cnt) const;
90 samplecnt_t write_unlocked (Sample *dst, samplecnt_t cnt);
91 samplecnt_t write_float (Sample* data, samplepos_t pos, samplecnt_t cnt);
96 BroadcastInfo *_broadcast_info;
100 int setup_broadcast_info (samplepos_t when, struct tm&, time_t);
105 static samplecnt_t xfade_samples;
107 static gain_t* out_coefficient;
108 static gain_t* in_coefficient;
112 samplepos_t capture_start_sample;
113 samplepos_t file_pos; // unit is samples
116 samplecnt_t crossfade (Sample* data, samplecnt_t cnt, int dir);
117 void set_natural_position (samplepos_t);
118 samplecnt_t destructive_write_unlocked (Sample *dst, samplecnt_t cnt);
119 samplecnt_t nondestructive_write_unlocked (Sample *dst, samplecnt_t cnt);
120 void handle_header_position_change ();
121 PBD::ScopedConnection header_position_connection;
124 } // namespace ARDOUR
126 #endif /* __sndfile_source_h__ */