Ardour  9.0-pre0-439-ga53b99b307
srcfilesource.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2014-2017 Paul Davis <paul@linuxaudiosystems.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #include <cstring>
23 #include <samplerate.h>
24 
26 #include "ardour/audiofilesource.h"
27 #include "ardour/session.h"
28 
29 namespace ARDOUR {
30 
32 public:
33  SrcFileSource (Session&, std::shared_ptr<AudioFileSource>, SrcQuality srcq = SrcQuality(SrcQuick));
35 
36  int update_header (samplepos_t /*when*/, struct tm&, time_t) { return 0; }
37  int flush_header () { return 0; }
38  void flush () { }
40  void set_length (samplecnt_t /*len*/) {};
41 
42  float sample_rate () const { return _session.nominal_sample_rate(); }
43 
44  timepos_t natural_position() const { return _source->natural_position().scale (_ratio); }
45  samplecnt_t readable_length_samples() const { assert (_source->length().time_domain() == Temporal::AudioTime); return _source->length().samples () * _ratio; }
46  timepos_t length () const { assert (_source->length().time_domain() == Temporal::AudioTime); return timepos_t ((samplepos_t) (_source->length().samples () * _ratio)); }
47 
48  bool can_be_analysed() const { return false; }
49  bool clamped_at_unity() const { return false; }
50 
51 protected:
52  void close ();
54  samplecnt_t write_unlocked (Sample const */*src*/, samplecnt_t /*cnt*/) { return 0; }
55 
57  double /*samples_per_unit*/, samplecnt_t /*fpp*/) const {
58  memset (peaks, 0, sizeof (PeakData) * npeaks);
59  return 0;
60  }
61 
62 private:
63  static const uint32_t max_blocksize;
64  std::shared_ptr<AudioFileSource> _source;
65 
66  mutable SRC_STATE* _src_state;
67  mutable SRC_DATA _src_data;
68 
69  mutable Sample* _src_buffer;
72  mutable double _fract_position;
73 
74  double _ratio;
76 };
77 
78 } // namespace ARDOUR
79 
80 
std::shared_ptr< AudioFileSource > _source
Definition: srcfilesource.h:64
SRC_STATE * _src_state
Definition: srcfilesource.h:66
static const uint32_t max_blocksize
Definition: srcfilesource.h:63
bool can_be_analysed() const
Definition: srcfilesource.h:48
bool clamped_at_unity() const
Definition: srcfilesource.h:49
samplecnt_t readable_length_samples() const
Definition: srcfilesource.h:45
samplecnt_t read_unlocked(Sample *dst, samplepos_t start, samplecnt_t cnt) const
timepos_t length() const
Definition: srcfilesource.h:46
void set_length(samplecnt_t)
Definition: srcfilesource.h:40
SrcFileSource(Session &, std::shared_ptr< AudioFileSource >, SrcQuality srcq=SrcQuality(SrcQuick))
int update_header(samplepos_t, struct tm &, time_t)
Definition: srcfilesource.h:36
int read_peaks_with_fpp(PeakData *peaks, samplecnt_t npeaks, samplepos_t, samplecnt_t, double, samplecnt_t) const
Definition: srcfilesource.h:56
samplepos_t _target_position
Definition: srcfilesource.h:71
float sample_rate() const
Definition: srcfilesource.h:42
samplecnt_t src_buffer_size
Definition: srcfilesource.h:75
samplepos_t _source_position
Definition: srcfilesource.h:70
timepos_t natural_position() const
Definition: srcfilesource.h:44
samplecnt_t write_unlocked(Sample const *, samplecnt_t)
Definition: srcfilesource.h:54
void set_header_natural_position()
Definition: srcfilesource.h:39
timepos_t scale(ratio_t const &n) const
#define LIBARDOUR_API
void peaks(const float *data, float &min, float &max, uint32_t n_samples)
void memset(float *data, const float val, const uint32_t n_samples)
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
Temporal::timepos_t timepos_t
Temporal::samplepos_t samplepos_t