blob: 115d3630c95a4a8513b21236d252d630339d2d1b [file] [log] [blame]
agsantosc9181b42020-11-26 12:03:04 -05001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantosc9181b42020-11-26 12:03:04 -05003 *
4 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef AUDIOFORMAT_H
22#define AUDIOFORMAT_H
23
24extern "C" {
25#include <libavutil/samplefmt.h>
26struct AVFrame;
27}
28
29/**
30 * Structure to hold sample rate and channel number associated with audio data.
31 */
32struct AudioFormat
33{
34 unsigned sample_rate;
35 unsigned nb_channels;
36 AVSampleFormat sampleFormat;
37
38 constexpr AudioFormat(unsigned sr, unsigned c)
39 : sample_rate(sr)
40 , nb_channels(c)
41 , sampleFormat(AV_SAMPLE_FMT_S16)
42 {}
43
44 constexpr AudioFormat(unsigned sr, unsigned c, AVSampleFormat f)
45 : sample_rate(sr)
46 , nb_channels(c)
47 , sampleFormat(f)
48 {}
49
50 static const constexpr unsigned DEFAULT_SAMPLE_RATE = 48000;
51 static const constexpr AudioFormat DEFAULT() { return AudioFormat {16000, 1}; }
52 static const constexpr AudioFormat NONE() { return AudioFormat {0, 0}; }
53 static const constexpr AudioFormat MONO() { return AudioFormat {DEFAULT_SAMPLE_RATE, 1}; }
54 static const constexpr AudioFormat STEREO() { return AudioFormat {DEFAULT_SAMPLE_RATE, 2}; }
55};
56
57#endif // AUDIOFORMAT_H