summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--src/pcm/Silence.cxx35
-rw-r--r--src/pcm/Silence.hxx36
-rw-r--r--src/pcm/Volume.cxx8
4 files changed, 75 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 91f0f326c..7cd68f86e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -467,6 +467,7 @@ libpcm_a_SOURCES = \
src/pcm/PcmConvert.cxx src/pcm/PcmConvert.hxx \
src/pcm/PcmDop.cxx src/pcm/PcmDop.hxx \
src/pcm/Volume.cxx src/pcm/Volume.hxx \
+ src/pcm/Silence.cxx src/pcm/Silence.hxx \
src/pcm/PcmMix.cxx src/pcm/PcmMix.hxx \
src/pcm/PcmChannels.cxx src/pcm/PcmChannels.hxx \
src/pcm/PcmPack.cxx src/pcm/PcmPack.hxx \
diff --git a/src/pcm/Silence.cxx b/src/pcm/Silence.cxx
new file mode 100644
index 000000000..c8f67f2b0
--- /dev/null
+++ b/src/pcm/Silence.cxx
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 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.
+ */
+
+#include "config.h"
+#include "Silence.hxx"
+#include "AudioFormat.hxx"
+#include "util/WritableBuffer.hxx"
+
+#include <string.h>
+
+void
+PcmSilence(WritableBuffer<void> dest, SampleFormat format)
+{
+ uint8_t pattern = 0;
+ if (format == SampleFormat::DSD)
+ pattern = 0x69;
+
+ memset(dest.data, pattern, dest.size);
+}
diff --git a/src/pcm/Silence.hxx b/src/pcm/Silence.hxx
new file mode 100644
index 000000000..5fcf99316
--- /dev/null
+++ b/src/pcm/Silence.hxx
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 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.
+ */
+
+#ifndef MPD_PCM_SILENCE_HXX
+#define MPD_PCM_SILENCE_HXX
+
+#include "check.h"
+
+#include <stdint.h>
+
+template<typename T> struct WritableBuffer;
+enum class SampleFormat : uint8_t;
+
+/**
+ * Fill the given buffer with the format-specific silence pattern.
+ */
+void
+PcmSilence(WritableBuffer<void> dest, SampleFormat format);
+
+#endif
diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx
index 37f90c582..6d28a9b36 100644
--- a/src/pcm/Volume.cxx
+++ b/src/pcm/Volume.cxx
@@ -19,10 +19,12 @@
#include "config.h"
#include "Volume.hxx"
+#include "Silence.hxx"
#include "Domain.hxx"
#include "PcmUtils.hxx"
#include "Traits.hxx"
#include "util/ConstBuffer.hxx"
+#include "util/WritableBuffer.hxx"
#include "util/Error.hxx"
#include "PcmDither.cxx" // including the .cxx file to get inlined templates
@@ -134,11 +136,7 @@ PcmVolume::Apply(ConstBuffer<void> src)
if (volume == 0) {
/* optimized special case: 0% volume = memset(0) */
- uint8_t pattern = 0;
- if (format == SampleFormat::DSD)
- pattern = 0x69;
-
- memset(data, pattern, src.size);
+ PcmSilence({data, src.size}, format);
return { data, src.size };
}