output/alsa: move functions to lib/alsa/Format.hxx
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "AlsaOutputPlugin.hxx"
|
||||
#include "lib/alsa/Format.hxx"
|
||||
#include "lib/alsa/NonBlock.hxx"
|
||||
#include "lib/alsa/PeriodBuffer.hxx"
|
||||
#include "lib/alsa/Version.hxx"
|
||||
@@ -366,105 +367,6 @@ alsa_test_default_device()
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert MPD's #SampleFormat enum to libasound's snd_pcm_format_t
|
||||
* enum. Returns SND_PCM_FORMAT_UNKNOWN if there is no according ALSA
|
||||
* PCM format.
|
||||
*/
|
||||
gcc_const
|
||||
static snd_pcm_format_t
|
||||
ToAlsaPcmFormat(SampleFormat sample_format) noexcept
|
||||
{
|
||||
switch (sample_format) {
|
||||
case SampleFormat::UNDEFINED:
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
|
||||
case SampleFormat::DSD:
|
||||
#ifdef HAVE_ALSA_DSD
|
||||
return SND_PCM_FORMAT_DSD_U8;
|
||||
#else
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
#endif
|
||||
|
||||
case SampleFormat::S8:
|
||||
return SND_PCM_FORMAT_S8;
|
||||
|
||||
case SampleFormat::S16:
|
||||
return SND_PCM_FORMAT_S16;
|
||||
|
||||
case SampleFormat::S24_P32:
|
||||
return SND_PCM_FORMAT_S24;
|
||||
|
||||
case SampleFormat::S32:
|
||||
return SND_PCM_FORMAT_S32;
|
||||
|
||||
case SampleFormat::FLOAT:
|
||||
return SND_PCM_FORMAT_FLOAT;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
gcc_unreachable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the byte-swapped PCM format. Returns
|
||||
* SND_PCM_FORMAT_UNKNOWN if the format cannot be byte-swapped.
|
||||
*/
|
||||
static snd_pcm_format_t
|
||||
ByteSwapAlsaPcmFormat(snd_pcm_format_t fmt) noexcept
|
||||
{
|
||||
switch (fmt) {
|
||||
case SND_PCM_FORMAT_S16_LE: return SND_PCM_FORMAT_S16_BE;
|
||||
case SND_PCM_FORMAT_S24_LE: return SND_PCM_FORMAT_S24_BE;
|
||||
case SND_PCM_FORMAT_S32_LE: return SND_PCM_FORMAT_S32_BE;
|
||||
case SND_PCM_FORMAT_S16_BE: return SND_PCM_FORMAT_S16_LE;
|
||||
case SND_PCM_FORMAT_S24_BE: return SND_PCM_FORMAT_S24_LE;
|
||||
|
||||
case SND_PCM_FORMAT_S24_3BE:
|
||||
return SND_PCM_FORMAT_S24_3LE;
|
||||
|
||||
case SND_PCM_FORMAT_S24_3LE:
|
||||
return SND_PCM_FORMAT_S24_3BE;
|
||||
|
||||
case SND_PCM_FORMAT_S32_BE: return SND_PCM_FORMAT_S32_LE;
|
||||
|
||||
#ifdef HAVE_ALSA_DSD_U32
|
||||
case SND_PCM_FORMAT_DSD_U16_LE:
|
||||
return SND_PCM_FORMAT_DSD_U16_BE;
|
||||
|
||||
case SND_PCM_FORMAT_DSD_U16_BE:
|
||||
return SND_PCM_FORMAT_DSD_U16_LE;
|
||||
|
||||
case SND_PCM_FORMAT_DSD_U32_LE:
|
||||
return SND_PCM_FORMAT_DSD_U32_BE;
|
||||
|
||||
case SND_PCM_FORMAT_DSD_U32_BE:
|
||||
return SND_PCM_FORMAT_DSD_U32_LE;
|
||||
#endif
|
||||
|
||||
default: return SND_PCM_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a "packed" version of the give PCM format.
|
||||
* Returns SND_PCM_FORMAT_UNKNOWN if not.
|
||||
*/
|
||||
static snd_pcm_format_t
|
||||
PackAlsaPcmFormat(snd_pcm_format_t fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
case SND_PCM_FORMAT_S24_LE:
|
||||
return SND_PCM_FORMAT_S24_3LE;
|
||||
|
||||
case SND_PCM_FORMAT_S24_BE:
|
||||
return SND_PCM_FORMAT_S24_3BE;
|
||||
|
||||
default:
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to configure the specified sample format. On failure,
|
||||
* fall back to the packed version.
|
||||
|
Reference in New Issue
Block a user