mpd/src/AudioFormat.cxx

86 lines
1.8 KiB
C++
Raw Normal View History

/*
2016-02-26 17:54:05 +01:00
* Copyright 2003-2016 The Music Player Daemon Project
* 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.
*/
2013-08-03 21:00:50 +02:00
#include "AudioFormat.hxx"
#include <assert.h>
#include <stdio.h>
void
2013-08-03 21:00:50 +02:00
AudioFormat::ApplyMask(AudioFormat mask)
{
2013-08-03 21:00:50 +02:00
assert(IsValid());
assert(mask.IsMaskValid());
2013-08-03 21:00:50 +02:00
if (mask.sample_rate != 0)
sample_rate = mask.sample_rate;
2013-08-03 21:00:50 +02:00
if (mask.format != SampleFormat::UNDEFINED)
format = mask.format;
2013-08-03 21:00:50 +02:00
if (mask.channels != 0)
channels = mask.channels;
2013-08-03 21:00:50 +02:00
assert(IsValid());
}
const char *
2013-08-03 21:00:50 +02:00
sample_format_to_string(SampleFormat format)
{
switch (format) {
2013-08-03 21:00:50 +02:00
case SampleFormat::UNDEFINED:
return "?";
2013-08-03 21:00:50 +02:00
case SampleFormat::S8:
return "8";
2013-08-03 21:00:50 +02:00
case SampleFormat::S16:
return "16";
2013-08-03 21:00:50 +02:00
case SampleFormat::S24_P32:
return "24";
2013-08-03 21:00:50 +02:00
case SampleFormat::S32:
return "32";
2013-08-03 21:00:50 +02:00
case SampleFormat::FLOAT:
return "f";
2013-08-03 21:00:50 +02:00
case SampleFormat::DSD:
return "dsd";
}
/* unreachable */
assert(false);
2013-08-03 21:34:17 +02:00
gcc_unreachable();
}
const char *
2013-08-03 21:00:50 +02:00
audio_format_to_string(const AudioFormat af,
struct audio_format_string *s)
{
2013-08-03 21:00:50 +02:00
assert(s != nullptr);
snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
2013-08-03 21:00:50 +02:00
af.sample_rate, sample_format_to_string(af.format),
af.channels);
return s->buffer;
}