vapoursynth-ares 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vapoursynth_ares-0.4.0/CMakeLists.txt +40 -0
- vapoursynth_ares-0.4.0/PKG-INFO +188 -0
- vapoursynth_ares-0.4.0/README.md +21 -0
- vapoursynth_ares-0.4.0/ares/.gitattributes +1 -0
- vapoursynth_ares-0.4.0/ares/.gitignore +32 -0
- vapoursynth_ares-0.4.0/ares/CMakeLists.txt +174 -0
- vapoursynth_ares-0.4.0/ares/LICENSE +21 -0
- vapoursynth_ares-0.4.0/ares/README.md +152 -0
- vapoursynth_ares-0.4.0/ares/cmake/Clang.cmake +17 -0
- vapoursynth_ares-0.4.0/ares/cmake/fetch.cmake +24 -0
- vapoursynth_ares-0.4.0/ares/cmake/soxr.cmake +37 -0
- vapoursynth_ares-0.4.0/ares/cmake/soxr_patches.cmake +4 -0
- vapoursynth_ares-0.4.0/ares/include/vapoursynth/COPYING.LESSER +502 -0
- vapoursynth_ares-0.4.0/ares/include/vapoursynth/VSConstants4.h +94 -0
- vapoursynth_ares-0.4.0/ares/include/vapoursynth/VSHelper4.h +217 -0
- vapoursynth_ares-0.4.0/ares/include/vapoursynth/VSScript4.h +109 -0
- vapoursynth_ares-0.4.0/ares/include/vapoursynth/VapourSynth4.h +514 -0
- vapoursynth_ares-0.4.0/ares/src/common/overflow.cpp +83 -0
- vapoursynth_ares-0.4.0/ares/src/common/overflow.hpp +220 -0
- vapoursynth_ares-0.4.0/ares/src/common/resquality.cpp +27 -0
- vapoursynth_ares-0.4.0/ares/src/common/resquality.hpp +21 -0
- vapoursynth_ares-0.4.0/ares/src/common/sampletype.cpp +148 -0
- vapoursynth_ares-0.4.0/ares/src/common/sampletype.hpp +38 -0
- vapoursynth_ares-0.4.0/ares/src/config.hpp +13 -0
- vapoursynth_ares-0.4.0/ares/src/plugin.cpp +14 -0
- vapoursynth_ares-0.4.0/ares/src/resample.cpp +958 -0
- vapoursynth_ares-0.4.0/ares/src/resample.hpp +118 -0
- vapoursynth_ares-0.4.0/ares/src/utils/array.hpp +36 -0
- vapoursynth_ares-0.4.0/ares/src/utils/debug.hpp +8 -0
- vapoursynth_ares-0.4.0/ares/src/utils/map.hpp +48 -0
- vapoursynth_ares-0.4.0/ares/src/utils/number.hpp +62 -0
- vapoursynth_ares-0.4.0/ares/src/utils/sample.hpp +119 -0
- vapoursynth_ares-0.4.0/ares/src/utils/string.cpp +21 -0
- vapoursynth_ares-0.4.0/ares/src/utils/string.hpp +11 -0
- vapoursynth_ares-0.4.0/ares/src/vsmap/vsmap.cpp +31 -0
- vapoursynth_ares-0.4.0/ares/src/vsmap/vsmap.hpp +12 -0
- vapoursynth_ares-0.4.0/ares/src/vsmap/vsmap_common.cpp +72 -0
- vapoursynth_ares-0.4.0/ares/src/vsmap/vsmap_common.hpp +100 -0
- vapoursynth_ares-0.4.0/ares/src/vsutils/audio.cpp +104 -0
- vapoursynth_ares-0.4.0/ares/src/vsutils/audio.hpp +31 -0
- vapoursynth_ares-0.4.0/ares/src/vsutils/bitshift.hpp +25 -0
- vapoursynth_ares-0.4.0/pyproject.toml +84 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
project(Ares_Package)
|
|
3
|
+
|
|
4
|
+
# === C++ Standard & Options ===
|
|
5
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
6
|
+
|
|
7
|
+
if(SKBUILD_PROJECT_VERSION)
|
|
8
|
+
set(VCS_TAG "v${SKBUILD_PROJECT_VERSION}" CACHE STRING "Version from scikit-build-core")
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
# === Dependencies ===
|
|
12
|
+
set(SUBMODULE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ares")
|
|
13
|
+
file(READ "${SUBMODULE_SRC_DIR}/CMakeLists.txt" SUBMODULE_CMAKE_CONTENT)
|
|
14
|
+
|
|
15
|
+
string(REPLACE "\${CMAKE_SOURCE_DIR}" "\${SUBMODULE_SRC_DIR}" MODIFIED_CMAKE_CONTENT "${SUBMODULE_CMAKE_CONTENT}")
|
|
16
|
+
string(REPLACE "\${CMAKE_CURRENT_LIST_DIR}" "\${SUBMODULE_SRC_DIR}" MODIFIED_CMAKE_CONTENT "${MODIFIED_CMAKE_CONTENT}")
|
|
17
|
+
|
|
18
|
+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ares_generated/CMakeLists.txt" "${MODIFIED_CMAKE_CONTENT}")
|
|
19
|
+
|
|
20
|
+
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
|
21
|
+
|
|
22
|
+
# === Target Definition & Configuration ===
|
|
23
|
+
add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/ares_generated" "${CMAKE_CURRENT_BINARY_DIR}/ares_build" EXCLUDE_FROM_ALL)
|
|
24
|
+
|
|
25
|
+
# The upstream CMakeLists adds -static for all non-Windows GCC/Clang builds
|
|
26
|
+
# (including inside generator expressions), which is incompatible with building
|
|
27
|
+
# a shared object (.so). Strip "-static" from the raw property string.
|
|
28
|
+
if(NOT WIN32)
|
|
29
|
+
get_target_property(_ares_link_opts AudioResample LINK_OPTIONS)
|
|
30
|
+
if(_ares_link_opts)
|
|
31
|
+
string(REPLACE ";-static;" ";" _ares_link_opts "${_ares_link_opts}")
|
|
32
|
+
string(REGEX REPLACE "-static[ \t]+" "" _ares_link_opts "${_ares_link_opts}")
|
|
33
|
+
set_target_properties(AudioResample PROPERTIES LINK_OPTIONS "${_ares_link_opts}")
|
|
34
|
+
endif()
|
|
35
|
+
endif()
|
|
36
|
+
|
|
37
|
+
add_custom_target(build_ares ALL DEPENDS AudioResample)
|
|
38
|
+
|
|
39
|
+
# === Packaging & Installation ===
|
|
40
|
+
install(TARGETS AudioResample RUNTIME DESTINATION . LIBRARY DESTINATION .)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vapoursynth-ares
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Audio sample rate and sample type converter for VapourSynth utilizing the SoX Resampler library
|
|
5
|
+
Author: ropagr
|
|
6
|
+
Maintainer-Email: =?utf-8?b?VmFyZMOr?= <ichunjo.le.terrible@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: ares/LICENSE
|
|
9
|
+
Project-URL: Source Code, https://github.com/ropagr/VS-AudioResample
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/ropagr/VS-AudioResample/issues
|
|
11
|
+
Project-URL: Repository, https://github.com/Jaded-Encoding-Thaumaturgy/vs-wheels
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Requires-Dist: vapoursynth>=75
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# VapourSynth Ares
|
|
17
|
+
|
|
18
|
+
This package contains the [VS-AudioResample](https://github.com/ropagr/VS-AudioResample) VapourSynth plugin.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install vapoursynth-ares
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Building from source
|
|
27
|
+
|
|
28
|
+
```powershell
|
|
29
|
+
uv build --package vapoursynth-ares
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
Detailed parameter information from the parent project follows.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
# VS-AudioResample
|
|
38
|
+
This is an audio sample rate and sample type converter for VapourSynth utilizing the [SoX Resampler](https://sourceforge.net/projects/soxr/) library.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
```python
|
|
42
|
+
ares.Resample(clip: vs.AudioNode,
|
|
43
|
+
sample_rate: int = -1,
|
|
44
|
+
sample_type: str = None,
|
|
45
|
+
quality: str = 'very_high',
|
|
46
|
+
overflow: str = 'error',
|
|
47
|
+
overflow_log: str = 'once'
|
|
48
|
+
) -> vs.AudioNode
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
*clip* - input audio clip (any format)
|
|
52
|
+
|
|
53
|
+
*sample_rate* - new sample rate (e.g. 16000, 44100, 48000, ...); same as input clip if negative; default: -1
|
|
54
|
+
|
|
55
|
+
*sample_type* - new sample type; same as input clip if None; default: None
|
|
56
|
+
```text
|
|
57
|
+
'i16' - integer 16-bit
|
|
58
|
+
'i24' - integer 24-bit
|
|
59
|
+
'i32' - integer 32-bit
|
|
60
|
+
'f32' - float 32-bit
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
*quality* - resample quality; default: 'very_high'
|
|
64
|
+
```text
|
|
65
|
+
'quick' - quick cubic interpolation
|
|
66
|
+
'low' - low quality
|
|
67
|
+
'medium' - medium quality
|
|
68
|
+
'high' - high quality
|
|
69
|
+
'very_high' - very high quality (default)
|
|
70
|
+
'max' - maximum quality
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
*overflow* - sample overflow handling; default: 'error'
|
|
74
|
+
```text
|
|
75
|
+
'error' - raise an error (default)
|
|
76
|
+
'clip' - clip overflowing samples (all types)
|
|
77
|
+
'clip_int' - clip overflowing samples for integer output sample types
|
|
78
|
+
keep overflowing samples for float output sample types
|
|
79
|
+
'keep_float' - keep overflowing samples for float output sample types
|
|
80
|
+
raise an error if output sample type is not float
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
To properly handle overflows the clip should be converted to a float sample type ('f32'), if not already.
|
|
84
|
+
|
|
85
|
+
⚠️ Overflowing samples of integer sample types (output) are always clipped (disruptive), or they raise an error
|
|
86
|
+
|
|
87
|
+
Use `overflow='keep_float'` for float output sample types to leave overflowing samples unchanged.
|
|
88
|
+
Then call a scaling function like `std.AudioGain` that scales the peak sample value below or to equal 1.0 (see [Example 3](#example-3))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
*overflow_log* - sample overflow logging; default: 'once'
|
|
92
|
+
```text
|
|
93
|
+
'all' - log all sample overflows (not recommended, this can be a lot)
|
|
94
|
+
'once' - log only the first sample overflow (default)
|
|
95
|
+
'none' - do not log any sample overflows
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Note**: a summary of all overflowing samples will be logged at the end of each function (if any)
|
|
99
|
+
|
|
100
|
+
### Example 1
|
|
101
|
+
|
|
102
|
+
basic usage
|
|
103
|
+
```python
|
|
104
|
+
import vapoursynth as vs
|
|
105
|
+
|
|
106
|
+
# load audio
|
|
107
|
+
audio = ...
|
|
108
|
+
|
|
109
|
+
# convert sample rate to 48000 and sample type to 24-bit integer
|
|
110
|
+
audio = vs.core.ares.Resample(audio, sample_rate=48000, sample_type='i24')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Example 2
|
|
114
|
+
|
|
115
|
+
change speed of an audio clip (but keep the sample rate)
|
|
116
|
+
```python
|
|
117
|
+
import vapoursynth as vs
|
|
118
|
+
|
|
119
|
+
# load audio
|
|
120
|
+
audio = ...
|
|
121
|
+
|
|
122
|
+
# speedup factor
|
|
123
|
+
factor = 2.0
|
|
124
|
+
|
|
125
|
+
resample_rate = round(audio.sample_rate / factor)
|
|
126
|
+
res_audio = vs.core.ares.Resample(audio, sample_rate=resample_rate)
|
|
127
|
+
audio = vs.core.std.AssumeSampleRate(res_audio, samplerate=audio.sample_rate)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
### Example 3
|
|
132
|
+
|
|
133
|
+
handle overflowing samples
|
|
134
|
+
```python
|
|
135
|
+
import vapoursynth as vs
|
|
136
|
+
|
|
137
|
+
# load audio (integer or float sample type)
|
|
138
|
+
audio = ...
|
|
139
|
+
|
|
140
|
+
# convert sample rate to 48000 and sample type to 32-bit float
|
|
141
|
+
# leave possible overflowing samples unchanged with 'keep_float'
|
|
142
|
+
audio = vs.core.ares.Resample(audio, sample_rate=48000, sample_type='f32', overflow='keep_float')
|
|
143
|
+
|
|
144
|
+
# scale audio samples
|
|
145
|
+
# choose a factor that limits the peak value below or to equal 1
|
|
146
|
+
audio = vs.core.std.AudioGain(audio, 0.5)
|
|
147
|
+
|
|
148
|
+
# optional: convert sample type back to integer if needed (e.g. 24-bit)
|
|
149
|
+
audio = vs.core.ares.Resample(audio, sample_type='i24')
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Dependencies
|
|
153
|
+
This project uses the [SoX Resampler](https://sourceforge.net/projects/soxr/) library (`soxr`), which is licensed under the [GNU Lesser General Public License (LGPL) v2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
|
|
154
|
+
|
|
155
|
+
The distributed binaries of this plugin statically link to `soxr` for performance and ease of use. If you prefer to use a customized version of `soxr`, or to link dynamically instead, you can build the plugin from source. See the [Build from source](#build-from-source) section for instructions.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## Build from source
|
|
159
|
+
To build the plugin, you’ll need CMake and a C++20-compatible compiler. OpenMP support is optional.
|
|
160
|
+
|
|
161
|
+
Run CMake to configure your preferred build system, then build the project. This process will automatically download and build the `soxr` dependency along with the plugin.
|
|
162
|
+
|
|
163
|
+
**Note:** You don’t need to download or build `soxr` yourself. However, if you prefer to use a local or customized version of `soxr`, you can provide its source path during configuration (see options below).
|
|
164
|
+
|
|
165
|
+
e.g. CMake with Ninja:
|
|
166
|
+
```sh
|
|
167
|
+
# EITHER build with statically linked soxr
|
|
168
|
+
cmake -G Ninja -B ./build-ninja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
|
|
169
|
+
|
|
170
|
+
# OR build with dynamically linked soxr
|
|
171
|
+
cmake -G Ninja -B ./build-ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
|
|
172
|
+
|
|
173
|
+
ninja -C ./build-ninja
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Custom options for cmake:
|
|
177
|
+
```text
|
|
178
|
+
-DSOXR_SOURCE_DIR=<PATH> Use a custom soxr source directory
|
|
179
|
+
(must contain CMakeLists.txt)
|
|
180
|
+
-DSOXR_USE_PATCHES=<ON|OFF> Enable patches needed for outdated
|
|
181
|
+
soxr build scripts (default: ON)
|
|
182
|
+
-DWITH_OPENMP=<ON|OFF> Enable or disable OpenMP support (default: ON)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# VapourSynth Ares
|
|
2
|
+
|
|
3
|
+
This package contains the [VS-AudioResample](https://github.com/ropagr/VS-AudioResample) VapourSynth plugin.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install vapoursynth-ares
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Building from source
|
|
12
|
+
|
|
13
|
+
```powershell
|
|
14
|
+
uv build --package vapoursynth-ares
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
Detailed parameter information from the parent project follows.
|
|
20
|
+
|
|
21
|
+
---
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Prerequisites
|
|
2
|
+
*.d
|
|
3
|
+
|
|
4
|
+
# Compiled Object files
|
|
5
|
+
*.slo
|
|
6
|
+
*.lo
|
|
7
|
+
*.o
|
|
8
|
+
*.obj
|
|
9
|
+
|
|
10
|
+
# Precompiled Headers
|
|
11
|
+
*.gch
|
|
12
|
+
*.pch
|
|
13
|
+
|
|
14
|
+
# Compiled Dynamic libraries
|
|
15
|
+
*.so
|
|
16
|
+
*.dylib
|
|
17
|
+
*.dll
|
|
18
|
+
|
|
19
|
+
# Fortran module files
|
|
20
|
+
*.mod
|
|
21
|
+
*.smod
|
|
22
|
+
|
|
23
|
+
# Compiled Static libraries
|
|
24
|
+
*.lai
|
|
25
|
+
*.la
|
|
26
|
+
*.a
|
|
27
|
+
*.lib
|
|
28
|
+
|
|
29
|
+
# Executables
|
|
30
|
+
*.exe
|
|
31
|
+
*.out
|
|
32
|
+
*.app
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
|
|
3
|
+
project(
|
|
4
|
+
VS-AudioResample
|
|
5
|
+
DESCRIPTION "audio sample rate and sample type converter for VapourSynth"
|
|
6
|
+
VERSION 0.4.0
|
|
7
|
+
LANGUAGES C CXX
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
# original soxr repository on sourceforge
|
|
11
|
+
# set(SOXR_GIT "https://git.code.sf.net/p/soxr/code")
|
|
12
|
+
|
|
13
|
+
# mirror on github (faster)
|
|
14
|
+
set(SOXR_GIT "https://github.com/chirlu/soxr.git")
|
|
15
|
+
|
|
16
|
+
# use commit from February 24, 2018
|
|
17
|
+
# commit id is the same for the sourceforge and github repository
|
|
18
|
+
set(SOXR_COMMIT "945b592b70470e29f917f4de89b4281fbbd540c0")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Include modules
|
|
22
|
+
include(FetchContent)
|
|
23
|
+
|
|
24
|
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|
25
|
+
include(Clang)
|
|
26
|
+
include(fetch)
|
|
27
|
+
include(soxr)
|
|
28
|
+
|
|
29
|
+
Clang_GetStyle_CXX(IS_CLANG_GCC IS_CLANG_MSVC)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Custom options
|
|
33
|
+
set(SOXR_SOURCE_DIR "" CACHE PATH "Path to a custom soxr source directory")
|
|
34
|
+
|
|
35
|
+
option(SOXR_USE_PATCHES "Apply patches to soxr for compatibility" ON)
|
|
36
|
+
|
|
37
|
+
# OpenMP support
|
|
38
|
+
|
|
39
|
+
if (DEFINED WITH_OPENMP)
|
|
40
|
+
set(WITH_OPENMP_SET_BY_USER ON)
|
|
41
|
+
else()
|
|
42
|
+
set(WITH_OPENMP_SET_BY_USER OFF)
|
|
43
|
+
endif()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
option(WITH_OPENMP "Enable OpenMP support" ON)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (WITH_OPENMP)
|
|
50
|
+
if (WITH_OPENMP_SET_BY_USER)
|
|
51
|
+
find_package(OpenMP)
|
|
52
|
+
if (NOT OpenMP_C_FOUND)
|
|
53
|
+
message(FATAL_ERROR "OpenMP requested, but not found.")
|
|
54
|
+
endif()
|
|
55
|
+
else()
|
|
56
|
+
find_package(OpenMP)
|
|
57
|
+
if (NOT OpenMP_C_FOUND)
|
|
58
|
+
message(WARNING "OpenMP enabled by default, but not found. Proceeding without it.")
|
|
59
|
+
set(WITH_OPENMP OFF)
|
|
60
|
+
endif()
|
|
61
|
+
endif()
|
|
62
|
+
endif()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Prepare soxr source directory
|
|
66
|
+
|
|
67
|
+
if (SOXR_SOURCE_DIR)
|
|
68
|
+
if (NOT EXISTS "${SOXR_SOURCE_DIR}/CMakeLists.txt")
|
|
69
|
+
message(FATAL_ERROR "Error: Specified soxr source directory does not contain CMakeLists.txt")
|
|
70
|
+
endif()
|
|
71
|
+
|
|
72
|
+
message(STATUS "Using custom soxr from ${SOXR_SOURCE_DIR}")
|
|
73
|
+
set(SOXR_BINARY_DIR "${CMAKE_BINARY_DIR}/soxr-build")
|
|
74
|
+
else()
|
|
75
|
+
fetch_FromGit("${SOXR_GIT}" "${SOXR_COMMIT}" SOXR_SOURCE_DIR SOXR_BINARY_DIR)
|
|
76
|
+
endif()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Add soxr source directory to the project
|
|
80
|
+
|
|
81
|
+
# disable soxr tests and libsamplerate bindings
|
|
82
|
+
set(BUILD_TESTS OFF CACHE INTERNAL "Disable tests")
|
|
83
|
+
set(WITH_LSR_BINDINGS OFF CACHE INTERNAL "Disable LSR bindings")
|
|
84
|
+
|
|
85
|
+
if (${SOXR_USE_PATCHES})
|
|
86
|
+
soxr_AddPatched("${SOXR_SOURCE_DIR}" "${SOXR_BINARY_DIR}")
|
|
87
|
+
else()
|
|
88
|
+
add_subdirectory("${SOXR_SOURCE_DIR}" "${SOXR_BINARY_DIR}")
|
|
89
|
+
endif()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
add_library(AudioResample SHARED
|
|
93
|
+
"${CMAKE_SOURCE_DIR}/src/plugin.cpp"
|
|
94
|
+
"${CMAKE_SOURCE_DIR}/src/resample.cpp"
|
|
95
|
+
"${CMAKE_SOURCE_DIR}/src/resample.hpp"
|
|
96
|
+
"${CMAKE_SOURCE_DIR}/src/common/overflow.cpp"
|
|
97
|
+
"${CMAKE_SOURCE_DIR}/src/common/overflow.hpp"
|
|
98
|
+
"${CMAKE_SOURCE_DIR}/src/common/resquality.cpp"
|
|
99
|
+
"${CMAKE_SOURCE_DIR}/src/common/resquality.hpp"
|
|
100
|
+
"${CMAKE_SOURCE_DIR}/src/common/sampletype.cpp"
|
|
101
|
+
"${CMAKE_SOURCE_DIR}/src/common/sampletype.hpp"
|
|
102
|
+
"${CMAKE_SOURCE_DIR}/src/utils/array.hpp"
|
|
103
|
+
"${CMAKE_SOURCE_DIR}/src/utils/debug.hpp"
|
|
104
|
+
"${CMAKE_SOURCE_DIR}/src/utils/map.hpp"
|
|
105
|
+
"${CMAKE_SOURCE_DIR}/src/utils/number.hpp"
|
|
106
|
+
"${CMAKE_SOURCE_DIR}/src/utils/sample.hpp"
|
|
107
|
+
"${CMAKE_SOURCE_DIR}/src/utils/string.cpp"
|
|
108
|
+
"${CMAKE_SOURCE_DIR}/src/utils/string.hpp"
|
|
109
|
+
"${CMAKE_SOURCE_DIR}/src/vsmap/vsmap.cpp"
|
|
110
|
+
"${CMAKE_SOURCE_DIR}/src/vsmap/vsmap.hpp"
|
|
111
|
+
"${CMAKE_SOURCE_DIR}/src/vsmap/vsmap_common.cpp"
|
|
112
|
+
"${CMAKE_SOURCE_DIR}/src/vsmap/vsmap_common.hpp"
|
|
113
|
+
"${CMAKE_SOURCE_DIR}/src/vsutils/audio.cpp"
|
|
114
|
+
"${CMAKE_SOURCE_DIR}/src/vsutils/audio.hpp"
|
|
115
|
+
"${CMAKE_SOURCE_DIR}/src/vsutils/bitshift.hpp"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
target_include_directories(AudioResample
|
|
119
|
+
PRIVATE
|
|
120
|
+
"${CMAKE_SOURCE_DIR}/include/vapoursynth"
|
|
121
|
+
"${CMAKE_SOURCE_DIR}/src"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
target_compile_features(AudioResample PRIVATE cxx_std_20)
|
|
125
|
+
|
|
126
|
+
target_link_libraries(AudioResample PRIVATE soxr)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# Linker options for OpenMP support
|
|
130
|
+
if (WITH_OPENMP)
|
|
131
|
+
if ((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR ${IS_CLANG_GCC}) AND NOT ${BUILD_SHARED_LIBS})
|
|
132
|
+
# Windows + GCC/Clang(GCC) + static
|
|
133
|
+
# use -fopenmp as linker argument to let the linker find a static library
|
|
134
|
+
# because apparently "target_link_libraries(AudioResample PRIVATE OpenMP::OpenMP_CXX)" prefers a dynamically linked library
|
|
135
|
+
target_link_options(AudioResample PRIVATE -static -fopenmp)
|
|
136
|
+
else()
|
|
137
|
+
target_link_libraries(AudioResample PRIVATE OpenMP::OpenMP_C)
|
|
138
|
+
endif()
|
|
139
|
+
endif()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
target_compile_options(AudioResample
|
|
143
|
+
PRIVATE
|
|
144
|
+
# Debug + CXX + GCC/Clang(GCC)
|
|
145
|
+
$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<BOOL:${IS_CLANG_GCC}>>>:
|
|
146
|
+
-Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-unused-variable>
|
|
147
|
+
|
|
148
|
+
# Release + CXX + GCC/Clang(GCC)
|
|
149
|
+
$<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<BOOL:${IS_CLANG_GCC}>>>:
|
|
150
|
+
-O2 -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-unused-variable>
|
|
151
|
+
|
|
152
|
+
# Debug + CXX + MSVC/Clang(MSVC)
|
|
153
|
+
$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:MSVC>,$<BOOL:${IS_CLANG_MSVC}>>>:
|
|
154
|
+
/W4 /wd4100 /wd4702 /Zc:__cplusplus>
|
|
155
|
+
|
|
156
|
+
# Release + CXX + MSVC/Clang(MSVC)
|
|
157
|
+
$<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:MSVC>,$<BOOL:${IS_CLANG_MSVC}>>>:
|
|
158
|
+
/W4 /wd4100 /wd4702 /Zc:__cplusplus>
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
target_link_options(AudioResample
|
|
163
|
+
PRIVATE
|
|
164
|
+
# Windows + CXX + GCC/Clang(GCC)
|
|
165
|
+
$<$<AND:$<PLATFORM_ID:Windows>,$<LINK_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<BOOL:${IS_CLANG_GCC}>>>:
|
|
166
|
+
-static -static-libstdc++ -s>
|
|
167
|
+
|
|
168
|
+
# Non-Windows + CXX + GCC/Clang(GCC)
|
|
169
|
+
$<$<AND:$<NOT:$<PLATFORM_ID:Windows>>,$<LINK_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<BOOL:${IS_CLANG_GCC}>>>:
|
|
170
|
+
-static -s>
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
set_target_properties(AudioResample PROPERTIES PREFIX "")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ropagr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# VS-AudioResample
|
|
2
|
+
This is an audio sample rate and sample type converter for VapourSynth utilizing the [SoX Resampler](https://sourceforge.net/projects/soxr/) library.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
```python
|
|
6
|
+
ares.Resample(clip: vs.AudioNode,
|
|
7
|
+
sample_rate: int = -1,
|
|
8
|
+
sample_type: str = None,
|
|
9
|
+
quality: str = 'very_high',
|
|
10
|
+
overflow: str = 'error',
|
|
11
|
+
overflow_log: str = 'once'
|
|
12
|
+
) -> vs.AudioNode
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
*clip* - input audio clip (any format)
|
|
16
|
+
|
|
17
|
+
*sample_rate* - new sample rate (e.g. 16000, 44100, 48000, ...); same as input clip if negative; default: -1
|
|
18
|
+
|
|
19
|
+
*sample_type* - new sample type; same as input clip if None; default: None
|
|
20
|
+
```text
|
|
21
|
+
'i16' - integer 16-bit
|
|
22
|
+
'i24' - integer 24-bit
|
|
23
|
+
'i32' - integer 32-bit
|
|
24
|
+
'f32' - float 32-bit
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
*quality* - resample quality; default: 'very_high'
|
|
28
|
+
```text
|
|
29
|
+
'quick' - quick cubic interpolation
|
|
30
|
+
'low' - low quality
|
|
31
|
+
'medium' - medium quality
|
|
32
|
+
'high' - high quality
|
|
33
|
+
'very_high' - very high quality (default)
|
|
34
|
+
'max' - maximum quality
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
*overflow* - sample overflow handling; default: 'error'
|
|
38
|
+
```text
|
|
39
|
+
'error' - raise an error (default)
|
|
40
|
+
'clip' - clip overflowing samples (all types)
|
|
41
|
+
'clip_int' - clip overflowing samples for integer output sample types
|
|
42
|
+
keep overflowing samples for float output sample types
|
|
43
|
+
'keep_float' - keep overflowing samples for float output sample types
|
|
44
|
+
raise an error if output sample type is not float
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To properly handle overflows the clip should be converted to a float sample type ('f32'), if not already.
|
|
48
|
+
|
|
49
|
+
⚠️ Overflowing samples of integer sample types (output) are always clipped (disruptive), or they raise an error
|
|
50
|
+
|
|
51
|
+
Use `overflow='keep_float'` for float output sample types to leave overflowing samples unchanged.
|
|
52
|
+
Then call a scaling function like `std.AudioGain` that scales the peak sample value below or to equal 1.0 (see [Example 3](#example-3))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
*overflow_log* - sample overflow logging; default: 'once'
|
|
56
|
+
```text
|
|
57
|
+
'all' - log all sample overflows (not recommended, this can be a lot)
|
|
58
|
+
'once' - log only the first sample overflow (default)
|
|
59
|
+
'none' - do not log any sample overflows
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Note**: a summary of all overflowing samples will be logged at the end of each function (if any)
|
|
63
|
+
|
|
64
|
+
### Example 1
|
|
65
|
+
|
|
66
|
+
basic usage
|
|
67
|
+
```python
|
|
68
|
+
import vapoursynth as vs
|
|
69
|
+
|
|
70
|
+
# load audio
|
|
71
|
+
audio = ...
|
|
72
|
+
|
|
73
|
+
# convert sample rate to 48000 and sample type to 24-bit integer
|
|
74
|
+
audio = vs.core.ares.Resample(audio, sample_rate=48000, sample_type='i24')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Example 2
|
|
78
|
+
|
|
79
|
+
change speed of an audio clip (but keep the sample rate)
|
|
80
|
+
```python
|
|
81
|
+
import vapoursynth as vs
|
|
82
|
+
|
|
83
|
+
# load audio
|
|
84
|
+
audio = ...
|
|
85
|
+
|
|
86
|
+
# speedup factor
|
|
87
|
+
factor = 2.0
|
|
88
|
+
|
|
89
|
+
resample_rate = round(audio.sample_rate / factor)
|
|
90
|
+
res_audio = vs.core.ares.Resample(audio, sample_rate=resample_rate)
|
|
91
|
+
audio = vs.core.std.AssumeSampleRate(res_audio, samplerate=audio.sample_rate)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Example 3
|
|
96
|
+
|
|
97
|
+
handle overflowing samples
|
|
98
|
+
```python
|
|
99
|
+
import vapoursynth as vs
|
|
100
|
+
|
|
101
|
+
# load audio (integer or float sample type)
|
|
102
|
+
audio = ...
|
|
103
|
+
|
|
104
|
+
# convert sample rate to 48000 and sample type to 32-bit float
|
|
105
|
+
# leave possible overflowing samples unchanged with 'keep_float'
|
|
106
|
+
audio = vs.core.ares.Resample(audio, sample_rate=48000, sample_type='f32', overflow='keep_float')
|
|
107
|
+
|
|
108
|
+
# scale audio samples
|
|
109
|
+
# choose a factor that limits the peak value below or to equal 1
|
|
110
|
+
audio = vs.core.std.AudioGain(audio, 0.5)
|
|
111
|
+
|
|
112
|
+
# optional: convert sample type back to integer if needed (e.g. 24-bit)
|
|
113
|
+
audio = vs.core.ares.Resample(audio, sample_type='i24')
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Dependencies
|
|
117
|
+
This project uses the [SoX Resampler](https://sourceforge.net/projects/soxr/) library (`soxr`), which is licensed under the [GNU Lesser General Public License (LGPL) v2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
|
|
118
|
+
|
|
119
|
+
The distributed binaries of this plugin statically link to `soxr` for performance and ease of use. If you prefer to use a customized version of `soxr`, or to link dynamically instead, you can build the plugin from source. See the [Build from source](#build-from-source) section for instructions.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## Build from source
|
|
123
|
+
To build the plugin, you’ll need CMake and a C++20-compatible compiler. OpenMP support is optional.
|
|
124
|
+
|
|
125
|
+
Run CMake to configure your preferred build system, then build the project. This process will automatically download and build the `soxr` dependency along with the plugin.
|
|
126
|
+
|
|
127
|
+
**Note:** You don’t need to download or build `soxr` yourself. However, if you prefer to use a local or customized version of `soxr`, you can provide its source path during configuration (see options below).
|
|
128
|
+
|
|
129
|
+
e.g. CMake with Ninja:
|
|
130
|
+
```sh
|
|
131
|
+
# EITHER build with statically linked soxr
|
|
132
|
+
cmake -G Ninja -B ./build-ninja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
|
|
133
|
+
|
|
134
|
+
# OR build with dynamically linked soxr
|
|
135
|
+
cmake -G Ninja -B ./build-ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
|
|
136
|
+
|
|
137
|
+
ninja -C ./build-ninja
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Custom options for cmake:
|
|
141
|
+
```text
|
|
142
|
+
-DSOXR_SOURCE_DIR=<PATH> Use a custom soxr source directory
|
|
143
|
+
(must contain CMakeLists.txt)
|
|
144
|
+
-DSOXR_USE_PATCHES=<ON|OFF> Enable patches needed for outdated
|
|
145
|
+
soxr build scripts (default: ON)
|
|
146
|
+
-DWITH_OPENMP=<ON|OFF> Enable or disable OpenMP support (default: ON)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function(Clang_GetStyle_CXX IS_CLANG_GCC IS_CLANG_MSVC)
|
|
2
|
+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
3
|
+
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
|
4
|
+
set(${IS_CLANG_GCC} OFF PARENT_SCOPE)
|
|
5
|
+
set(${IS_CLANG_MSVC} ON PARENT_SCOPE)
|
|
6
|
+
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
|
|
7
|
+
set(${IS_CLANG_GCC} ON PARENT_SCOPE)
|
|
8
|
+
set(${IS_CLANG_MSVC} OFF PARENT_SCOPE)
|
|
9
|
+
else()
|
|
10
|
+
set(${IS_CLANG_GCC} OFF PARENT_SCOPE)
|
|
11
|
+
set(${IS_CLANG_MSVC} OFF PARENT_SCOPE)
|
|
12
|
+
endif()
|
|
13
|
+
else()
|
|
14
|
+
set(${IS_CLANG_GCC} OFF PARENT_SCOPE)
|
|
15
|
+
set(${IS_CLANG_MSVC} OFF PARENT_SCOPE)
|
|
16
|
+
endif()
|
|
17
|
+
endfunction()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
include(FetchContent)
|
|
2
|
+
|
|
3
|
+
function(fetch_FromGit SOXR_GIT SOXR_COMMIT SOXR_SOURCE_DIR SOXR_BINARY_DIR)
|
|
4
|
+
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
|
|
5
|
+
FetchContent_Populate(
|
|
6
|
+
soxr
|
|
7
|
+
GIT_REPOSITORY ${SOXR_GIT}
|
|
8
|
+
GIT_PROGRESS ON
|
|
9
|
+
GIT_TAG ${SOXR_COMMIT}
|
|
10
|
+
)
|
|
11
|
+
else()
|
|
12
|
+
FetchContent_Declare(
|
|
13
|
+
soxr
|
|
14
|
+
GIT_REPOSITORY ${SOXR_GIT}
|
|
15
|
+
GIT_PROGRESS ON
|
|
16
|
+
GIT_TAG ${SOXR_COMMIT}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
FetchContent_Populate(soxr)
|
|
20
|
+
endif()
|
|
21
|
+
|
|
22
|
+
set(${SOXR_SOURCE_DIR} "${soxr_SOURCE_DIR}" PARENT_SCOPE)
|
|
23
|
+
set(${SOXR_BINARY_DIR} "${soxr_BINARY_DIR}" PARENT_SCOPE)
|
|
24
|
+
endfunction()
|