NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
audiofile.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
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 3 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
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef AUDIOFILE_HPP
20#define AUDIOFILE_HPP
21
22#include <vector>
23#include <string>
24#include <cmath>
25
26namespace Audio
27{
32 struct Sample
33 {
34 double leftOrMono;
35 double right;
36
37 Sample(double _mono) : leftOrMono(_mono), right(NAN) {}
38 Sample(double _left, double _right) : leftOrMono(_left), right(_right) {}
39 };
40
41
46 class File
47 {
48 public:
49 File() {}
50 virtual ~File() {}
51
52 virtual bool isValid() const = 0;
53
54 virtual void newFile() = 0;
55 virtual void setChannels(size_t channels) = 0;
56 virtual void setSampleRate(size_t freq) = 0;
57 virtual void write(const Sample& frame) = 0;
58
59 virtual size_t getChannels() const = 0;
60 virtual size_t getSampleRate() const = 0;
61 virtual size_t getLength() const = 0;
62 virtual Sample read() const = 0;
63
71 virtual bool isSeekable() const
72 {
73 return false;
74 }
75 };
76
77
84 class SeekableFile : public File
85 {
86 public:
88
97 virtual bool isSeekable() const override
98 {
99 return true;
100 }
101
102 virtual size_t getPosition() const = 0;
103 virtual void setPosition(size_t pos) = 0;
104
105 virtual std::vector<Sample> readSome(size_t len) const = 0;
106 virtual void writeSome(const std::vector<Sample> vFrames) = 0;
107 };
108
109
110 File* getAudioFileByType(const std::string& sFileName);
111}
112
113#endif // AUDIOFILE_HPP
114
115
116
This class represents a generic audio file with reading and writing functionalities.
Definition: audiofile.hpp:47
virtual Sample read() const =0
virtual ~File()
Definition: audiofile.hpp:50
virtual void newFile()=0
virtual bool isSeekable() const
Audio files, which inherit from this class do not have any seeking functionality.
Definition: audiofile.hpp:71
virtual size_t getChannels() const =0
virtual size_t getLength() const =0
virtual size_t getSampleRate() const =0
virtual void write(const Sample &frame)=0
virtual void setSampleRate(size_t freq)=0
virtual void setChannels(size_t channels)=0
virtual bool isValid() const =0
This class extends the generic audio file with seeking functionalities as well as possibilities for r...
Definition: audiofile.hpp:85
virtual bool isSeekable() const override
Overrides the base classes member function to signal the possibility to safely up-cast to this class.
Definition: audiofile.hpp:97
virtual size_t getPosition() const =0
virtual std::vector< Sample > readSome(size_t len) const =0
virtual void setPosition(size_t pos)=0
virtual void writeSome(const std::vector< Sample > vFrames)=0
File * getAudioFileByType(const std::string &sFileName)
Return a audio file type depending on the file extension or a nullptr if the file type is not support...
Definition: audiofile.cpp:34
Defines a sample in the audio stream, i.e. a single value per channel.
Definition: audiofile.hpp:33
double right
Definition: audiofile.hpp:35
Sample(double _left, double _right)
Definition: audiofile.hpp:38
double leftOrMono
Definition: audiofile.hpp:34
Sample(double _mono)
Definition: audiofile.hpp:37