summaryrefslogtreecommitdiff
path: root/recipes/soundtouch/0001-Add-Meson-build.patch
blob: 356e5a22770ab70229955abd29a8404473c85b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
From bb3c46416624a573c62cb0ad09533a5d433b65e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Le=20Page?= <llepage@igalia.com>
Date: Tue, 30 Apr 2024 21:17:12 +0200
Subject: [PATCH 1/1] Add Meson build

---
 LICENSE.build                       |  19 +++++
 include/meson.build                 |  19 +++++
 meson.build                         | 122 ++++++++++++++++++++++++++++
 meson_options.txt                   |   9 ++
 source/Android-lib/meson.build      |  12 +++
 source/SoundStretch/meson.build     |  16 ++++
 source/SoundTouch/meson.build       |  48 +++++++++++
 source/SoundTouchDLL/meson.build    |  47 +++++++++++
 source/SoundTouchDLL/meson/afxres.h |   1 +
 source/meson.build                  |   6 ++
 10 files changed, 299 insertions(+)
 create mode 100644 LICENSE.build
 create mode 100644 include/meson.build
 create mode 100644 meson.build
 create mode 100644 meson_options.txt
 create mode 100644 source/Android-lib/meson.build
 create mode 100644 source/SoundStretch/meson.build
 create mode 100644 source/SoundTouch/meson.build
 create mode 100644 source/SoundTouchDLL/meson.build
 create mode 100644 source/SoundTouchDLL/meson/afxres.h
 create mode 100644 source/meson.build

