diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f6375397a..ae4eb244a5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -164,6 +164,7 @@ jobs: conda activate base conda install -yq conda-build "conda-package-handling!=1.5.0" bash packaging/build_conda.sh + rm /C/tools/miniconda3/conda-bld/win-64/vs2019*.tar.bz2 - store_artifacts: path: C:/tools/miniconda3/conda-bld/win-64 - persist_to_workspace: diff --git a/.circleci/config.yml.in b/.circleci/config.yml.in index 284ca38ae9..e6d300ff98 100644 --- a/.circleci/config.yml.in +++ b/.circleci/config.yml.in @@ -164,6 +164,7 @@ jobs: conda activate base conda install -yq conda-build "conda-package-handling!=1.5.0" bash packaging/build_conda.sh + rm /C/tools/miniconda3/conda-bld/win-64/vs2019*.tar.bz2 - store_artifacts: path: C:/tools/miniconda3/conda-bld/win-64 - persist_to_workspace: diff --git a/.circleci/unittest/windows/scripts/environment.yml b/.circleci/unittest/windows/scripts/environment.yml index f3526b671b..784d750f1d 100644 --- a/.circleci/unittest/windows/scripts/environment.yml +++ b/.circleci/unittest/windows/scripts/environment.yml @@ -11,6 +11,5 @@ dependencies: - pip: - scipy - kaldi-io - - PySoundFile - librosa - future diff --git a/.circleci/unittest/windows/scripts/install.bat b/.circleci/unittest/windows/scripts/install.bat new file mode 100644 index 0000000000..fe57e2d61d --- /dev/null +++ b/.circleci/unittest/windows/scripts/install.bat @@ -0,0 +1,20 @@ +@echo on + +for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,17^) -property installationPath`) do ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VS15INSTALLDIR=%%i" + set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" + goto vswhere + ) +) + +:vswhere +if "%VSDEVCMD_ARGS%" == "" ( + call "%VS15VCVARSALL%" x64 || exit /b 1 +) else ( + call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS% || exit /b 1 +) + +@echo on + +python setup.py develop || exit /b 1 diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 7a56e94b52..48273d191e 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -7,6 +7,11 @@ unset PYTORCH_VERSION set -e +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +root_dir="$(git rev-parse --show-toplevel)" + +cd "${root_dir}" + eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" conda activate ./env @@ -20,4 +25,6 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}" conda install -y -c pytorch-nightly pytorch "${cudatoolkit}" printf "* Installing torchaudio\n" -IS_CONDA=true python setup.py develop +curl --retry 3 https://s3.amazonaws.com/ossci-windows/torchaudio_deps.7z --output /tmp/torchaudio_deps.7z +7z x /tmp/torchaudio_deps.7z -othird_party +IS_CONDA=true "$this_dir/install.bat" diff --git a/packaging/build_conda.sh b/packaging/build_conda.sh index 3e011d312f..119d85fb4a 100755 --- a/packaging/build_conda.sh +++ b/packaging/build_conda.sh @@ -9,4 +9,5 @@ export NO_CUDA_PACKAGE=1 setup_env 0.6.0 export SOURCE_ROOT_DIR="$PWD" setup_conda_pytorch_constraint +setup_visual_studio_constraint conda build $CONDA_CHANNEL_FLAGS --no-anaconda-upload --python "$PYTHON_VERSION" packaging/torchaudio diff --git a/packaging/build_wheel.sh b/packaging/build_wheel.sh index 576cf9f286..8624e2fe5b 100755 --- a/packaging/build_wheel.sh +++ b/packaging/build_wheel.sh @@ -8,15 +8,12 @@ export BUILD_TYPE="wheel" export NO_CUDA_PACKAGE=1 setup_env 0.6.0 setup_wheel_python -if [[ "$OSTYPE" != "msys" ]]; then +if [[ "$OSTYPE" == "msys" ]]; then + "$script_dir/download_deps.sh" "$(pwd)" # Download static dependencies +else "$script_dir/build_from_source.sh" "$(pwd)" # Build static dependencies fi pip_install numpy future setup_pip_pytorch_version python setup.py clean -if [[ "$OSTYPE" == "msys" ]]; then - python_tag="$(echo "cp$PYTHON_VERSION" | tr -d '.')" - IS_WHEEL=1 python setup.py bdist_wheel --plat-name win_amd64 --python-tag $python_tag -else - IS_WHEEL=1 python setup.py bdist_wheel -fi +IS_WHEEL=1 python setup.py bdist_wheel diff --git a/packaging/download_deps.sh b/packaging/download_deps.sh new file mode 100644 index 0000000000..8041c61319 --- /dev/null +++ b/packaging/download_deps.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -ex + +# Arguments: PREFIX, specifying where to install dependencies into + +PREFIX="$(cygpath $1)" + +curl --retry 3 https://s3.amazonaws.com/ossci-windows/torchaudio_deps.7z --output /tmp/torchaudio_deps.7z +7z x /tmp/torchaudio_deps.7z -o"$PREFIX/third_party" diff --git a/packaging/pkg_helpers.bash b/packaging/pkg_helpers.bash index 4030128a98..6711ea144e 100644 --- a/packaging/pkg_helpers.bash +++ b/packaging/pkg_helpers.bash @@ -219,3 +219,13 @@ setup_conda_cudatoolkit_constraint() { esac fi } + +# Build the proper compiler package before building the final package +setup_visual_studio_constraint() { + if [[ "$OSTYPE" == "msys" ]]; then + export VSTOOLCHAIN_PACKAGE=vs2019 + export VSDEVCMD_ARGS='' + conda build $CONDA_CHANNEL_FLAGS --no-anaconda-upload packaging/$VSTOOLCHAIN_PACKAGE + cp packaging/$VSTOOLCHAIN_PACKAGE/conda_build_config.yaml packaging/torchaudio/conda_build_config.yaml + fi +} diff --git a/packaging/torchaudio/bld.bat b/packaging/torchaudio/bld.bat index 6b31d4319c..6e9d935f30 100644 --- a/packaging/torchaudio/bld.bat +++ b/packaging/torchaudio/bld.bat @@ -1,5 +1,8 @@ @echo off +sh packaging/download_deps.sh '%CD%' +if errorlevel 1 exit /b 1 + set IS_CONDA=1 python setup.py install --single-version-externally-managed --record=record.txt diff --git a/packaging/vs2019/activate.bat b/packaging/vs2019/activate.bat new file mode 100644 index 0000000000..6f607ba751 --- /dev/null +++ b/packaging/vs2019/activate.bat @@ -0,0 +1,44 @@ +:: Set env vars that tell distutils to use the compiler that we put on path +SET DISTUTILS_USE_SDK=1 +SET MSSdk=1 + +SET "VS_VERSION=16.0" +SET "VS_MAJOR=16" +SET "VS_YEAR=2019" + +set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out" +set "MSYS2_ENV_CONV_EXCL=CL" + +:: For Python 3.5+, ensure that we link with the dynamic runtime. See +:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info +set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime140.dll" + +for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16^,17^) -property installationPath`) do ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VSINSTALLDIR=%%i\" + goto :vswhere + ) +) + +:vswhere + +:: Shorten PATH to avoid the `input line too long` error. +SET MyPath=%PATH% + +setlocal EnableDelayedExpansion + +SET TempPath="%MyPath:;=";"%" +SET var= +FOR %%a IN (%TempPath%) DO ( + IF EXIST %%~sa ( + SET "var=!var!;%%~sa" + ) +) + +set "TempPath=!var:~1!" +endlocal & set "PATH=%TempPath%" + +:: Shorten current directory too +FOR %%A IN (.) DO CD "%%~sA" + +:: other things added by install_activate.bat at package build time diff --git a/packaging/vs2019/conda_build_config.yaml b/packaging/vs2019/conda_build_config.yaml new file mode 100644 index 0000000000..358052ec01 --- /dev/null +++ b/packaging/vs2019/conda_build_config.yaml @@ -0,0 +1,24 @@ +blas_impl: + - mkl # [x86_64] +c_compiler: + - vs2019 # [win] +cxx_compiler: + - vs2019 # [win] +python: + - 3.5 + - 3.6 +# This differs from target_platform in that it determines what subdir the compiler +# will target, not what subdir the compiler package will be itself. +# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32 +# code on win-64 miniconda. +cross_compiler_target_platform: + - win-64 # [win] +target_platform: + - win-64 # [win] +vc: + - 14 +zip_keys: + - # [win] + - vc # [win] + - c_compiler # [win] + - cxx_compiler # [win] diff --git a/packaging/vs2019/install_activate.bat b/packaging/vs2019/install_activate.bat new file mode 100644 index 0000000000..3c38253aa5 --- /dev/null +++ b/packaging/vs2019/install_activate.bat @@ -0,0 +1,30 @@ +set YEAR=2019 +set VER=16 + +mkdir "%PREFIX%\etc\conda\activate.d" +COPY "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + +IF "%cross_compiler_target_platform%" == "win-64" ( + set "target_platform=amd64" + echo SET "CMAKE_GENERATOR=Visual Studio %VER% %YEAR% Win64" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + IF "%VSDEVCMD_ARGS%" == "" ( + echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + ) ELSE ( + echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + ) + echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + ) else ( + set "target_platform=x86" + echo SET "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo popd + ) + diff --git a/packaging/vs2019/install_runtime.bat b/packaging/vs2019/install_runtime.bat new file mode 100644 index 0000000000..e09a5ccfb0 --- /dev/null +++ b/packaging/vs2019/install_runtime.bat @@ -0,0 +1,49 @@ +set VC_PATH=x86 +if "%ARCH%"=="64" ( + set VC_PATH=x64 +) + +set MSC_VER=2019 + +rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015 +rem FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\Microsoft\DevDiv\VC\Servicing\14.0\IDE.x64" /v UpdateVersion`) DO ( +rem set SP=%%A +rem ) + +rem if not "%SP%" == "%PKG_VERSION%" ( +rem echo "Version detected from registry: %SP%" +rem echo "does not match version of package being built (%PKG_VERSION%)" +rem echo "Do you have current updates for VS 2015 installed?" +rem exit 1 +rem ) + + +REM ========== REQUIRES Win 10 SDK be installed, or files otherwise copied to location below! +robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%LIBRARY_BIN%" *.dll /E +robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%PREFIX%" *.dll /E +if %ERRORLEVEL% GEQ 8 exit 1 + +REM ========== This one comes from visual studio 2019 +set "VC_VER=142" + +for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16^,17^) -property installationPath`) do ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" + goto :eof + ) +) + +@setlocal +call "%VS15VARSALL%" x64 + +set "REDIST_ROOT=%VCToolsRedistDir%%VC_PATH%" + +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%LIBRARY_BIN%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%PREFIX%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%LIBRARY_BIN%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%PREFIX%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +@endlocal diff --git a/packaging/vs2019/meta.yaml b/packaging/vs2019/meta.yaml new file mode 100644 index 0000000000..94a0ed4db3 --- /dev/null +++ b/packaging/vs2019/meta.yaml @@ -0,0 +1,24 @@ +{% set vcver="14.2" %} +{% set vcfeature="14" %} +{% set vsyear="2019" %} +{% set fullver="15.4.27004.2010" %} + +package: + name: vs{{ vsyear }} + version: {{ fullver }} + +build: + skip: True [not win] + script_env: + - VSDEVCMD_ARGS # [win] + +outputs: + - name: vs{{ vsyear }}_{{ cross_compiler_target_platform }} + script: install_activate.bat + track_features: + # VS 2019 is binary-compatible with VS 2017/vc 14.1 and 2015/vc14. Tools are "v142". + strong: + - vc{{ vcfeature }} + about: + summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler + license: BSD 3-clause diff --git a/requirements.txt b/requirements.txt index 316bd5c7fd..42ca9d8f99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,5 @@ torch>=1.4.0 -# Required for Windows because it's the only available backend -SoundFile; sys_platform == 'win32' - # Optional for torchaudio.kaldi_io numpy kaldi_io diff --git a/setup.py b/setup.py index 624b47c317..5f86b23f08 100644 --- a/setup.py +++ b/setup.py @@ -44,10 +44,19 @@ def check_env_flag(name, default=''): # proper link order (sox, mad, flac, lame) # (the most important thing is that dependencies come after a libraryl # e.g., sox comes first) - extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/libsox.a')] - extra_objects += [os.path.join(audio_path, 'third_party/mad/lib/libmad.a')] - extra_objects += [os.path.join(audio_path, 'third_party/flac/lib/libFLAC.a')] - extra_objects += [os.path.join(audio_path, 'third_party/lame/lib/libmp3lame.a')] + if platform.system() == 'Windows': + extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/sox.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/mad/lib/mad.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/flac/lib/FLAC.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/lame/lib/mp3lame.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/ogg/lib/ogg.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/lpc10.lib')] + extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/gsm.lib')] + else: + extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/libsox.a')] + extra_objects += [os.path.join(audio_path, 'third_party/mad/lib/libmad.a')] + extra_objects += [os.path.join(audio_path, 'third_party/flac/lib/libFLAC.a')] + extra_objects += [os.path.join(audio_path, 'third_party/lame/lib/libmp3lame.a')] else: libraries += ['sox'] @@ -79,19 +88,16 @@ def check_env_flag(name, default=''): if pytorch_package_version is not None: pytorch_package_dep += "==" + pytorch_package_version -if platform.system() == 'Windows': - ext_modules = None -else: - ext_modules = [ - CppExtension( - 'torchaudio._torchaudio', - ['torchaudio/csrc/sox.cpp'], - libraries=libraries, - include_dirs=include_dirs + [cwd], - extra_compile_args=eca, - extra_objects=extra_objects, - extra_link_args=ela), - ] +ext_modules = [ + CppExtension( + 'torchaudio._torchaudio', + ['torchaudio/csrc/sox.cpp'], + libraries=libraries, + include_dirs=include_dirs + [cwd], + extra_compile_args=eca, + extra_objects=extra_objects, + extra_link_args=ela), +] setup( diff --git a/torchaudio/_backend.py b/torchaudio/_backend.py index f5646d7970..66b3bbbd2d 100644 --- a/torchaudio/_backend.py +++ b/torchaudio/_backend.py @@ -8,12 +8,8 @@ from . import _soundfile_backend, _sox_backend -if platform.system() == "Windows": - _audio_backend = "soundfile" - _audio_backends = {"soundfile": _soundfile_backend} -else: - _audio_backend = "sox" - _audio_backends = {"sox": _sox_backend, "soundfile": _soundfile_backend} +_audio_backend = "sox" +_audio_backends = {"sox": _sox_backend, "soundfile": _soundfile_backend} def set_audio_backend(backend: str) -> None: diff --git a/torchaudio/csrc/sox.cpp b/torchaudio/csrc/sox.cpp index 3ae81bef19..6974cdc4e4 100644 --- a/torchaudio/csrc/sox.cpp +++ b/torchaudio/csrc/sox.cpp @@ -2,12 +2,80 @@ #include #include +#include #include #include +#ifdef _WIN32 +// Additional headers for implementation for mkstemp +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#endif + namespace torch { namespace audio { namespace { +#ifdef _WIN32 +int mkstemp(char* tmpl) { + int len; + char* name; + int fd = -1; + int save_errno = errno; + + len = strlen(tmpl); + if (len < 6 || + strncmp(&tmpl[len - 6], "XXXXXX", 6)) { + return -1; + } + + name = &tmpl[len - 6]; + + std::random_device rd; + do { + for (unsigned i = 0; i < 6; ++i) { + name[i] = "abcdefghijklmnopqrstuvwxyz0123456789"[rd() % 36]; + } + + fd = _open(tmpl, _O_RDWR | _O_CREAT | _O_EXCL, _S_IWRITE | _S_IREAD); + } while (errno == EEXIST); + + if (fd >= 0) { + errno = save_errno; + return fd; + } else { + return -1; + } +} +static const std::string get_temp_path() { + char lpTempPathBuffer[MAX_PATH]; + + DWORD dwRetVal = GetTempPath( + MAX_PATH, // length of the buffer + lpTempPathBuffer); // buffer for path + + if (dwRetVal >= MAX_PATH + 1 || dwRetVal == 0) { + throw std::runtime_error("Error getting temporary directory using GetTempPath"); + } + + return std::string(lpTempPathBuffer); +} +static const std::string temp_dir = get_temp_path(); +#endif + /// Helper struct to safely close the sox_format_t descriptor. struct SoxDescriptor { explicit SoxDescriptor(sox_format_t* fd) noexcept : fd_(fd) {} @@ -261,6 +329,15 @@ int build_flow_effects(const std::string& file_name, close(tmp_fd); sox_format_t* output = sox_open_write(tmp_name, target_signal, target_encoding, "wav", nullptr, nullptr); + +#elif defined(_WIN32) + // According to the local test results, sox_open_memstream_write doesn't work on Windows. + std::string t = temp_dir + "fileXXXXXX"; + std::vector tn(t.c_str(), t.c_str() + t.size() + 1); + int tmp_fd = mkstemp(tn.data()); + _close(tmp_fd); + sox_format_t* output = sox_open_write(tn.data(), target_signal, + target_encoding, "wav", nullptr, nullptr); #else // create buffer and buffer_size for output in memwrite char* buffer; @@ -294,13 +371,15 @@ int build_flow_effects(const std::string& file_name, sox_effect_options(e, 0, nullptr); } else { int num_opts = tae.eopts.size(); - char* sox_args[max_num_eopts]; + std::unique_ptr sox_args(new char* [max_num_eopts]); for(std::vector::size_type i = 0; i != tae.eopts.size(); i++) { sox_args[i] = (char*) tae.eopts[i].c_str(); } - if(sox_effect_options(e, num_opts, sox_args) != SOX_SUCCESS) { + if(sox_effect_options(e, num_opts, sox_args.get()) != SOX_SUCCESS) { #ifdef __APPLE__ unlink(tmp_name); +#elif defined(_WIN32) + _unlink(tn.data()); #endif throw std::runtime_error("invalid effect options, see SoX docs for details"); } @@ -335,6 +414,12 @@ int build_flow_effects(const std::string& file_name, target_signal, target_encoding, "wav"); // delete temporary audio file unlink(tmp_name); +#elif defined(_WIN32) + // Same logic as MAC + sr = read_audio_file(tn.data(), otensor, ch_first, 0, 0, + target_signal, target_encoding, "wav"); + // delete temporary audio file + _unlink(tn.data()); #else // Resize output tensor to desired dimensions, different effects result in output->signal.length, // interm_signal.length and buffer size being inconsistent with the result of the file output.