aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform/win/pcm_io/pcm_io.cpp
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2019-12-30 00:13:23 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2020-01-01 22:29:50 +0300
commit3d69df17657c40030fb486a86ef179a42b3873ca (patch)
tree56002a11e97322d6b6360b1479330ba83e87d731 /src/platform/win/pcm_io/pcm_io.cpp
parentb58f4dd8353121094acdb41ad96fbdec4a580d79 (diff)
downloadatracdenc-3d69df17657c40030fb486a86ef179a42b3873ca.tar.gz
Initiall support of stdin reading for windows
Expected au(snd) format, 44100hz, 16bit, stereo or mono
Diffstat (limited to 'src/platform/win/pcm_io/pcm_io.cpp')
-rw-r--r--src/platform/win/pcm_io/pcm_io.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/platform/win/pcm_io/pcm_io.cpp b/src/platform/win/pcm_io/pcm_io.cpp
new file mode 100644
index 0000000..fb44cc0
--- /dev/null
+++ b/src/platform/win/pcm_io/pcm_io.cpp
@@ -0,0 +1,64 @@
+/*
+ * This file is part of AtracDEnc.
+ *
+ * AtracDEnc is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * AtracDEnc 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with AtracDEnc; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "pcm_io_impl.h"
+#include "mf/pcm_io_mf.h"
+#include "win32/pcm_io_win32.h"
+
+#include <endian.h>
+
+#include <iostream>
+#include <windows.h>
+
+
+void ConvertToPcmBufferFromLE(const BYTE* audioData, TPCMBuffer<TFloat>& buf, size_t sz, size_t shift, size_t channelsNum) {
+ if (channelsNum == 1) {
+ for (size_t i = 0; i < sz; i++) {
+ *(buf[i + shift] + 0) = (*(int16_t*)(audioData + i * 2 + 0)) / (TFloat)32768.0;
+ }
+ } else {
+ for (size_t i = 0; i < sz; i++) {
+ *(buf[i + shift] + 0) = (*(int16_t*)(audioData + i * 4 + 0)) / (TFloat)32768.0;
+ *(buf[i + shift] + 1) = (*(int16_t*)(audioData + i * 4 + 2)) / (TFloat)32768.0;
+ }
+ }
+}
+
+void ConvertToPcmBufferFromBE(const BYTE* audioData, TPCMBuffer<TFloat>& buf, size_t sz, size_t shift, size_t channelsNum) {
+ if (channelsNum == 1) {
+ for (size_t i = 0; i < sz; i++) {
+ *(buf[i + shift] + 0) = conv_ntoh((*(int16_t*)(audioData + i * 2 + 0))) / (TFloat)32768.0;
+ }
+ } else {
+ for (size_t i = 0; i < sz; i++) {
+ *(buf[i + shift] + 0) = conv_ntoh((*(int16_t*)(audioData + i * 4 + 0))) / (TFloat)32768.0;
+ *(buf[i + shift] + 1) = conv_ntoh((*(int16_t*)(audioData + i * 4 + 2))) / (TFloat)32768.0;
+ }
+ }
+}
+
+IPCMProviderImpl* CreatePCMIOReadImpl(const std::string& path) {
+ if (path == "-") {
+ return CreatePCMIOStreamWin32ReadImpl();
+ }
+ return CreatePCMIOMFReadImpl(path);
+}
+
+IPCMProviderImpl* CreatePCMIOWriteImpl(const std::string& path, int channels, int sampleRate) {
+ return CreatePCMIOMFWriteImpl(path, channels, sampleRate);
+} \ No newline at end of file