diff --git a/LICENSE.build b/LICENSE.build
new file mode 100644
index 0000000..b59833d
--- /dev/null
+++ b/LICENSE.build
@@ -0,0 +1,19 @@
+Copyright (c) 2021 The Meson development team
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/include/meson.build b/include/meson.build
new file mode 100644
index 0000000..a395462
--- /dev/null
+++ b/include/meson.build
@@ -0,0 +1,19 @@
+soundtouch_headers = files(
+    'BPMDetect.h',
+    'FIFOSampleBuffer.h',
+    'FIFOSamplePipe.h',
+    'STTypes.h',
+    'SoundTouch.h',
+)
+
+soundtouch_config_h = configure_file(
+    output: 'soundtouch_config.h',
+    configuration: conf,
+)
+
+soundtouch_includes = include_directories('.')
+
+install_headers(
+    [soundtouch_headers, soundtouch_config_h],
+    subdir: 'soundtouch'
+)
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..1977d0d
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,122 @@
+project(
+    'soundtouch',
+    'c', 'cpp',
+    version: '2.3.2',
+    license: 'LGPL-2.1-or-later',
+    default_options: [
+        'debug=true',
+        'optimization=3',
+        'c_std=c11',
+        # to avoid Meson's warning under MSVC
+        'cpp_std=c++14',
+        # See below ("ST_NO_EXCEPTION_HANDLING") for the rationale
+        'cpp_eh=default',
+        'pkgconfig.relocatable=true',
+    ],
+    meson_version: '>= 0.53',
+)
+
+cpp = meson.get_compiler('cpp')
+system = host_machine.system()
+cpu = host_machine.cpu()
+
+openmp = dependency('openmp', required: get_option('openmp'))
+m = cpp.find_library('m', required: false)
+
+soundtouch_args = []
+
+conf = configuration_data()
+
+# Autotools applies -Ofast (implies -O3 -ffast-math) to allow gcc
+# autovectorization generate effective SIMD code.
+# I prefer here to do so only with these to avoid surprises
+# at lower levels. -- amyspark
+if get_option('optimization') in ['2', '3', 's']
+    soundtouch_args += cpp.get_supported_arguments(
+        '/fp:fast',
+        '-ffast-math',
+    )
+endif
+
+is_android_softfp = cpp.compiles('''
+#if defined(__SOFTFP__) && defined(ANDROID)
+#else
+#error "Not under Android soft FP"
+#endif''', name: 'targeting Android with soft float implementation')
+
+if get_option('integer_samples')
+    conf.set('SOUNDTOUCH_INTEGER_SAMPLES', 1)
+    soundtouch_args += ['-DSOUNDTOUCH_INTEGER_SAMPLES=1']
+else
+    conf.set('SOUNDTOUCH_FLOAT_SAMPLES', 1)
+    soundtouch_args += ['-DSOUNDTOUCH_FLOAT_SAMPLES=1']
+endif
+
+neon_cpu = cpu in ['arm', 'aarch64']
+
+# Use ARM instruction set instead of Thumb for improved calculation performance in ARM CPUs
+if cpu == 'arm' and system == 'android'
+    if cpp.get_define('__thumb__') != ''
+        soundtouch_args += cpp.get_supported_arguments('-marm')
+    endif
+endif
+
+if neon_cpu and get_option('neon')
+    conf.set('SOUNDTOUCH_USE_NEON', 1)
+    soundtouch_args += ['-DSOUNDTOUCH_USE_NEON=1']
+    soundtouch_args += cpp.get_supported_arguments('-mfpu=neon')
+endif
+
+# GCC, by default, handles exceptions in C++ sources as /EHsc, allowing
+# exceptions intra C++ code, and terminating the app on hitting a C function's
+# stack.
+# Grep ST_NO_EXCEPTION_HANDLING and see:
+# https://learn.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=msvc-170
+# https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fexceptions
+#
+# However, -fexceptions in Application.mk must be manually injected, as
+# their toolchain does not add it for historical reasons.
+# https://developer.android.com/ndk/guides/cpp-support?hl=es-419
+if get_option('cpp_eh') in ['none']
+    soundtouch_args += ['-DST_NO_EXCEPTION_HANDLING']
+elif system == 'android'
+    soundtouch_args += cpp.get_supported_arguments('-fexceptions')
+endif
+
+# Work around Android Clang / MS Clang not defining __GNUC__
+# This affects cpuid detection in x86 and x64 targets
+# Amyspark: careful with this flag, it may interfere with STTypes.h
+if cpp.get_define('__clang__') != '' and cpp.get_define('__GNUC__') == ''
+    soundtouch_args += cpp.get_supported_arguments('-fgnuc-version=10')
+endif
+
+# Amyspark: Turn off certain warnings that can trigger Werror
+soundtouch_args += cpp.get_supported_arguments(
+    '-Wno-unused-variable',
+    '-Wno-sign-compare',
+    '-Wno-unused-but-set-variable',
+    '-Wno-inconsistent-missing-override',
+    '-Wno-unused-const-variable',
+)
+
+if cpu == 'x86'
+    soundtouch_args += cpp.get_supported_arguments('-mstackrealign')
+endif
+
+deps = [
+    openmp,
+    m,
+]
+
+subdir('include')
+subdir('source')
+
+pkg = import('pkgconfig')
+
+pkg.generate(
+    soundtouch_lib,
+    name: 'SoundTouch',
+    description: 'SoundTouch is an open-source audio processing library for changing the Tempo, Pitch and Playback Rates of audio streams or files',
+    filebase: 'soundtouch',
+    subdirs: 'soundtouch'
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..9aa9714
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,9 @@
+option('integer_samples', type: 'boolean', value: false, description: 'Use integers instead of floats for samples')
+
+option('neon', type: 'boolean', value: true, description: 'Use ARM Neon SIMD instructions if in ARM CPU')
+
+option('soundtouch_dll', type: 'boolean', value: true, description: 'Build SoundTouchDLL C wrapper library.')
+
+option('soundstretch', type: 'boolean', value: false, description: 'Build soundstretch command line utility.')
+
+option('openmp', type: 'feature', value: 'disabled', description: 'Use parallel multicore calculation through OpenMP')
diff --git a/source/Android-lib/meson.build b/source/Android-lib/meson.build
new file mode 100644
index 0000000..38adee2
--- /dev/null
+++ b/source/Android-lib/meson.build
@@ -0,0 +1,12 @@
+soundtouch_sources_android = files(
+    'jni/soundtouch-jni.cpp',
+)
+
+log = cpp.find_library('log', required: true)
+
+deps += [log]
+
+soundtouch_args += cpp.get_supported_arguments(
+    '-fdata-sections',
+    '-ffunction-sections',
+)
diff --git a/source/SoundStretch/meson.build b/source/SoundStretch/meson.build
new file mode 100644
index 0000000..aebf564
--- /dev/null
+++ b/source/SoundStretch/meson.build
@@ -0,0 +1,16 @@
+soundstretch_sources = files(
+    'main.cpp',
+    'RunParameters.cpp',
+    'WavFile.cpp',
+)
+
+if get_option('soundstretch')
+    soundstretch_bin = executable(
+        'soundstretch',
+        soundstretch_sources,
+        cpp_args: soundtouch_args,
+        include_directories: include_directories('.'),
+        dependencies: soundtouch_dep,
+        install: true,
+    )
+endif
diff --git a/source/SoundTouch/meson.build b/source/SoundTouch/meson.build
new file mode 100644
index 0000000..26911bd
--- /dev/null
+++ b/source/SoundTouch/meson.build
@@ -0,0 +1,48 @@
+soundtouch_sources = files(
+    'AAFilter.cpp',
+    'BPMDetect.cpp',
+    'cpu_detect_x86.cpp',
+    'FIFOSampleBuffer.cpp',
+    'FIRFilter.cpp',
+    'InterpolateCubic.cpp',
+    'InterpolateLinear.cpp',
+    'InterpolateShannon.cpp',
+    'mmx_optimized.cpp',
+    'PeakFinder.cpp',
+    'RateTransposer.cpp',
+    'SoundTouch.cpp',
+    'sse_optimized.cpp',
+    'TDStretch.cpp',
+)
+
+# This library requires WINDOWS_EXPORT_ALL_SYMBOLS to export all the relevant
+# classes under MSVC. That's beyond mindbending to do for C++, see how it's done:
+# https://github.com/Kitware/CMake/blob/master/Source/bindexplib.cxx#L237
+if cpp.get_linker_id() in ['link', 'lld-link'] # MSVC relies on __declspec
+    soundtouch_lib = static_library(
+        'SoundTouch',
+        soundtouch_sources,
+        cpp_args: soundtouch_args,
+        dependencies: deps,
+        include_directories: soundtouch_includes,
+        install: true
+    )
+else # GCC and Clang etc. do not
+    soundtouch_lib = library(
+        'SoundTouch',
+        soundtouch_sources,
+        cpp_args: soundtouch_args,
+        dependencies: deps,
+        include_directories: soundtouch_includes,
+        version: meson.project_version(),
+        # DO NOT CHANGE THIS, SEE ABOVE!
+        # Also the Android.mk file was designed for GCC, not Clang (API 17+)
+        gnu_symbol_visibility: 'default',
+        install: true
+    )
+endif
+
+soundtouch_dep = declare_dependency(
+    link_with: soundtouch_lib,
+    include_directories: soundtouch_includes,
+)
diff --git a/source/SoundTouchDLL/meson.build b/source/SoundTouchDLL/meson.build
new file mode 100644
index 0000000..b0b41b5
--- /dev/null
+++ b/source/SoundTouchDLL/meson.build
@@ -0,0 +1,47 @@
+soundtouch_dll_sources = files(
+    'SoundTouchDLL.cpp',
+)
+
+soundtouch_dll_includes = files(
+    'SoundTouchDLL.h',
+)
+
+soundtouch_dll_include_directories = [include_directories('.')]
+
+windows = import('windows')
+
+if system in ['windows', 'cygwin']
+    if not cpp.has_header('afxres.h')
+        # Work around lack of afxres.h (ATL/MFC component missing in MSVS)
+        soundtouch_dll_include_directories += [include_directories('meson')]
+    endif
+
+    soundtouch_dll_sources += windows.compile_resources(
+        files(
+            'SoundTouchDLL.rc'
+        ),
+        include_directories: soundtouch_dll_include_directories
+    )
+endif
+
+if get_option('soundtouch_dll')
+    soundtouch_dll_args = [soundtouch_args, '-DDLL_EXPORTS']
+
+    soundtouch_dll_lib = shared_library(
+        'SoundTouchDLL',
+        soundtouch_dll_sources,
+        cpp_args: soundtouch_dll_args,
+        include_directories: soundtouch_dll_include_directories,
+        dependencies: soundtouch_dep,
+        gnu_symbol_visibility: 'inlineshidden',
+    )
+
+    soundtouch_dll_dep = declare_dependency(
+        link_with: soundtouch_dll_lib,
+    )
+
+    install_headers(
+        soundtouch_dll_includes,
+        subdir: 'soundtouch',
+    )
+endif
diff --git a/source/SoundTouchDLL/meson/afxres.h b/source/SoundTouchDLL/meson/afxres.h
new file mode 100644
index 0000000..776a87c
--- /dev/null
+++ b/source/SoundTouchDLL/meson/afxres.h
@@ -0,0 +1 @@
+#include <windows.h>
diff --git a/source/meson.build b/source/meson.build
new file mode 100644
index 0000000..6b809f5
--- /dev/null
+++ b/source/meson.build
@@ -0,0 +1,6 @@
+if system == 'android'
+    subdir('Android-lib')
+endif
+subdir('SoundTouch')
+subdir('SoundStretch')
+subdir('SoundTouchDLL')
-- 
2.34.1