eDSP  0.0.1
A cross-platform DSP library written in C++.
decoder.hpp
Go to the documentation of this file.
1 /*
2 * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3 * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along width
16 * this program. If not, see <http://www.gnu.org/licenses/>
17 *
18 * Filename: decoder.hpp
19 * Author: Mohammed Boujemaoui
20 * Date: 07/10/18
21 */
22 
23 #ifndef EDSP_DECODER_HPP
24 #define EDSP_DECODER_HPP
25 
27 #include <edsp/io/internal/codec/decoder_impl.hpp>
28 
29 namespace edsp { namespace io {
30 
38  template <typename T, std::size_t N = 1024>
39  class decoder {
40  public:
41  using index_type = std::ptrdiff_t;
42  using value_type = T;
43 
44  explicit decoder() = default;
45  ~decoder() = default;
46 
52  bool open(const edsp::string_view& file_path) {
53  return impl_.open(file_path);
54  }
55 
59  void close() {
60  impl_.close();
61  }
62 
67  bool is_open() const noexcept {
68  return impl_.is_open();
69  }
70 
76  index_type samples() const noexcept {
77  return impl_.samples();
78  }
79 
80  /*
81  * @brief Returns the number of frames in the audio file.
82  *
83  * Each sample frame of audio consists of a fixed number of samples (equal to the number of audio channels in
84  * the track. For monaural data, a sample frame consists of one audio sample. For stereophonic data, a sample
85  * frame consists of a stereo pair.
86  *
87  * @returns Number of frames in the audio file.
88  */
89  index_type frames() const noexcept {
90  return impl_.frames();
91  }
92 
100  index_type channels() const noexcept {
101  return impl_.channels();
102  }
103 
108  double duration() const noexcept {
109  return impl_.duration();
110  }
111 
116  double samplerate() const noexcept {
117  return impl_.samplerate();
118  }
119 
124  bool seekable() const noexcept {
125  return impl_.seekable();
126  }
127 
134  index_type seek(index_type position) noexcept {
135  return impl_.seek(position);
136  }
137 
143  index_type current() const noexcept {
144  return impl_.current();
145  }
146 
156  template <typename OutputIt>
157  index_type read(OutputIt d_first, OutputIt d_last) {
158  return impl_.read(d_first, d_last);
159  }
160 
161  private:
162  decoder_impl<T, N> impl_;
163  };
164 }} // namespace edsp::io
165 
166 #endif //EDSP_DECODER_HPP
bool seekable() const noexcept
Checks if the audio file is seekable.
Definition: decoder.hpp:124
double duration() const noexcept
Returns the duration of the audio file in seconds.
Definition: decoder.hpp:108
index_type current() const noexcept
Returns the current frame position of the track in an audio file.
Definition: decoder.hpp:143
index_type read(OutputIt d_first, OutputIt d_last)
Attempts to read data from the audio file and stores the results in the range [first, last)
Definition: decoder.hpp:157
std::ptrdiff_t index_type
Definition: decoder.hpp:41
index_type samples() const noexcept
Returns the number of samples in the audio file.
Definition: decoder.hpp:76
index_type seek(index_type position) noexcept
Updates the current frame position for a track in an audio file.
Definition: decoder.hpp:134
double samplerate() const noexcept
Returns the sampling rate of the audio file in Hz.
Definition: decoder.hpp:116
index_type channels() const noexcept
Returns the number of channels in the audio file.
Definition: decoder.hpp:100
void close()
Closes the audio file.
Definition: decoder.hpp:59
bool open(const edsp::string_view &file_path)
Opens an audio file.
Definition: decoder.hpp:52
~decoder()=default
This class implements a decoder object to read data from supported audio files.
Definition: decoder.hpp:39
index_type frames() const noexcept
Definition: decoder.hpp:89
bool is_open() const noexcept
Checks if the there is an audio file opened.
Definition: decoder.hpp:67
Definition: amplifier.hpp:29
T value_type
Definition: decoder.hpp:42