AudioFormat.cxx 1.85 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "AudioFormat.hxx"
21 22 23 24

#include <assert.h>
#include <stdio.h>

25
void
26
AudioFormat::ApplyMask(AudioFormat mask)
27
{
28 29
	assert(IsValid());
	assert(mask.IsMaskValid());
30

31 32
	if (mask.sample_rate != 0)
		sample_rate = mask.sample_rate;
33

34 35
	if (mask.format != SampleFormat::UNDEFINED)
		format = mask.format;
36

37 38
	if (mask.channels != 0)
		channels = mask.channels;
39

40
	assert(IsValid());
41 42
}

43
const char *
44
sample_format_to_string(SampleFormat format)
45 46
{
	switch (format) {
47
	case SampleFormat::UNDEFINED:
48 49
		return "?";

50
	case SampleFormat::S8:
51 52
		return "8";

53
	case SampleFormat::S16:
54 55
		return "16";

56
	case SampleFormat::S24_P32:
57 58
		return "24";

59
	case SampleFormat::S32:
60
		return "32";
61

62
	case SampleFormat::FLOAT:
63
		return "f";
64

65
	case SampleFormat::DSD:
66
		return "dsd";
67 68 69 70
	}

	/* unreachable */
	assert(false);
71
	gcc_unreachable();
72 73
}

74
const char *
75
audio_format_to_string(const AudioFormat af,
76 77
		       struct audio_format_string *s)
{
78
	assert(s != nullptr);
79

80
	snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
81 82
		 af.sample_rate, sample_format_to_string(af.format),
		 af.channels);
83 84 85

	return s->buffer;
}