Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b30c37eb
Commit
b30c37eb
authored
Oct 26, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/alsa: move functions to lib/alsa/Format.hxx
parent
b08cb148
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
99 deletions
+134
-99
Makefile.am
Makefile.am
+1
-0
Format.hxx
src/lib/alsa/Format.hxx
+132
-0
AlsaOutputPlugin.cxx
src/output/plugins/AlsaOutputPlugin.cxx
+1
-99
No files found.
Makefile.am
View file @
b30c37eb
...
...
@@ -258,6 +258,7 @@ UPNP_SOURCES = \
ALSA_SOURCES
=
\
src/lib/alsa/Version.cxx src/lib/alsa/Version.hxx
\
src/lib/alsa/Format.hxx
\
src/lib/alsa/PeriodBuffer.hxx
\
src/lib/alsa/NonBlock.cxx src/lib/alsa/NonBlock.hxx
...
...
src/lib/alsa/Format.hxx
0 → 100644
View file @
b30c37eb
/*
* Copyright 2003-2017 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.
*/
#ifndef MPD_ALSA_FORMAT_HXX
#define MPD_ALSA_FORMAT_HXX
#include "check.h"
#include "pcm/SampleFormat.hxx"
#include "Compiler.h"
#include <alsa/asoundlib.h>
#include <assert.h>
/**
* 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
inline
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.
*/
gcc_const
inline
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.
*/
gcc_const
inline
snd_pcm_format_t
PackAlsaPcmFormat
(
snd_pcm_format_t
fmt
)
noexcept
{
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
;
}
}
#endif
src/output/plugins/AlsaOutputPlugin.cxx
View file @
b30c37eb
...
...
@@ -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"
...
...
@@ -367,105 +368,6 @@ alsa_test_default_device()
}
/**
* 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.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment