Overview

Request 5589 (accepted)

New upstream release

Submit package home:zaitor:...s:Essentials / pipewire-aptx to package Essentials / pipewire-aptx

pipewire-aptx.changes Changed
x
 
1
@@ -1,4 +1,9 @@
2
 -------------------------------------------------------------------
3
+Mon Jul 11 18:00:28 UTC 2022 - Bjørn Lie <zaitor@opensuse.org>
4
+
5
+- Update to version 0.3.54
6
+
7
+-------------------------------------------------------------------
8
 Thu Jul  7 18:13:40 UTC 2022 - Bjørn Lie <zaitor@opensuse.org>
9
 
10
 - Update to version 0.3.53
11
pipewire-aptx.spec Changed
10
 
1
@@ -7,7 +7,7 @@
2
 %define soversion 0_2
3
 
4
 Name:           pipewire-aptx
5
-Version:        0.3.53
6
+Version:        0.3.54
7
 Release:        0
8
 Summary:        PipeWire Bluetooth aptX codec plugin
9
 License:        MIT
10
pipewire-0.3.53.tar.gz/NEWS -> pipewire-0.3.54.tar.gz/NEWS Changed
66
 
1
@@ -1,3 +1,55 @@
2
+# PipeWire 0.3.54 (2022-07-07)
3
+
4
+This is a quick bugfix release that is API and ABI compatible with previous
5
+0.3.x releases.
6
+
7
+## Highlights
8
+  - Some critical bugs in the new audioconvert were fixed. The old
9
+    adapter had internal buffering that was abused in some places.
10
+  - The bluetooth sources were rewritten using a ringbuffer to make them
11
+    more reliable to jitter and remove old audioconvert behaviour.
12
+  - Many improvements to the audio converter.
13
+  - Native DSD128 and up is now supported by pw-dsdplay.
14
+
15
+
16
+## tools
17
+  - Support DSD128 to DSD512 as well by scaling the amount of samples
18
+    to read per time slice.
19
+
20
+## SPA
21
+  - Format conversion is now generated with macros to remove duplication
22
+    of code.
23
+  - 24bits conversions were rewritten to use the generic conversion
24
+    functions.
25
+  - Temporary buffers in audioconvert are now made large enough in all
26
+    cases.
27
+  - Fix draining in audioconvert. This fixes speaker-test.
28
+  - Fix the channel remapping. (#2502, #2490)
29
+  - Audio conversion constants were tweaked to handle the maximum ranges
30
+    and provide lossless conversion between 24bits and floats.
31
+  - Vector code and C code are aligned and the unit tests are activated
32
+    again. A new lossless conversion test was added.
33
+  - Fix an underrun case where the adapter would not ask for more data.
34
+  - Fix PROP_INFO for audioconvert. (#2488)
35
+  - Use the blackman window again for the resampler, the cosh window has
36
+    some bugs that can cause distortion in some cases. (#2483)
37
+  - Add more unit tests for audioconvert. Add end-to-end conversion tests.
38
+  - Don't leak memory in format converter.
39
+
40
+## pulse-server
41
+  - Card properties are now also added to sinks and sources, just like
42
+    in pulseaudio.
43
+  - Increase the maxlength size to at least 4 times the fragsize to avoid
44
+    xruns.
45
+  - Fix a race when setting default devices.
46
+
47
+## Bluetooth
48
+  - The source was rewritten to use a ringbuffer. This avoids regressions
49
+    caused by audioconvert. 
50
+
51
+Older versions:
52
+
53
+
54
 # PipeWire 0.3.53 (2022-06-30)
55
 
56
 This is a bugfix release that is API and ABI compatible with previous
57
@@ -74,8 +126,6 @@
58
     giving a -19 nice level to all processes, not just the pipewire
59
     daemon.
60
 
61
-Older versions:
62
-
63
 # PipeWire 0.3.52 (2022-06-09)
64
 
65
 This is a bugfix release that is API and ABI compatible with previous
66
pipewire-0.3.53.tar.gz/meson.build -> pipewire-0.3.54.tar.gz/meson.build Changed
8
 
1
@@ -1,5 +1,5 @@
2
 project('pipewire', 'c' ,
3
-  version : '0.3.53',
4
+  version : '0.3.54',
5
   license :  'MIT', 'LGPL-2.1-or-later', 'GPL-2.0-only' ,
6
   meson_version : '>= 0.59.0',
7
   default_options :  'warning_level=3',
8
pipewire-0.3.53.tar.gz/pipewire-alsa/alsa-plugins/pcm_pipewire.c -> pipewire-0.3.54.tar.gz/pipewire-alsa/alsa-plugins/pcm_pipewire.c Changed
17
 
1
@@ -726,6 +726,7 @@
2
 {
3
    snd_pcm_pipewire_t *pw = io->private_data;
4
 
5
+   pw_thread_loop_lock(pw->main_loop);
6
    if (pw->stream) {
7
        snd_pcm_uframes_t min_avail;
8
        snd_pcm_sw_params_get_avail_min( sw_params, &min_avail);
9
@@ -746,6 +747,7 @@
10
    } else {
11
        pw_log_debug("%p: sw_params pre-prepare noop", pw);
12
    }
13
+   pw_thread_loop_unlock(pw->main_loop);
14
 
15
    return 0;
16
 }
17
pipewire-0.3.53.tar.gz/po/hr.po -> pipewire-0.3.54.tar.gz/po/hr.po Changed
248
 
1
@@ -7,8 +7,8 @@
2
 msgstr ""
3
 "Project-Id-Version: pipewire\n"
4
 "Report-Msgid-Bugs-To: \n"
5
-"POT-Creation-Date: 2022-04-03 12:56+0200\n"
6
-"PO-Revision-Date: 2022-04-03 12:57+0200\n"
7
+"POT-Creation-Date: 2022-06-30 12:50+0200\n"
8
+"PO-Revision-Date: 2022-06-30 13:14+0200\n"
9
 "Last-Translator: gogo <trebelnik2@gmail.com>\n"
10
 "Language-Team: Croatian <https://translate.fedoraproject.org/projects/"
11
 "pipewire/pipewire/hr/>\n"
12
@@ -34,8 +34,8 @@
13
 "      --version                         Prikaži inačicu\n"
14
 "  -c, --config                          Učitaj podešavanje (Zadano %s)\n"
15
 
16
-#: src/modules/module-protocol-pulse/modules/module-tunnel-sink.c:190
17
-#: src/modules/module-protocol-pulse/modules/module-tunnel-source.c:190
18
+#: src/modules/module-protocol-pulse/modules/module-tunnel-sink.c:180
19
+#: src/modules/module-protocol-pulse/modules/module-tunnel-source.c:180
20
 #, c-format
21
 msgid "Tunnel to %s/%s"
22
 msgstr "Tunel do %s/%s"
23
@@ -44,41 +44,41 @@
24
 msgid "Dummy Output"
25
 msgstr "Lažni izlaz"
26
 
27
-#: src/modules/module-pulse-tunnel.c:545
28
+#: src/modules/module-pulse-tunnel.c:648
29
 #, c-format
30
 msgid "Tunnel for %s@%s"
31
 msgstr "Tunel za %s@%s"
32
 
33
-#: src/modules/module-zeroconf-discover.c:313
34
+#: src/modules/module-zeroconf-discover.c:332
35
 msgid "Unknown device"
36
 msgstr "Nepoznat uređaj"
37
 
38
-#: src/modules/module-zeroconf-discover.c:325
39
+#: src/modules/module-zeroconf-discover.c:344
40
 #, c-format
41
 msgid "%s on %s@%s"
42
 msgstr "%s na %s@%s"
43
 
44
-#: src/modules/module-zeroconf-discover.c:329
45
+#: src/modules/module-zeroconf-discover.c:348
46
 #, c-format
47
 msgid "%s on %s"
48
 msgstr "%s na %s"
49
 
50
-#: src/tools/pw-cat.c:1087
51
+#: src/tools/pw-cat.c:784
52
 #, c-format
53
 msgid ""
54
-"%s options <file>\n"
55
+"%s options <file>|-\n"
56
 "  -h, --help                            Show this help\n"
57
 "      --version                         Show version\n"
58
 "  -v, --verbose                         Enable verbose operations\n"
59
 "\n"
60
 msgstr ""
61
-"%s mogućnosti <datoteka>\n"
62
+"%s mogućnosti <datoteka>|-\n"
63
 "  -h, --help                            Prikaži ovu pomoć\n"
64
 "      --version                         Prikaži inačicu\n"
65
 "  -v, --verbose                         Omogući opširnije radnje\n"
66
 "\n"
67
 
68
-#: src/tools/pw-cat.c:1094
69
+#: src/tools/pw-cat.c:791
70
 #, c-format
71
 msgid ""
72
 "  -R, --remote                          Remote daemon name\n"
73
@@ -92,7 +92,7 @@
74
 "                                          or direct samples (256)\n"
75
 "                                          the rate is the one of the source "
76
 "file\n"
77
-"      --list-targets                    List available targets for --target\n"
78
+"  -P  --properties                      Set node properties\n"
79
 "\n"
80
 msgstr ""
81
 "  -R, --remote                          Naziv udaljenog pozadinskog "
82
@@ -111,11 +111,10 @@
83
 "                                          ili izravne uzorke (256)\n"
84
 "                                          frekvencija je jednaka izvornoj "
85
 "datoteci\n"
86
-"      --list-targets                    Prikaži dostupna odredišta za --"
87
-"target\n"
88
+"  -P  --properties                      Postavi svojstva čvora\n"
89
 "\n"
90
 
91
-#: src/tools/pw-cat.c:1112
92
+#: src/tools/pw-cat.c:809
93
 #, c-format
94
 msgid ""
95
 "      --rate                            Sample rate (req. for rec) (default "
96
@@ -151,7 +150,7 @@
97
 "15) (zadano je %d)\n"
98
 "\n"
99
 
100
-#: src/tools/pw-cat.c:1129
101
+#: src/tools/pw-cat.c:826
102
 msgid ""
103
 "  -p, --playback                        Playback mode\n"
104
 "  -r, --record                          Recording mode\n"
105
@@ -165,7 +164,7 @@
106
 "  -d, --dsd                             DSD način\n"
107
 "\n"
108
 
109
-#: src/tools/pw-cli.c:3051
110
+#: src/tools/pw-cli.c:3165
111
 #, c-format
112
 msgid ""
113
 "%s options command\n"
114
@@ -188,8 +187,8 @@
115
 msgid "Pro Audio"
116
 msgstr "Pro Audio"
117
 
118
-#: spa/plugins/alsa/acp/acp.c:444 spa/plugins/alsa/acp/alsa-mixer.c:4648
119
-#: spa/plugins/bluez5/bluez5-device.c:1159
120
+#: spa/plugins/alsa/acp/acp.c:446 spa/plugins/alsa/acp/alsa-mixer.c:4648
121
+#: spa/plugins/bluez5/bluez5-device.c:1161
122
 msgid "Off"
123
 msgstr "Isključeno"
124
 
125
@@ -216,7 +215,7 @@
126
 
127
 #: spa/plugins/alsa/acp/alsa-mixer.c:2657
128
 #: spa/plugins/alsa/acp/alsa-mixer.c:2741
129
-#: spa/plugins/bluez5/bluez5-device.c:1328
130
+#: spa/plugins/bluez5/bluez5-device.c:1330
131
 msgid "Microphone"
132
 msgstr "Mikrofon"
133
 
134
@@ -282,7 +281,7 @@
135
 msgstr "Bez pojačanja basa"
136
 
137
 #: spa/plugins/alsa/acp/alsa-mixer.c:2672
138
-#: spa/plugins/bluez5/bluez5-device.c:1333
139
+#: spa/plugins/bluez5/bluez5-device.c:1335
140
 msgid "Speaker"
141
 msgstr "Zvučnik"
142
 
143
@@ -397,7 +396,7 @@
144
 
145
 #: spa/plugins/alsa/acp/alsa-mixer.c:4484
146
 #: spa/plugins/alsa/acp/alsa-mixer.c:4642
147
-#: spa/plugins/bluez5/bluez5-device.c:1318
148
+#: spa/plugins/bluez5/bluez5-device.c:1320
149
 msgid "Headset"
150
 msgstr "Slušalice s mikrofonom"
151
 
152
@@ -521,8 +520,7 @@
153
 msgid "%s Input"
154
 msgstr "%s ulaz"
155
 
156
-#: spa/plugins/alsa/acp/alsa-util.c:1173
157
-#: spa/plugins/alsa/acp/alsa-util.c:1267
158
+#: spa/plugins/alsa/acp/alsa-util.c:1173 spa/plugins/alsa/acp/alsa-util.c:1267
159
 #, c-format
160
 msgid ""
161
 "snd_pcm_avail() returned a value that is exceptionally large: %lu byte (%lu "
162
@@ -619,7 +617,7 @@
163
 "Najvjerojatnije je ovo greška ALSA upravljačkog programa '%s'. Prijavite "
164
 "problem ALSA razvijateljima."
165
 
166
-#: spa/plugins/alsa/acp/channelmap.h:464
167
+#: spa/plugins/alsa/acp/channelmap.h:457
168
 msgid "(invalid)"
169
 msgstr "(neispravno)"
170
 
171
@@ -631,62 +629,62 @@
172
 msgid "Modem"
173
 msgstr "Modem"
174
 
175
-#: spa/plugins/bluez5/bluez5-device.c:1170
176
+#: spa/plugins/bluez5/bluez5-device.c:1172
177
 msgid "Audio Gateway (A2DP Source & HSP/HFP AG)"
178
 msgstr "Zvučni pristupnik (A2DP izvor i HSP/HFP AG)"
179
 
180
-#: spa/plugins/bluez5/bluez5-device.c:1195
181
+#: spa/plugins/bluez5/bluez5-device.c:1197
182
 #, c-format
183
 msgid "High Fidelity Playback (A2DP Sink, codec %s)"
184
 msgstr "Reprodukcija visoke autentičnosti (A2DP slivnik, kôdek %s)"
185
 
186
-#: spa/plugins/bluez5/bluez5-device.c:1198
187
+#: spa/plugins/bluez5/bluez5-device.c:1200
188
 #, c-format
189
 msgid "High Fidelity Duplex (A2DP Source/Sink, codec %s)"
190
 msgstr "Telefonija visoke autentičnosti (A2DP slivnik, kôdek %s)"
191
 
192
-#: spa/plugins/bluez5/bluez5-device.c:1206
193
+#: spa/plugins/bluez5/bluez5-device.c:1208
194
 msgid "High Fidelity Playback (A2DP Sink)"
195
 msgstr "Reprodukcija visoke autentičnosti (A2DP slivnik)"
196
 
197
-#: spa/plugins/bluez5/bluez5-device.c:1208
198
+#: spa/plugins/bluez5/bluez5-device.c:1210
199
 msgid "High Fidelity Duplex (A2DP Source/Sink)"
200
 msgstr "Telefonija visoke autentičnosti (A2DP izvor/slivnik)"
201
 
202
-#: spa/plugins/bluez5/bluez5-device.c:1236
203
+#: spa/plugins/bluez5/bluez5-device.c:1238
204
 #, c-format
205
 msgid "Headset Head Unit (HSP/HFP, codec %s)"
206
 msgstr "Jedinica slušalice s mikrofonom (HSP/HFP, kôdek %s)"
207
 
208
-#: spa/plugins/bluez5/bluez5-device.c:1241
209
+#: spa/plugins/bluez5/bluez5-device.c:1243
210
 msgid "Headset Head Unit (HSP/HFP)"
211
 msgstr "Jedinica slušalice s mikrofonom (HSP/HFP)"
212
 
213
-#: spa/plugins/bluez5/bluez5-device.c:1323
214
+#: spa/plugins/bluez5/bluez5-device.c:1325
215
 msgid "Handsfree"
216
 msgstr "Bez-ruku"
217
 
218
-#: spa/plugins/bluez5/bluez5-device.c:1338
219
+#: spa/plugins/bluez5/bluez5-device.c:1340
220
 msgid "Headphone"
221
 msgstr "Slušalice"
222
 
223
-#: spa/plugins/bluez5/bluez5-device.c:1343
224
+#: spa/plugins/bluez5/bluez5-device.c:1345
225
 msgid "Portable"
226
 msgstr "Prijenosnik"
227
 
228
-#: spa/plugins/bluez5/bluez5-device.c:1348
229
+#: spa/plugins/bluez5/bluez5-device.c:1350
230
 msgid "Car"
231
 msgstr "Automobil"
232
 
233
-#: spa/plugins/bluez5/bluez5-device.c:1353
234
+#: spa/plugins/bluez5/bluez5-device.c:1355
235
 msgid "HiFi"
236
 msgstr "HiFi"
237
 
238
-#: spa/plugins/bluez5/bluez5-device.c:1358
239
+#: spa/plugins/bluez5/bluez5-device.c:1360
240
 msgid "Phone"
241
 msgstr "Telefon"
242
 
243
-#: spa/plugins/bluez5/bluez5-device.c:1364
244
+#: spa/plugins/bluez5/bluez5-device.c:1366
245
 msgid "Bluetooth"
246
 msgstr "Bluetooth"
247
 
248
pipewire-0.3.53.tar.gz/po/pipewire.pot -> pipewire-0.3.54.tar.gz/po/pipewire.pot Changed
220
 
1
@@ -8,7 +8,7 @@
2
 msgstr ""
3
 "Project-Id-Version: pipewire\n"
4
 "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/pipewire/pipewire/issues/new\n"
5
-"POT-Creation-Date: 2022-04-03 12:56+0200\n"
6
+"POT-Creation-Date: 2022-06-30 12:50+0200\n"
7
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
8
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
9
 "Language-Team: LANGUAGE <LL@li.org>\n"
10
@@ -27,8 +27,8 @@
11
 "  -c, --config                          Load config (Default %s)\n"
12
 msgstr ""
13
 
14
-#: src/modules/module-protocol-pulse/modules/module-tunnel-sink.c:190
15
-#: src/modules/module-protocol-pulse/modules/module-tunnel-source.c:190
16
+#: src/modules/module-protocol-pulse/modules/module-tunnel-sink.c:180
17
+#: src/modules/module-protocol-pulse/modules/module-tunnel-source.c:180
18
 #, c-format
19
 msgid "Tunnel to %s/%s"
20
 msgstr ""
21
@@ -37,36 +37,36 @@
22
 msgid "Dummy Output"
23
 msgstr ""
24
 
25
-#: src/modules/module-pulse-tunnel.c:545
26
+#: src/modules/module-pulse-tunnel.c:648
27
 #, c-format
28
 msgid "Tunnel for %s@%s"
29
 msgstr ""
30
 
31
-#: src/modules/module-zeroconf-discover.c:313
32
+#: src/modules/module-zeroconf-discover.c:332
33
 msgid "Unknown device"
34
 msgstr ""
35
 
36
-#: src/modules/module-zeroconf-discover.c:325
37
+#: src/modules/module-zeroconf-discover.c:344
38
 #, c-format
39
 msgid "%s on %s@%s"
40
 msgstr ""
41
 
42
-#: src/modules/module-zeroconf-discover.c:329
43
+#: src/modules/module-zeroconf-discover.c:348
44
 #, c-format
45
 msgid "%s on %s"
46
 msgstr ""
47
 
48
-#: src/tools/pw-cat.c:1087
49
+#: src/tools/pw-cat.c:784
50
 #, c-format
51
 msgid ""
52
-"%s options <file>\n"
53
+"%s options <file>|-\n"
54
 "  -h, --help                            Show this help\n"
55
 "      --version                         Show version\n"
56
 "  -v, --verbose                         Enable verbose operations\n"
57
 "\n"
58
 msgstr ""
59
 
60
-#: src/tools/pw-cat.c:1094
61
+#: src/tools/pw-cat.c:791
62
 #, c-format
63
 msgid ""
64
 "  -R, --remote                          Remote daemon name\n"
65
@@ -80,11 +80,11 @@
66
 "                                          or direct samples (256)\n"
67
 "                                          the rate is the one of the source "
68
 "file\n"
69
-"      --list-targets                    List available targets for --target\n"
70
+"  -P  --properties                      Set node properties\n"
71
 "\n"
72
 msgstr ""
73
 
74
-#: src/tools/pw-cat.c:1112
75
+#: src/tools/pw-cat.c:809
76
 #, c-format
77
 msgid ""
78
 "      --rate                            Sample rate (req. for rec) (default "
79
@@ -104,7 +104,7 @@
80
 "\n"
81
 msgstr ""
82
 
83
-#: src/tools/pw-cat.c:1129
84
+#: src/tools/pw-cat.c:826
85
 msgid ""
86
 "  -p, --playback                        Playback mode\n"
87
 "  -r, --record                          Recording mode\n"
88
@@ -113,7 +113,7 @@
89
 "\n"
90
 msgstr ""
91
 
92
-#: src/tools/pw-cli.c:3051
93
+#: src/tools/pw-cli.c:3165
94
 #, c-format
95
 msgid ""
96
 "%s options command\n"
97
@@ -128,8 +128,8 @@
98
 msgid "Pro Audio"
99
 msgstr ""
100
 
101
-#: spa/plugins/alsa/acp/acp.c:444 spa/plugins/alsa/acp/alsa-mixer.c:4648
102
-#: spa/plugins/bluez5/bluez5-device.c:1159
103
+#: spa/plugins/alsa/acp/acp.c:446 spa/plugins/alsa/acp/alsa-mixer.c:4648
104
+#: spa/plugins/bluez5/bluez5-device.c:1161
105
 msgid "Off"
106
 msgstr ""
107
 
108
@@ -156,7 +156,7 @@
109
 
110
 #: spa/plugins/alsa/acp/alsa-mixer.c:2657
111
 #: spa/plugins/alsa/acp/alsa-mixer.c:2741
112
-#: spa/plugins/bluez5/bluez5-device.c:1328
113
+#: spa/plugins/bluez5/bluez5-device.c:1330
114
 msgid "Microphone"
115
 msgstr ""
116
 
117
@@ -222,7 +222,7 @@
118
 msgstr ""
119
 
120
 #: spa/plugins/alsa/acp/alsa-mixer.c:2672
121
-#: spa/plugins/bluez5/bluez5-device.c:1333
122
+#: spa/plugins/bluez5/bluez5-device.c:1335
123
 msgid "Speaker"
124
 msgstr ""
125
 
126
@@ -337,7 +337,7 @@
127
 
128
 #: spa/plugins/alsa/acp/alsa-mixer.c:4484
129
 #: spa/plugins/alsa/acp/alsa-mixer.c:4642
130
-#: spa/plugins/bluez5/bluez5-device.c:1318
131
+#: spa/plugins/bluez5/bluez5-device.c:1320
132
 msgid "Headset"
133
 msgstr ""
134
 
135
@@ -516,7 +516,7 @@
136
 msgstr0 ""
137
 msgstr1 ""
138
 
139
-#: spa/plugins/alsa/acp/channelmap.h:464
140
+#: spa/plugins/alsa/acp/channelmap.h:457
141
 msgid "(invalid)"
142
 msgstr ""
143
 
144
@@ -528,61 +528,61 @@
145
 msgid "Modem"
146
 msgstr ""
147
 
148
-#: spa/plugins/bluez5/bluez5-device.c:1170
149
+#: spa/plugins/bluez5/bluez5-device.c:1172
150
 msgid "Audio Gateway (A2DP Source & HSP/HFP AG)"
151
 msgstr ""
152
 
153
-#: spa/plugins/bluez5/bluez5-device.c:1195
154
+#: spa/plugins/bluez5/bluez5-device.c:1197
155
 #, c-format
156
 msgid "High Fidelity Playback (A2DP Sink, codec %s)"
157
 msgstr ""
158
 
159
-#: spa/plugins/bluez5/bluez5-device.c:1198
160
+#: spa/plugins/bluez5/bluez5-device.c:1200
161
 #, c-format
162
 msgid "High Fidelity Duplex (A2DP Source/Sink, codec %s)"
163
 msgstr ""
164
 
165
-#: spa/plugins/bluez5/bluez5-device.c:1206
166
+#: spa/plugins/bluez5/bluez5-device.c:1208
167
 msgid "High Fidelity Playback (A2DP Sink)"
168
 msgstr ""
169
 
170
-#: spa/plugins/bluez5/bluez5-device.c:1208
171
+#: spa/plugins/bluez5/bluez5-device.c:1210
172
 msgid "High Fidelity Duplex (A2DP Source/Sink)"
173
 msgstr ""
174
 
175
-#: spa/plugins/bluez5/bluez5-device.c:1236
176
+#: spa/plugins/bluez5/bluez5-device.c:1238
177
 #, c-format
178
 msgid "Headset Head Unit (HSP/HFP, codec %s)"
179
 msgstr ""
180
 
181
-#: spa/plugins/bluez5/bluez5-device.c:1241
182
+#: spa/plugins/bluez5/bluez5-device.c:1243
183
 msgid "Headset Head Unit (HSP/HFP)"
184
 msgstr ""
185
 
186
-#: spa/plugins/bluez5/bluez5-device.c:1323
187
+#: spa/plugins/bluez5/bluez5-device.c:1325
188
 msgid "Handsfree"
189
 msgstr ""
190
 
191
-#: spa/plugins/bluez5/bluez5-device.c:1338
192
+#: spa/plugins/bluez5/bluez5-device.c:1340
193
 msgid "Headphone"
194
 msgstr ""
195
 
196
-#: spa/plugins/bluez5/bluez5-device.c:1343
197
+#: spa/plugins/bluez5/bluez5-device.c:1345
198
 msgid "Portable"
199
 msgstr ""
200
 
201
-#: spa/plugins/bluez5/bluez5-device.c:1348
202
+#: spa/plugins/bluez5/bluez5-device.c:1350
203
 msgid "Car"
204
 msgstr ""
205
 
206
-#: spa/plugins/bluez5/bluez5-device.c:1353
207
+#: spa/plugins/bluez5/bluez5-device.c:1355
208
 msgid "HiFi"
209
 msgstr ""
210
 
211
-#: spa/plugins/bluez5/bluez5-device.c:1358
212
+#: spa/plugins/bluez5/bluez5-device.c:1360
213
 msgid "Phone"
214
 msgstr ""
215
 
216
-#: spa/plugins/bluez5/bluez5-device.c:1364
217
+#: spa/plugins/bluez5/bluez5-device.c:1366
218
 msgid "Bluetooth"
219
 msgstr ""
220
pipewire-0.3.53.tar.gz/spa/plugins/alsa/alsa-pcm-sink.c -> pipewire-0.3.54.tar.gz/spa/plugins/alsa/alsa-pcm-sink.c Changed
9
 
1
@@ -707,6 +707,7 @@
2
        this->port_info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
3
        this->port_paramsPORT_Latency.user++;
4
        emit_port_info(this, false);
5
+       res = 0;
6
        break;
7
    }
8
    default:
9
pipewire-0.3.53.tar.gz/spa/plugins/alsa/alsa-pcm.c -> pipewire-0.3.54.tar.gz/spa/plugins/alsa/alsa-pcm.c Changed
54
 
1
@@ -752,7 +752,7 @@
2
 }
3
 
4
 static int add_rate(struct state *state, uint32_t scale, bool all, uint32_t index, uint32_t *next,
5
-       snd_pcm_hw_params_t *params, struct spa_pod_builder *b)
6
+       uint32_t min_allowed_rate, snd_pcm_hw_params_t *params, struct spa_pod_builder *b)
7
 {
8
    struct spa_pod_frame f1;
9
    int err, dir;
10
@@ -763,6 +763,9 @@
11
    CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min");
12
    CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max");
13
 
14
+   min_allowed_rate /= scale;
15
+   min = SPA_MAX(min_allowed_rate, min);
16
+
17
    if (!state->multi_rate && state->card->format_ref > 0)
18
        rate = state->card->rate;
19
    else
20
@@ -1017,7 +1020,7 @@
21
        choice->body.type = SPA_CHOICE_Enum;
22
    spa_pod_builder_pop(b, &f1);
23
 
24
-   if ((res = add_rate(state, 1, false, index & 0xffff, next, params, b)) != 1)
25
+   if ((res = add_rate(state, 1, false, index & 0xffff, next, 0, params, b)) != 1)
26
        return res;
27
 
28
    if ((res = add_channels(state, false, index & 0xffff, next, params, b)) != 1)
29
@@ -1110,7 +1113,7 @@
30
    }
31
    spa_pod_builder_pop(b, &f1);
32
 
33
-   if ((res = add_rate(state, 1, true, index & 0xffff, next, params, b)) != 1)
34
+   if ((res = add_rate(state, 1, true, index & 0xffff, next, 0, params, b)) != 1)
35
        return res;
36
 
37
    (*next)++;
38
@@ -1165,7 +1168,14 @@
39
    spa_pod_builder_prop(b, SPA_FORMAT_AUDIO_interleave, 0);
40
    spa_pod_builder_int(b, interleave);
41
 
42
-   if ((res = add_rate(state, SPA_ABS(interleave), true, index & 0xffff, next, params, b)) != 1)
43
+   /* Use a lower rate limit of 352800 (= 44100 * 64 / 8). This is because in
44
+    * PipeWire, DSD rates are given in bytes, not bits, so 352800 corresponds
45
+    * to the bit rate of DSD64. (The "64" in DSD64 means "64 times the rate
46
+    * of 44.1 kHz".) Some hardware may report rates lower than that, for example
47
+    * 176400. This would correspond to "DSD32" (which does not exist). Trying
48
+    * to use such a rate with DSD hardware does not work and may cause undefined
49
+    * behavior in said hardware. */
50
+   if ((res = add_rate(state, SPA_ABS(interleave), true, index & 0xffff, next, 44100 * 64 / 8, params, b)) != 1)
51
        return res;
52
 
53
    if ((res = add_channels(state, true, index & 0xffff, next, params, b)) != 1)
54
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/audioadapter.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/audioadapter.c Changed
25
 
1
@@ -1153,8 +1153,21 @@
2
    if (this->target != this->follower) {
3
        this->driver = true;
4
 
5
-       if (this->direction == SPA_DIRECTION_OUTPUT)
6
-           status = spa_node_process(this->convert);
7
+       if (this->direction == SPA_DIRECTION_OUTPUT) {
8
+           int retry = 8;
9
+           while (retry--) {
10
+               status = spa_node_process(this->convert);
11
+               if (status & SPA_STATUS_HAVE_DATA)
12
+                   break;
13
+
14
+               if (status & SPA_STATUS_NEED_DATA) {
15
+                   status = spa_node_process(this->follower);
16
+                   if (!(status & SPA_STATUS_HAVE_DATA))
17
+                       break;
18
+               }
19
+           }
20
+
21
+       }
22
    }
23
 
24
    return spa_node_call_ready(&this->callbacks, status);
25
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/audioconvert.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/audioconvert.c Changed
461
 
1
@@ -166,10 +166,10 @@
2
    unsigned int have_profile:1;
3
    struct spa_latency_info latency;
4
 
5
-   uint32_t src_remapMAX_PORTS;
6
-   uint32_t dst_remapMAX_PORTS;
7
+   uint32_t remapMAX_PORTS;
8
 
9
    struct convert conv;
10
+   unsigned int need_remap:1;
11
    unsigned int is_passthrough:1;
12
    unsigned int control:1;
13
 };
14
@@ -221,9 +221,7 @@
15
    uint32_t empty_size;
16
    float *empty;
17
    float *scratch;
18
-   float *tmp;
19
-   float *tmp2;
20
-
21
+   float *tmp2;
22
    float *tmp_datas2MAX_PORTS;
23
 };
24
 
25
@@ -438,21 +436,21 @@
26
            param = spa_pod_builder_add_object(&b,
27
                SPA_TYPE_OBJECT_PropInfo, id,
28
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_volume),
29
-               SPA_PROP_INFO_name, SPA_POD_String("Volume"),
30
+               SPA_PROP_INFO_description, SPA_POD_String("Volume"),
31
                SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0));
32
            break;
33
        case 1:
34
            param = spa_pod_builder_add_object(&b,
35
                SPA_TYPE_OBJECT_PropInfo, id,
36
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_mute),
37
-               SPA_PROP_INFO_name, SPA_POD_String("Mute"),
38
+               SPA_PROP_INFO_description, SPA_POD_String("Mute"),
39
                SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(p->channel.mute));
40
            break;
41
        case 2:
42
            param = spa_pod_builder_add_object(&b,
43
                SPA_TYPE_OBJECT_PropInfo, id,
44
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_channelVolumes),
45
-               SPA_PROP_INFO_name, SPA_POD_String("Channel Volumes"),
46
+               SPA_PROP_INFO_description, SPA_POD_String("Channel Volumes"),
47
                SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0),
48
                SPA_PROP_INFO_container, SPA_POD_Id(SPA_TYPE_Array));
49
            break;
50
@@ -460,7 +458,7 @@
51
            param = spa_pod_builder_add_object(&b,
52
                SPA_TYPE_OBJECT_PropInfo, id,
53
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_channelMap),
54
-               SPA_PROP_INFO_name, SPA_POD_String("Channel Map"),
55
+               SPA_PROP_INFO_description, SPA_POD_String("Channel Map"),
56
                SPA_PROP_INFO_type, SPA_POD_Id(SPA_AUDIO_CHANNEL_UNKNOWN),
57
                SPA_PROP_INFO_container, SPA_POD_Id(SPA_TYPE_Array));
58
            break;
59
@@ -468,14 +466,14 @@
60
            param = spa_pod_builder_add_object(&b,
61
                SPA_TYPE_OBJECT_PropInfo, id,
62
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_monitorMute),
63
-               SPA_PROP_INFO_name, SPA_POD_String("Monitor Mute"),
64
+               SPA_PROP_INFO_description, SPA_POD_String("Monitor Mute"),
65
                SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(p->monitor.mute));
66
            break;
67
        case 5:
68
            param = spa_pod_builder_add_object(&b,
69
                SPA_TYPE_OBJECT_PropInfo, id,
70
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_monitorVolumes),
71
-               SPA_PROP_INFO_name, SPA_POD_String("Monitor Volumes"),
72
+               SPA_PROP_INFO_description, SPA_POD_String("Monitor Volumes"),
73
                SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0),
74
                SPA_PROP_INFO_container, SPA_POD_Id(SPA_TYPE_Array));
75
            break;
76
@@ -483,14 +481,14 @@
77
            param = spa_pod_builder_add_object(&b,
78
                SPA_TYPE_OBJECT_PropInfo, id,
79
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_softMute),
80
-               SPA_PROP_INFO_name, SPA_POD_String("Soft Mute"),
81
+               SPA_PROP_INFO_description, SPA_POD_String("Soft Mute"),
82
                SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(p->soft.mute));
83
            break;
84
        case 7:
85
            param = spa_pod_builder_add_object(&b,
86
                SPA_TYPE_OBJECT_PropInfo, id,
87
                SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_softVolumes),
88
-               SPA_PROP_INFO_name, SPA_POD_String("Soft Volumes"),
89
+               SPA_PROP_INFO_description, SPA_POD_String("Soft Volumes"),
90
                SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0),
91
                SPA_PROP_INFO_container, SPA_POD_Id(SPA_TYPE_Array));
92
            break;
93
@@ -1104,6 +1102,7 @@
94
    struct dir *in = &this->dirSPA_DIRECTION_INPUT;
95
    struct spa_audio_info src_info, dst_info;
96
    int res;
97
+   bool remap = false;
98
 
99
    src_info = in->format;
100
    dst_info = src_info;
101
@@ -1125,10 +1124,11 @@
102
            if (src_info.info.raw.positioni !=
103
                dst_info.info.raw.positionj)
104
                continue;
105
-           in->src_remapi = j;
106
-           in->dst_remapj = i;
107
-           spa_log_debug(this->log, "%p: channel %d -> %d (%s -> %s)", this,
108
-                   i, j,
109
+           in->remapi = j;
110
+           if (i != j)
111
+               remap = true;
112
+           spa_log_debug(this->log, "%p: channel %d (%d) -> %d (%s -> %s)", this,
113
+                   i, in->remapi, j,
114
                    spa_debug_type_find_short_name(spa_type_audio_channel,
115
                        src_info.info.raw.positioni),
116
                    spa_debug_type_find_short_name(spa_type_audio_channel,
117
@@ -1137,17 +1137,21 @@
118
            break;
119
        }
120
    }
121
+   if (in->conv.free)
122
+       convert_free(&in->conv);
123
+
124
    in->conv.src_fmt = src_info.info.raw.format;
125
    in->conv.dst_fmt = dst_info.info.raw.format;
126
    in->conv.n_channels = dst_info.info.raw.channels;
127
    in->conv.cpu_flags = this->cpu_flags;
128
+   in->need_remap = remap;
129
 
130
    if ((res = convert_init(&in->conv)) < 0)
131
        return res;
132
 
133
-   spa_log_debug(this->log, "%p: got converter features %08x:%08x passthrough:%d %s", this,
134
+   spa_log_debug(this->log, "%p: got converter features %08x:%08x passthrough:%d remap:%d %s", this,
135
            this->cpu_flags, in->conv.cpu_flags, in->conv.is_passthrough,
136
-           in->conv.func_name);
137
+           remap, in->conv.func_name);
138
 
139
    return 0;
140
 }
141
@@ -1266,7 +1270,7 @@
142
        vol = &this->props.channel;
143
 
144
    for (i = 0; i < vol->n_volumes; i++)
145
-       volumesi = vol->volumesdir->src_remapi;
146
+       volumesi = vol->volumesdir->remapi;
147
 
148
    channelmix_set_volume(&this->mix, this->props.volume, vol->mute,
149
            vol->n_volumes, volumes);
150
@@ -1396,6 +1400,7 @@
151
    struct dir *out = &this->dirSPA_DIRECTION_OUTPUT;
152
    struct spa_audio_info src_info, dst_info;
153
    int res;
154
+   bool remap = false;
155
 
156
    dst_info = out->format;
157
    src_info = dst_info;
158
@@ -1417,10 +1422,12 @@
159
            if (src_info.info.raw.positioni !=
160
                dst_info.info.raw.positionj)
161
                continue;
162
-           out->src_remapi = j;
163
-           out->dst_remapj = i;
164
-           spa_log_debug(this->log, "%p: channel %d -> %d (%s -> %s)", this,
165
-                   i, j,
166
+           out->remapi = j;
167
+           if (i != j)
168
+               remap = true;
169
+
170
+           spa_log_debug(this->log, "%p: channel %d (%d) -> %d (%s -> %s)", this,
171
+                   i, out->remapi, j,
172
                    spa_debug_type_find_short_name(spa_type_audio_channel,
173
                        src_info.info.raw.positioni),
174
                    spa_debug_type_find_short_name(spa_type_audio_channel,
175
@@ -1429,20 +1436,23 @@
176
            break;
177
        }
178
    }
179
-   out->conv.quantize = calc_width(&dst_info) * 8;
180
+   if (out->conv.free)
181
+       convert_free(&out->conv);
182
+
183
    out->conv.src_fmt = src_info.info.raw.format;
184
    out->conv.dst_fmt = dst_info.info.raw.format;
185
    out->conv.rate = dst_info.info.raw.rate;
186
    out->conv.n_channels = dst_info.info.raw.channels;
187
    out->conv.cpu_flags = this->cpu_flags;
188
+   out->need_remap = remap;
189
 
190
    if ((res = convert_init(&out->conv)) < 0)
191
        return res;
192
 
193
-   spa_log_debug(this->log, "%p: got converter features %08x:%08x quant:%d:%d:%d passthrough:%d %s", this,
194
+   spa_log_debug(this->log, "%p: got converter features %08x:%08x quant:%d:%d"
195
+           " passthrough:%d remap:%d %s", this,
196
            this->cpu_flags, out->conv.cpu_flags, out->conv.method,
197
-           out->conv.quantize, out->conv.noise,
198
-           out->conv.is_passthrough, out->conv.func_name);
199
+           out->conv.noise, out->conv.is_passthrough, remap, out->conv.func_name);
200
 
201
    return 0;
202
 }
203
@@ -1491,9 +1501,9 @@
204
        return res;
205
 
206
    for (i = 0; i < MAX_PORTS; i++) {
207
-       this->tmp_datas0i = SPA_PTROFF(this->tmp, this->empty_size * i, void);
208
+       this->tmp_datas0i = SPA_PTROFF(this->tmp0, this->empty_size * i, void);
209
        this->tmp_datas0i = SPA_PTR_ALIGN(this->tmp_datas0i, MAX_ALIGN, void);
210
-       this->tmp_datas1i = SPA_PTROFF(this->tmp2, this->empty_size * i, void);
211
+       this->tmp_datas1i = SPA_PTROFF(this->tmp1, this->empty_size * i, void);
212
        this->tmp_datas1i = SPA_PTR_ALIGN(this->tmp_datas1i, MAX_ALIGN, void);
213
    }
214
 
215
@@ -2009,7 +2019,8 @@
216
 
217
    clear_buffers(this, port);
218
 
219
-   maxsize = 0;
220
+   maxsize = this->quantum_limit * sizeof(float);
221
+
222
    for (i = 0; i < n_buffers; i++) {
223
        struct buffer *b;
224
        uint32_t n_datas = buffersi->n_datas;
225
@@ -2050,10 +2061,10 @@
226
    if (maxsize > this->empty_size) {
227
        this->empty = realloc(this->empty, maxsize + MAX_ALIGN);
228
        this->scratch = realloc(this->scratch, maxsize + MAX_ALIGN);
229
-       this->tmp = realloc(this->tmp, (4 * maxsize + MAX_ALIGN) * MAX_PORTS);
230
-       this->tmp2 = realloc(this->tmp2, (4 * maxsize + MAX_ALIGN) * MAX_PORTS);
231
+       this->tmp0 = realloc(this->tmp0, (maxsize + MAX_ALIGN) * MAX_PORTS);
232
+       this->tmp1 = realloc(this->tmp1, (maxsize + MAX_ALIGN) * MAX_PORTS);
233
        if (this->empty == NULL || this->scratch == NULL ||
234
-           this->tmp == NULL || this->tmp2 == NULL)
235
+           this->tmp0 == NULL || this->tmp1 == NULL)
236
            return -errno;
237
        memset(this->empty, 0, maxsize + MAX_ALIGN);
238
        this->empty_size = maxsize;
239
@@ -2221,7 +2232,8 @@
240
 {
241
    struct impl *this = object;
242
    const void *src_datasMAX_PORTS, **in_datas;
243
-   void *dst_datasMAX_PORTS, **out_datas;
244
+   void *dst_datasMAX_PORTS, *remap_src_datasMAX_PORTS, *remap_dst_datasMAX_PORTS;
245
+   void **out_datas, **dst_remap;
246
    uint32_t i, j, n_src_datas = 0, n_dst_datas = 0, n_mon_datas = 0, remap;
247
    uint32_t n_samples, max_in, n_out, max_out, quant_samples;
248
    struct port *port, *ctrlport = NULL;
249
@@ -2229,14 +2241,13 @@
250
    struct spa_data *bd;
251
    struct dir *dir;
252
    int tmp = 0, res = 0;
253
-   bool in_passthrough, mix_passthrough, resample_passthrough, out_passthrough, end_passthrough;
254
+   bool in_passthrough, mix_passthrough, resample_passthrough, out_passthrough;
255
    bool in_avail = false, flush_in = false, flush_out = false, draining = false, in_empty = true;
256
    struct spa_io_buffers *io, *ctrlio = NULL;
257
    const struct spa_pod_sequence *ctrl = NULL;
258
 
259
    dir = &this->dirSPA_DIRECTION_INPUT;
260
    in_passthrough = dir->conv.is_passthrough;
261
-
262
    max_in = UINT32_MAX;
263
 
264
    /* collect input port data */
265
@@ -2255,6 +2266,7 @@
266
                spa_log_trace_fp(this->log, "%p: empty input port %d %p %d %d %d",
267
                        this, port->id, io, io->status, io->buffer_id,
268
                        port->n_buffers);
269
+               this->drained = false;
270
            }
271
            buf = NULL;
272
        } else if (SPA_UNLIKELY(io->buffer_id >= port->n_buffers)) {
273
@@ -2264,6 +2276,9 @@
274
            io->status = -EINVAL;
275
            buf = NULL;
276
        } else {
277
+           spa_log_trace_fp(this->log, "%p: input buffer port %d io:%p status:%d id:%d n:%d",
278
+                   this, port->id, io, io->status, io->buffer_id,
279
+                   port->n_buffers);
280
            buf = &port->buffersio->buffer_id;
281
        }
282
 
283
@@ -2273,7 +2288,7 @@
284
                    spa_log_trace_fp(this->log, "%p: empty control %d", this,
285
                            i * port->blocks + j);
286
                } else {
287
-                   remap = dir->src_remapn_src_datas++;
288
+                   remap = n_src_datas++;
289
                    src_datasremap = SPA_PTR_ALIGN(this->empty, MAX_ALIGN, void);
290
                    spa_log_trace_fp(this->log, "%p: empty input %d->%d", this,
291
                            i * port->blocks + j, remap);
292
@@ -2308,7 +2323,7 @@
293
                } else  {
294
                    max_in = SPA_MIN(max_in, size / port->stride);
295
 
296
-                   remap = dir->src_remapn_src_datas++;
297
+                   remap = n_src_datas++;
298
                    offs += this->in_offset * port->stride;
299
                    src_datasremap = SPA_PTROFF(bd->data, offs, void);
300
 
301
@@ -2374,8 +2389,6 @@
302
    }
303
 
304
    dir = &this->dirSPA_DIRECTION_OUTPUT;
305
-   out_passthrough = dir->conv.is_passthrough;
306
-
307
    /* collect output ports and monitor ports data */
308
    for (i = 0; i < dir->n_ports; i++) {
309
        port = GET_OUT_PORT(this, i);
310
@@ -2401,7 +2414,7 @@
311
                } else if (port->is_control) {
312
                    spa_log_trace_fp(this->log, "%p: empty control %d", this, j);
313
                } else {
314
-                   remap = dir->dst_remapn_dst_datas++;
315
+                   remap = n_dst_datas++;
316
                    dst_datasremap = SPA_PTR_ALIGN(this->scratch, MAX_ALIGN, void);
317
                    spa_log_trace_fp(this->log, "%p: empty output %d->%d", this,
318
                        i * port->blocks + j, remap);
319
@@ -2440,7 +2453,7 @@
320
                } else if (SPA_UNLIKELY(port->is_control)) {
321
                    spa_log_trace_fp(this->log, "%p: control %d", this, j);
322
                } else {
323
-                   remap = dir->dst_remapn_dst_datas++;
324
+                   remap = n_dst_datas++;
325
                    dst_datasremap = SPA_PTROFF(bd->data,
326
                            this->out_offset * port->stride, void);
327
                    max_out = SPA_MIN(max_out, bd->maxsize / port->stride);
328
@@ -2452,34 +2465,54 @@
329
            }
330
        }
331
    }
332
-
333
-   n_out = max_out - SPA_MIN(max_out, this->out_offset);
334
-
335
    mix_passthrough = SPA_FLAG_IS_SET(this->mix.flags, CHANNELMIX_FLAG_IDENTITY) &&
336
        (ctrlport == NULL || ctrlport->ctrl == NULL);
337
-   end_passthrough = mix_passthrough && resample_passthrough && out_passthrough;
338
 
339
-   if (!in_passthrough || end_passthrough) {
340
-       if (end_passthrough) {
341
-           out_datas = (void **)dst_datas;
342
-           n_samples = SPA_MIN(n_samples, n_out);
343
+   out_passthrough = dir->conv.is_passthrough;
344
+   if (in_passthrough && mix_passthrough && resample_passthrough)
345
+       out_passthrough = false;
346
+
347
+   if (out_passthrough && dir->need_remap) {
348
+       for (i = 0; i < dir->conv.n_channels; i++) {
349
+           remap_dst_datasi = dst_datasdir->remapi;
350
+           spa_log_trace_fp(this->log, "%p: output remap %d -> %d", this, i, dir->remapi);
351
        }
352
+       dst_remap = (void **)remap_dst_datas;
353
+   } else {
354
+       dst_remap = (void **)dst_datas;
355
+   }
356
+
357
+   n_out = max_out - SPA_MIN(max_out, this->out_offset);
358
+
359
+   dir = &this->dirSPA_DIRECTION_INPUT;
360
+   if (!in_passthrough) {
361
+       if (mix_passthrough && resample_passthrough && out_passthrough)
362
+           out_datas = (void **)dst_remap;
363
        else
364
            out_datas = (void **)this->tmp_datas(tmp++) & 1;
365
-       spa_log_trace_fp(this->log, "%p: convert %d %d", this, n_samples, end_passthrough);
366
-       convert_process(&this->dirSPA_DIRECTION_INPUT.conv, out_datas, src_datas, n_samples);
367
    } else {
368
        out_datas = (void **)src_datas;
369
    }
370
+   if (dir->need_remap) {
371
+       for (i = 0; i < dir->conv.n_channels; i++) {
372
+           remap_src_datasi = out_datasdir->remapi;
373
+           spa_log_trace_fp(this->log, "%p: input remap %d -> %d", this, dir->remapi, i);
374
+       }
375
+       out_datas = (void **)remap_src_datas;
376
+   }
377
+   if (!in_passthrough) {
378
+       spa_log_trace_fp(this->log, "%p: input convert %d", this, n_samples);
379
+       convert_process(&dir->conv, out_datas, src_datas, n_samples);
380
+   }
381
 
382
    if (!mix_passthrough) {
383
        in_datas = (const void**)out_datas;
384
        if (resample_passthrough && out_passthrough) {
385
-           out_datas = (void **)dst_datas;
386
+           out_datas = (void **)dst_remap;
387
            n_samples = SPA_MIN(n_samples, n_out);
388
-       }
389
-       else
390
+       } else {
391
            out_datas = (void **)this->tmp_datas(tmp++) & 1;
392
+       }
393
        spa_log_trace_fp(this->log, "%p: channelmix %d %d %d", this, n_samples,
394
                resample_passthrough, out_passthrough);
395
        if (ctrlport != NULL && ctrlport->ctrl != NULL) {
396
@@ -2492,13 +2525,12 @@
397
            channelmix_process(&this->mix, out_datas, in_datas, n_samples);
398
        }
399
    }
400
-
401
    if (!resample_passthrough) {
402
        uint32_t in_len, out_len;
403
 
404
        in_datas = (const void**)out_datas;
405
        if (out_passthrough)
406
-           out_datas = (void **)dst_datas;
407
+           out_datas = (void **)dst_remap;
408
        else
409
            out_datas = (void **)this->tmp_datas(tmp++) & 1;
410
 
411
@@ -2516,9 +2548,18 @@
412
    this->out_offset += n_samples;
413
 
414
    if (!out_passthrough) {
415
-       in_datas = (const void**)out_datas;
416
-       spa_log_trace_fp(this->log, "%p: convert %d", this, n_samples);
417
-       convert_process(&this->dirSPA_DIRECTION_OUTPUT.conv, dst_datas, in_datas, n_samples);
418
+       dir = &this->dirSPA_DIRECTION_OUTPUT;
419
+       if (dir->need_remap) {
420
+           for (i = 0; i < dir->conv.n_channels; i++) {
421
+               remap_dst_datasi = out_datasdir->remapi;
422
+               spa_log_trace_fp(this->log, "%p: output remap %d -> %d", this, i, dir->remapi);
423
+           }
424
+           in_datas = (const void**)remap_dst_datas;
425
+       } else {
426
+           in_datas = (const void**)out_datas;
427
+       }
428
+       spa_log_trace_fp(this->log, "%p: output convert %d", this, n_samples);
429
+       convert_process(&dir->conv, dst_datas, in_datas, n_samples);
430
    }
431
 
432
    spa_log_trace_fp(this->log, "%d/%d  %d/%d %d->%d", this->in_offset, max_in,
433
@@ -2534,7 +2575,8 @@
434
            if (SPA_UNLIKELY((io = port->io) == NULL))
435
                continue;
436
            spa_log_trace_fp(this->log, "return: input %d %d", port->id, io->buffer_id);
437
-           io->status = SPA_STATUS_NEED_DATA;
438
+           if (!draining)
439
+               io->status = SPA_STATUS_NEED_DATA;
440
        }
441
        this->in_offset = 0;
442
        max_in = 0;
443
@@ -2641,11 +2683,15 @@
444
        free(this->dirSPA_DIRECTION_OUTPUT.portsi);
445
    free(this->empty);
446
    free(this->scratch);
447
-   free(this->tmp);
448
-   free(this->tmp2);
449
+   free(this->tmp0);
450
+   free(this->tmp1);
451
 
452
    if (this->resample.free)
453
        resample_free(&this->resample);
454
+   if (this->dir0.conv.free)
455
+       convert_free(&this->dir0.conv);
456
+   if (this->dir1.conv.free)
457
+       convert_free(&this->dir1.conv);
458
 
459
    return 0;
460
 }
461
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/benchmark-fmt-ops.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/benchmark-fmt-ops.c Changed
28
 
1
@@ -271,18 +271,18 @@
2
 
3
 static void test_interleave(void)
4
 {
5
-   run_test("test_interleave_8", "c", false, true, conv_interleave_8_c);
6
-   run_test("test_interleave_16", "c", false, true, conv_interleave_16_c);
7
-   run_test("test_interleave_24", "c", false, true, conv_interleave_24_c);
8
-   run_test("test_interleave_32", "c", false, true, conv_interleave_32_c);
9
+   run_test("test_8d_to_8", "c", false, true, conv_8d_to_8_c);
10
+   run_test("test_16d_to_16", "c", false, true, conv_16d_to_16_c);
11
+   run_test("test_24d_to_24", "c", false, true, conv_24d_to_24_c);
12
+   run_test("test_32d_to_32", "c", false, true, conv_32d_to_32_c);
13
 }
14
 
15
 static void test_deinterleave(void)
16
 {
17
-   run_test("test_deinterleave_8", "c", true, false, conv_deinterleave_8_c);
18
-   run_test("test_deinterleave_16", "c", true, false, conv_deinterleave_16_c);
19
-   run_test("test_deinterleave_24", "c", true, false, conv_deinterleave_24_c);
20
-   run_test("test_deinterleave_32", "c", true, false, conv_deinterleave_32_c);
21
+   run_test("test_8_to_8d", "c", true, false, conv_8_to_8d_c);
22
+   run_test("test_16_to_16d", "c", true, false, conv_16_to_16d_c);
23
+   run_test("test_24_to_24d", "c", true, false, conv_24_to_24d_c);
24
+   run_test("test_32_to_32d", "c", true, false, conv_32_to_32d_c);
25
 }
26
 
27
 static int compare_func(const void *_a, const void *_b)
28
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops-avx2.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops-avx2.c Changed
557
 
1
@@ -147,7 +147,7 @@
2
 conv_s24_to_f32d_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
3
        uint32_t n_channels, uint32_t n_samples)
4
 {
5
-   const uint8_t *s = src;
6
+   const int24_t *s = src;
7
    float *d0 = dst0;
8
    uint32_t n, unrolled;
9
    __m128i in;
10
@@ -164,21 +164,21 @@
11
    for(n = 0; n < unrolled; n += 4) {
12
        in = _mm_setr_epi32(
13
            *((uint32_t*)&s0 * n_channels),
14
-           *((uint32_t*)&s3 * n_channels),
15
-           *((uint32_t*)&s6 * n_channels),
16
-           *((uint32_t*)&s9 * n_channels));
17
+           *((uint32_t*)&s1 * n_channels),
18
+           *((uint32_t*)&s2 * n_channels),
19
+           *((uint32_t*)&s3 * n_channels));
20
        in = _mm_slli_epi32(in, 8);
21
        in = _mm_srai_epi32(in, 8);
22
        out = _mm_cvtepi32_ps(in);
23
        out = _mm_mul_ps(out, factor);
24
        _mm_store_ps(&d0n, out);
25
-       s += 12 * n_channels;
26
+       s += 4 * n_channels;
27
    }
28
    for(; n < n_samples; n++) {
29
-       out = _mm_cvtsi32_ss(factor, read_s24(s));
30
+       out = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
31
        out = _mm_mul_ss(out, factor);
32
        _mm_store_ss(&d0n, out);
33
-       s += 3 * n_channels;
34
+       s += n_channels;
35
    }
36
 }
37
 
38
@@ -186,7 +186,7 @@
39
 conv_s24_to_f32d_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
40
        uint32_t n_channels, uint32_t n_samples)
41
 {
42
-   const uint8_t *s = src;
43
+   const int24_t *s = src;
44
    float *d0 = dst0, *d1 = dst1;
45
    uint32_t n, unrolled;
46
    __m128i in2;
47
@@ -205,14 +205,14 @@
48
    for(n = 0; n < unrolled; n += 4) {
49
        in0 = _mm_setr_epi32(
50
            *((uint32_t*)&s0 + 0*n_channels),
51
-           *((uint32_t*)&s0 + 3*n_channels),
52
-           *((uint32_t*)&s0 + 6*n_channels),
53
-           *((uint32_t*)&s0 + 9*n_channels));
54
+           *((uint32_t*)&s0 + 1*n_channels),
55
+           *((uint32_t*)&s0 + 2*n_channels),
56
+           *((uint32_t*)&s0 + 3*n_channels));
57
        in1 = _mm_setr_epi32(
58
-           *((uint32_t*)&s3 + 0*n_channels),
59
-           *((uint32_t*)&s3 + 3*n_channels),
60
-           *((uint32_t*)&s3 + 6*n_channels),
61
-           *((uint32_t*)&s3 + 9*n_channels));
62
+           *((uint32_t*)&s1 + 0*n_channels),
63
+           *((uint32_t*)&s1 + 1*n_channels),
64
+           *((uint32_t*)&s1 + 2*n_channels),
65
+           *((uint32_t*)&s1 + 3*n_channels));
66
 
67
        in0 = _mm_slli_epi32(in0, 8);
68
        in1 = _mm_slli_epi32(in1, 8);
69
@@ -229,23 +229,23 @@
70
        _mm_store_ps(&d0n, out0);
71
        _mm_store_ps(&d1n, out1);
72
 
73
-       s += 12 * n_channels;
74
+       s += 4 * n_channels;
75
    }
76
    for(; n < n_samples; n++) {
77
-       out0 = _mm_cvtsi32_ss(factor, read_s24(s));
78
-       out1 = _mm_cvtsi32_ss(factor, read_s24(s+3));
79
+       out0 = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
80
+       out1 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+1)));
81
        out0 = _mm_mul_ss(out0, factor);
82
        out1 = _mm_mul_ss(out1, factor);
83
        _mm_store_ss(&d0n, out0);
84
        _mm_store_ss(&d1n, out1);
85
-       s += 3 * n_channels;
86
+       s += n_channels;
87
    }
88
 }
89
 static void
90
 conv_s24_to_f32d_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
91
        uint32_t n_channels, uint32_t n_samples)
92
 {
93
-   const uint8_t *s = src;
94
+   const int24_t *s = src;
95
    float *d0 = dst0, *d1 = dst1, *d2 = dst2, *d3 = dst3;
96
    uint32_t n, unrolled;
97
    __m128i in4;
98
@@ -266,24 +266,24 @@
99
    for(n = 0; n < unrolled; n += 4) {
100
        in0 = _mm_setr_epi32(
101
            *((uint32_t*)&s0 + 0*n_channels),
102
-           *((uint32_t*)&s0 + 3*n_channels),
103
-           *((uint32_t*)&s0 + 6*n_channels),
104
-           *((uint32_t*)&s0 + 9*n_channels));
105
+           *((uint32_t*)&s0 + 1*n_channels),
106
+           *((uint32_t*)&s0 + 2*n_channels),
107
+           *((uint32_t*)&s0 + 3*n_channels));
108
        in1 = _mm_setr_epi32(
109
-           *((uint32_t*)&s3 + 0*n_channels),
110
-           *((uint32_t*)&s3 + 3*n_channels),
111
-           *((uint32_t*)&s3 + 6*n_channels),
112
-           *((uint32_t*)&s3 + 9*n_channels));
113
+           *((uint32_t*)&s1 + 0*n_channels),
114
+           *((uint32_t*)&s1 + 1*n_channels),
115
+           *((uint32_t*)&s1 + 2*n_channels),
116
+           *((uint32_t*)&s1 + 3*n_channels));
117
        in2 = _mm_setr_epi32(
118
-           *((uint32_t*)&s6 + 0*n_channels),
119
-           *((uint32_t*)&s6 + 3*n_channels),
120
-           *((uint32_t*)&s6 + 6*n_channels),
121
-           *((uint32_t*)&s6 + 9*n_channels));
122
+           *((uint32_t*)&s2 + 0*n_channels),
123
+           *((uint32_t*)&s2 + 1*n_channels),
124
+           *((uint32_t*)&s2 + 2*n_channels),
125
+           *((uint32_t*)&s2 + 3*n_channels));
126
        in3 = _mm_setr_epi32(
127
-           *((uint32_t*)&s9 + 0*n_channels),
128
-           *((uint32_t*)&s9 + 3*n_channels),
129
-           *((uint32_t*)&s9 + 6*n_channels),
130
-           *((uint32_t*)&s9 + 9*n_channels));
131
+           *((uint32_t*)&s3 + 0*n_channels),
132
+           *((uint32_t*)&s3 + 1*n_channels),
133
+           *((uint32_t*)&s3 + 2*n_channels),
134
+           *((uint32_t*)&s3 + 3*n_channels));
135
 
136
        in0 = _mm_slli_epi32(in0, 8);
137
        in1 = _mm_slli_epi32(in1, 8);
138
@@ -310,13 +310,13 @@
139
        _mm_store_ps(&d2n, out2);
140
        _mm_store_ps(&d3n, out3);
141
 
142
-       s += 12 * n_channels;
143
+       s += 4 * n_channels;
144
    }
145
    for(; n < n_samples; n++) {
146
-       out0 = _mm_cvtsi32_ss(factor, read_s24(s));
147
-       out1 = _mm_cvtsi32_ss(factor, read_s24(s+3));
148
-       out2 = _mm_cvtsi32_ss(factor, read_s24(s+6));
149
-       out3 = _mm_cvtsi32_ss(factor, read_s24(s+9));
150
+       out0 = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
151
+       out1 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+1)));
152
+       out2 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+2)));
153
+       out3 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+3)));
154
        out0 = _mm_mul_ss(out0, factor);
155
        out1 = _mm_mul_ss(out1, factor);
156
        out2 = _mm_mul_ss(out2, factor);
157
@@ -325,7 +325,7 @@
158
        _mm_store_ss(&d1n, out1);
159
        _mm_store_ss(&d2n, out2);
160
        _mm_store_ss(&d3n, out3);
161
-       s += 3 * n_channels;
162
+       s += n_channels;
163
    }
164
 }
165
 
166
@@ -353,7 +353,7 @@
167
    float *d0 = dst0, *d1 = dst1, *d2 = dst2, *d3 = dst3;
168
    uint32_t n, unrolled;
169
    __m256i in4, t4;
170
-   __m256 out4, factor = _mm256_set1_ps(1.0f / S24_SCALE);
171
+   __m256 out4, factor = _mm256_set1_ps(1.0f / S32_SCALE);
172
    __m256i mask1 = _mm256_setr_epi64x(0*n_channels, 0*n_channels+2, 4*n_channels, 4*n_channels+2);
173
    __m256i mask2 = _mm256_setr_epi64x(1*n_channels, 1*n_channels+2, 5*n_channels, 5*n_channels+2);
174
    __m256i mask3 = _mm256_setr_epi64x(2*n_channels, 2*n_channels+2, 6*n_channels, 6*n_channels+2);
175
@@ -373,11 +373,6 @@
176
        in2 = _mm256_i64gather_epi64((long long int *)&s0*n_channels, mask3, 4);
177
        in3 = _mm256_i64gather_epi64((long long int *)&s0*n_channels, mask4, 4);
178
 
179
-       in0 = _mm256_srai_epi32(in0, 8); /* a0 b0 c0 d0 a4 b4 c4 d4 */
180
-       in1 = _mm256_srai_epi32(in1, 8); /* a1 b1 c1 d1 a5 b5 c5 d5 */
181
-       in2 = _mm256_srai_epi32(in2, 8); /* a2 b2 c2 d2 a6 b6 c6 d6 */
182
-       in3 = _mm256_srai_epi32(in3, 8); /* a3 b3 c3 d3 a7 b7 c7 d7 */
183
-
184
        t0 = _mm256_unpacklo_epi32(in0, in1);   /* a0 a1 b0 b1 a4 a5 b4 b5 */
185
        t1 = _mm256_unpackhi_epi32(in0, in1);   /* c0 c1 d0 d1 c4 c5 d4 d5 */
186
        t2 = _mm256_unpacklo_epi32(in2, in3);   /* a2 a3 b2 b3 a6 a7 b6 b7 */
187
@@ -405,11 +400,11 @@
188
        s += 8*n_channels;
189
    }
190
    for(; n < n_samples; n++) {
191
-       __m128 out4, factor = _mm_set1_ps(1.0f / S24_SCALE);
192
-       out0 = _mm_cvtsi32_ss(factor, s0>>8);
193
-       out1 = _mm_cvtsi32_ss(factor, s1>>8);
194
-       out2 = _mm_cvtsi32_ss(factor, s2>>8);
195
-       out3 = _mm_cvtsi32_ss(factor, s3>>8);
196
+       __m128 out4, factor = _mm_set1_ps(1.0f / S32_SCALE);
197
+       out0 = _mm_cvtsi32_ss(factor, s0);
198
+       out1 = _mm_cvtsi32_ss(factor, s1);
199
+       out2 = _mm_cvtsi32_ss(factor, s2);
200
+       out3 = _mm_cvtsi32_ss(factor, s3);
201
        out0 = _mm_mul_ss(out0, factor);
202
        out1 = _mm_mul_ss(out1, factor);
203
        out2 = _mm_mul_ss(out2, factor);
204
@@ -430,7 +425,7 @@
205
    float *d0 = dst0, *d1 = dst1;
206
    uint32_t n, unrolled;
207
    __m256i in4, t4;
208
-   __m256 out4, factor = _mm256_set1_ps(1.0f / S24_SCALE);
209
+   __m256 out4, factor = _mm256_set1_ps(1.0f / S32_SCALE);
210
    __m256i perm = _mm256_setr_epi32(0, 2, 4, 6, 1, 3, 5, 7);
211
    __m256i mask1 = _mm256_setr_epi64x(0*n_channels, 1*n_channels, 2*n_channels, 3*n_channels);
212
    __m256i mask2 = _mm256_setr_epi64x(4*n_channels, 5*n_channels, 6*n_channels, 7*n_channels);
213
@@ -445,9 +440,6 @@
214
        in0 = _mm256_i64gather_epi64((long long int *)s, mask1, 4);
215
        in1 = _mm256_i64gather_epi64((long long int *)s, mask2, 4);
216
 
217
-       in0 = _mm256_srai_epi32(in0, 8);
218
-       in1 = _mm256_srai_epi32(in1, 8);
219
-
220
        t0 = _mm256_permutevar8x32_epi32(in0, perm);
221
        t1 = _mm256_permutevar8x32_epi32(in1, perm);
222
 
223
@@ -466,9 +458,9 @@
224
        s += 8*n_channels;
225
    }
226
    for(; n < n_samples; n++) {
227
-       __m128 out2, factor = _mm_set1_ps(1.0f / S24_SCALE);
228
-       out0 = _mm_cvtsi32_ss(factor, s0>>8);
229
-       out1 = _mm_cvtsi32_ss(factor, s1>>8);
230
+       __m128 out2, factor = _mm_set1_ps(1.0f / S32_SCALE);
231
+       out0 = _mm_cvtsi32_ss(factor, s0);
232
+       out1 = _mm_cvtsi32_ss(factor, s1);
233
        out0 = _mm_mul_ss(out0, factor);
234
        out1 = _mm_mul_ss(out1, factor);
235
        _mm_store_ss(&d0n, out0);
236
@@ -485,7 +477,7 @@
237
    float *d0 = dst0;
238
    uint32_t n, unrolled;
239
    __m256i in2;
240
-   __m256 out2, factor = _mm256_set1_ps(1.0f / S24_SCALE);
241
+   __m256 out2, factor = _mm256_set1_ps(1.0f / S32_SCALE);
242
    __m256i mask1 = _mm256_setr_epi64x(0*n_channels, 1*n_channels, 2*n_channels, 3*n_channels);
243
    __m256i mask2 = _mm256_setr_epi64x(4*n_channels, 5*n_channels, 6*n_channels, 7*n_channels);
244
 
245
@@ -502,9 +494,6 @@
246
                _mm256_i64gather_epi32(&s 8*n_channels, mask1, 4),
247
                _mm256_i64gather_epi32(&s 8*n_channels, mask2, 4));
248
 
249
-       in0 = _mm256_srai_epi32(in0, 8);
250
-       in1 = _mm256_srai_epi32(in1, 8);
251
-
252
        out0 = _mm256_cvtepi32_ps(in0);
253
        out1 = _mm256_cvtepi32_ps(in1);
254
 
255
@@ -517,8 +506,8 @@
256
        s += 16*n_channels;
257
    }
258
    for(; n < n_samples; n++) {
259
-       __m128 out, factor = _mm_set1_ps(1.0f / S24_SCALE);
260
-       out = _mm_cvtsi32_ss(factor, s0>>8);
261
+       __m128 out, factor = _mm_set1_ps(1.0f / S32_SCALE);
262
+       out = _mm_cvtsi32_ss(factor, s0);
263
        out = _mm_mul_ss(out, factor);
264
        _mm_store_ss(&d0n, out);
265
        s += n_channels;
266
@@ -560,7 +549,7 @@
267
    for(n = 0; n < unrolled; n += 4) {
268
        in0 = _mm_mul_ps(_mm_load_ps(&s0n), scale);
269
        in0 = _mm_min_ps(in0, int_max);
270
-       out0 = _mm_cvtps_epi32(in0);
271
+       out0 = _mm_cvttps_epi32(in0);
272
        out1 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(0, 3, 2, 1));
273
        out2 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(1, 0, 3, 2));
274
        out3 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(2, 1, 0, 3));
275
@@ -605,8 +594,8 @@
276
        in0 = _mm256_min_ps(in0, int_max);
277
        in1 = _mm256_min_ps(in1, int_max);
278
 
279
-       out0 = _mm256_cvtps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
280
-       out1 = _mm256_cvtps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
281
+       out0 = _mm256_cvttps_epi32(in0);    /* a0 a1 a2 a3 a4 a5 a6 a7 */
282
+       out1 = _mm256_cvttps_epi32(in1);    /* b0 b1 b2 b3 b4 b5 b6 b7 */
283
 
284
        t0 = _mm256_unpacklo_epi32(out0, out1); /* a0 b0 a1 b1 a4 b4 a5 b5 */
285
        t1 = _mm256_unpackhi_epi32(out0, out1); /* a2 b2 a3 b3 a6 b6 a7 b7 */
286
@@ -645,7 +634,7 @@
287
 
288
        in0 = _mm_mul_ps(in0, scale);
289
        in0 = _mm_min_ps(in0, int_max);
290
-       out0 = _mm_cvtps_epi32(in0);
291
+       out0 = _mm_cvttps_epi32(in0);
292
        _mm_storel_epi64((__m128i*)d, out0);
293
        d += n_channels;
294
    }
295
@@ -682,10 +671,10 @@
296
        in2 = _mm256_min_ps(in2, int_max);
297
        in3 = _mm256_min_ps(in3, int_max);
298
 
299
-       out0 = _mm256_cvtps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
300
-       out1 = _mm256_cvtps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
301
-       out2 = _mm256_cvtps_epi32(in2); /* c0 c1 c2 c3 c4 c5 c6 c7 */
302
-       out3 = _mm256_cvtps_epi32(in3); /* d0 d1 d2 d3 d4 d5 d6 d7 */
303
+       out0 = _mm256_cvttps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
304
+       out1 = _mm256_cvttps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
305
+       out2 = _mm256_cvttps_epi32(in2); /* c0 c1 c2 c3 c4 c5 c6 c7 */
306
+       out3 = _mm256_cvttps_epi32(in3); /* d0 d1 d2 d3 d4 d5 d6 d7 */
307
 
308
        t0 = _mm256_unpacklo_epi32(out0, out1); /* a0 b0 a1 b1 a4 b4 a5 b5 */
309
        t1 = _mm256_unpackhi_epi32(out0, out1); /* a2 b2 a3 b3 a6 b6 a7 b7 */
310
@@ -724,7 +713,7 @@
311
 
312
        in0 = _mm_mul_ps(in0, scale);
313
        in0 = _mm_min_ps(in0, int_max);
314
-       out0 = _mm_cvtps_epi32(in0);
315
+       out0 = _mm_cvttps_epi32(in0);
316
        _mm_storeu_si128((__m128i*)d, out0);
317
        d += n_channels;
318
    }
319
@@ -754,8 +743,9 @@
320
    uint32_t n, unrolled;
321
    __m128 in2;
322
    __m128i out2;
323
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
324
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
325
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
326
+   __m128 int_max = _mm_set1_ps(S16_MAX);
327
+   __m128 int_min = _mm_set1_ps(S16_MIN);
328
 
329
    if (SPA_IS_ALIGNED(s0, 16))
330
        unrolled = n_samples & ~7;
331
@@ -763,10 +753,10 @@
332
        unrolled = 0;
333
 
334
    for(n = 0; n < unrolled; n += 8) {
335
-       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_max);
336
-       in1 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_max);
337
-       out0 = _mm_cvtps_epi32(in0);
338
-       out1 = _mm_cvtps_epi32(in1);
339
+       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_scale);
340
+       in1 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_scale);
341
+       out0 = _mm_cvttps_epi32(in0);
342
+       out1 = _mm_cvttps_epi32(in1);
343
        out0 = _mm_packs_epi32(out0, out1);
344
 
345
        d0*n_channels = _mm_extract_epi16(out0, 0);
346
@@ -780,7 +770,7 @@
347
        d += 8*n_channels;
348
    }
349
    for(; n < n_samples; n++) {
350
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
351
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
352
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
353
        *d = _mm_cvtss_si32(in0);
354
        d += n_channels;
355
@@ -796,7 +786,7 @@
356
    uint32_t n, unrolled;
357
    __m256 in2;
358
    __m256i out4, t2;
359
-   __m256 int_max = _mm256_set1_ps(S16_MAX_F);
360
+   __m256 int_scale = _mm256_set1_ps(S16_SCALE);
361
 
362
    if (SPA_IS_ALIGNED(s0, 32) &&
363
        SPA_IS_ALIGNED(s1, 32))
364
@@ -805,11 +795,11 @@
365
        unrolled = 0;
366
 
367
    for(n = 0; n < unrolled; n += 8) {
368
-       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n+0), int_max);
369
-       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n+0), int_max);
370
+       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n+0), int_scale);
371
+       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n+0), int_scale);
372
 
373
-       out0 = _mm256_cvtps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
374
-       out1 = _mm256_cvtps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
375
+       out0 = _mm256_cvttps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
376
+       out1 = _mm256_cvttps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
377
 
378
        t0 = _mm256_unpacklo_epi32(out0, out1); /* a0 b0 a1 b1 a4 b4 a5 b5 */
379
        t1 = _mm256_unpackhi_epi32(out0, out1); /* a2 b2 a3 b3 a6 b6 a7 b7 */
380
@@ -829,11 +819,12 @@
381
    }
382
    for(; n < n_samples; n++) {
383
        __m128 in2;
384
-       __m128 int_max = _mm_set1_ps(S16_MAX_F);
385
-           __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
386
+       __m128 int_scale = _mm_set1_ps(S16_SCALE);
387
+       __m128 int_max = _mm_set1_ps(S16_MAX);
388
+       __m128 int_min = _mm_set1_ps(S16_MIN);
389
 
390
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
391
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
392
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
393
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
394
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
395
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
396
        d0 = _mm_cvtss_si32(in0);
397
@@ -851,7 +842,7 @@
398
    uint32_t n, unrolled;
399
    __m256 in4;
400
    __m256i out4, t4;
401
-   __m256 int_max = _mm256_set1_ps(S16_MAX_F);
402
+   __m256 int_scale = _mm256_set1_ps(S16_SCALE);
403
 
404
    if (SPA_IS_ALIGNED(s0, 32) &&
405
        SPA_IS_ALIGNED(s1, 32) &&
406
@@ -862,15 +853,15 @@
407
        unrolled = 0;
408
 
409
    for(n = 0; n < unrolled; n += 8) {
410
-       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n), int_max);
411
-       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n), int_max);
412
-       in2 = _mm256_mul_ps(_mm256_load_ps(&s2n), int_max);
413
-       in3 = _mm256_mul_ps(_mm256_load_ps(&s3n), int_max);
414
+       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n), int_scale);
415
+       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n), int_scale);
416
+       in2 = _mm256_mul_ps(_mm256_load_ps(&s2n), int_scale);
417
+       in3 = _mm256_mul_ps(_mm256_load_ps(&s3n), int_scale);
418
 
419
-       t0 = _mm256_cvtps_epi32(in0);  /* a0 a1 a2 a3 a4 a5 a6 a7 */
420
-       t1 = _mm256_cvtps_epi32(in1);  /* b0 b1 b2 b3 b4 b5 b6 b7 */
421
-       t2 = _mm256_cvtps_epi32(in2);  /* c0 c1 c2 c3 c4 c5 c6 c7 */
422
-       t3 = _mm256_cvtps_epi32(in3);  /* d0 d1 d2 d3 d4 d5 d6 d7 */
423
+       t0 = _mm256_cvttps_epi32(in0);  /* a0 a1 a2 a3 a4 a5 a6 a7 */
424
+       t1 = _mm256_cvttps_epi32(in1);  /* b0 b1 b2 b3 b4 b5 b6 b7 */
425
+       t2 = _mm256_cvttps_epi32(in2);  /* c0 c1 c2 c3 c4 c5 c6 c7 */
426
+       t3 = _mm256_cvttps_epi32(in3);  /* d0 d1 d2 d3 d4 d5 d6 d7 */
427
 
428
        t0 = _mm256_packs_epi32(t0, t2); /* a0 a1 a2 a3 c0 c1 c2 c3 a4 a5 a6 a7 c4 c5 c6 c7 */
429
        t1 = _mm256_packs_epi32(t1, t3); /* b0 b1 b2 b3 d0 d1 d2 d3 b4 b5 b6 b7 d4 d5 d6 d7 */
430
@@ -905,13 +896,14 @@
431
    }
432
    for(; n < n_samples; n++) {
433
        __m128 in4;
434
-       __m128 int_max = _mm_set1_ps(S16_MAX_F);
435
-           __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
436
-
437
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
438
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
439
-       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_max);
440
-       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_max);
441
+       __m128 int_scale = _mm_set1_ps(S16_SCALE);
442
+       __m128 int_max = _mm_set1_ps(S16_MAX);
443
+       __m128 int_min = _mm_set1_ps(S16_MIN);
444
+
445
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
446
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
447
+       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_scale);
448
+       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_scale);
449
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
450
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
451
        in2 = _mm_min_ss(int_max, _mm_max_ss(in2, int_min));
452
@@ -948,7 +940,7 @@
453
    uint32_t n, unrolled;
454
    __m256 in4;
455
    __m256i out4, t4;
456
-   __m256 int_max = _mm256_set1_ps(S16_MAX_F);
457
+   __m256 int_scale = _mm256_set1_ps(S16_SCALE);
458
 
459
    if (SPA_IS_ALIGNED(s0, 32) &&
460
        SPA_IS_ALIGNED(s1, 32) &&
461
@@ -959,15 +951,15 @@
462
        unrolled = 0;
463
 
464
    for(n = 0; n < unrolled; n += 8) {
465
-       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n), int_max);
466
-       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n), int_max);
467
-       in2 = _mm256_mul_ps(_mm256_load_ps(&s2n), int_max);
468
-       in3 = _mm256_mul_ps(_mm256_load_ps(&s3n), int_max);
469
+       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n), int_scale);
470
+       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n), int_scale);
471
+       in2 = _mm256_mul_ps(_mm256_load_ps(&s2n), int_scale);
472
+       in3 = _mm256_mul_ps(_mm256_load_ps(&s3n), int_scale);
473
 
474
-       t0 = _mm256_cvtps_epi32(in0);  /* a0 a1 a2 a3 a4 a5 a6 a7 */
475
-       t1 = _mm256_cvtps_epi32(in1);  /* b0 b1 b2 b3 b4 b5 b6 b7 */
476
-       t2 = _mm256_cvtps_epi32(in2);  /* c0 c1 c2 c3 c4 c5 c6 c7 */
477
-       t3 = _mm256_cvtps_epi32(in3);  /* d0 d1 d2 d3 d4 d5 d6 d7 */
478
+       t0 = _mm256_cvttps_epi32(in0);  /* a0 a1 a2 a3 a4 a5 a6 a7 */
479
+       t1 = _mm256_cvttps_epi32(in1);  /* b0 b1 b2 b3 b4 b5 b6 b7 */
480
+       t2 = _mm256_cvttps_epi32(in2);  /* c0 c1 c2 c3 c4 c5 c6 c7 */
481
+       t3 = _mm256_cvttps_epi32(in3);  /* d0 d1 d2 d3 d4 d5 d6 d7 */
482
 
483
        t0 = _mm256_packs_epi32(t0, t2); /* a0 a1 a2 a3 c0 c1 c2 c3 a4 a5 a6 a7 c4 c5 c6 c7 */
484
        t1 = _mm256_packs_epi32(t1, t3); /* b0 b1 b2 b3 d0 d1 d2 d3 b4 b5 b6 b7 d4 d5 d6 d7 */
485
@@ -987,13 +979,14 @@
486
    }
487
    for(; n < n_samples; n++) {
488
        __m128 in4;
489
-       __m128 int_max = _mm_set1_ps(S16_MAX_F);
490
-           __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
491
-
492
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
493
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
494
-       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_max);
495
-       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_max);
496
+       __m128 int_scale = _mm_set1_ps(S16_SCALE);
497
+       __m128 int_max = _mm_set1_ps(S16_MAX);
498
+       __m128 int_min = _mm_set1_ps(S16_MIN);
499
+
500
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
501
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
502
+       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_scale);
503
+       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_scale);
504
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
505
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
506
        in2 = _mm_min_ss(int_max, _mm_max_ss(in2, int_min));
507
@@ -1014,7 +1007,7 @@
508
    uint32_t n, unrolled;
509
    __m256 in4;
510
    __m256i out4, t4;
511
-   __m256 int_max = _mm256_set1_ps(S16_MAX_F);
512
+   __m256 int_scale = _mm256_set1_ps(S16_SCALE);
513
 
514
    if (SPA_IS_ALIGNED(s0, 32) &&
515
        SPA_IS_ALIGNED(s1, 32))
516
@@ -1023,15 +1016,15 @@
517
        unrolled = 0;
518
 
519
    for(n = 0; n < unrolled; n += 16) {
520
-       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n+0), int_max);
521
-       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n+0), int_max);
522
-       in2 = _mm256_mul_ps(_mm256_load_ps(&s0n+8), int_max);
523
-       in3 = _mm256_mul_ps(_mm256_load_ps(&s1n+8), int_max);
524
+       in0 = _mm256_mul_ps(_mm256_load_ps(&s0n+0), int_scale);
525
+       in1 = _mm256_mul_ps(_mm256_load_ps(&s1n+0), int_scale);
526
+       in2 = _mm256_mul_ps(_mm256_load_ps(&s0n+8), int_scale);
527
+       in3 = _mm256_mul_ps(_mm256_load_ps(&s1n+8), int_scale);
528
 
529
-       out0 = _mm256_cvtps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
530
-       out1 = _mm256_cvtps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
531
-       out2 = _mm256_cvtps_epi32(in2); /* a0 a1 a2 a3 a4 a5 a6 a7 */
532
-       out3 = _mm256_cvtps_epi32(in3); /* b0 b1 b2 b3 b4 b5 b6 b7 */
533
+       out0 = _mm256_cvttps_epi32(in0); /* a0 a1 a2 a3 a4 a5 a6 a7 */
534
+       out1 = _mm256_cvttps_epi32(in1); /* b0 b1 b2 b3 b4 b5 b6 b7 */
535
+       out2 = _mm256_cvttps_epi32(in2); /* a0 a1 a2 a3 a4 a5 a6 a7 */
536
+       out3 = _mm256_cvttps_epi32(in3); /* b0 b1 b2 b3 b4 b5 b6 b7 */
537
 
538
        t0 = _mm256_unpacklo_epi32(out0, out1); /* a0 b0 a1 b1 a4 b4 a5 b5 */
539
        t1 = _mm256_unpackhi_epi32(out0, out1); /* a2 b2 a3 b3 a6 b6 a7 b7 */
540
@@ -1048,11 +1041,12 @@
541
    }
542
    for(; n < n_samples; n++) {
543
        __m128 in4;
544
-       __m128 int_max = _mm_set1_ps(S16_MAX_F);
545
-       __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
546
+       __m128 int_scale = _mm_set1_ps(S16_SCALE);
547
+       __m128 int_max = _mm_set1_ps(S16_MAX);
548
+       __m128 int_min = _mm_set1_ps(S16_MIN);
549
 
550
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
551
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
552
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
553
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
554
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
555
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
556
        d0 = _mm_cvtss_si32(in0);
557
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops-c.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops-c.c Changed
2334
 
1
@@ -33,708 +33,196 @@
2
 #include "fmt-ops.h"
3
 #include "law.h"
4
 
5
-void
6
-conv_copy8d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
7
-       uint32_t n_samples)
8
-{
9
-   uint32_t i, n_channels = conv->n_channels;
10
-   for (i = 0; i < n_channels; i++)
11
-       spa_memcpy(dsti, srci, n_samples);
12
-}
13
-
14
-void
15
-conv_copy8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
16
-       uint32_t n_samples)
17
-{
18
-   spa_memcpy(dst0, src0, n_samples * conv->n_channels);
19
-}
20
-
21
-
22
-void
23
-conv_copy16d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
24
-       uint32_t n_samples)
25
-{
26
-   uint32_t i, n_channels = conv->n_channels;
27
-   for (i = 0; i < n_channels; i++)
28
-       spa_memcpy(dsti, srci, n_samples * sizeof(int16_t));
29
-}
30
-
31
-void
32
-conv_copy16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
33
-       uint32_t n_samples)
34
-{
35
-   spa_memcpy(dst0, src0, n_samples * sizeof(int16_t) * conv->n_channels);
36
-}
37
-
38
-void
39
-conv_copy24d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
40
-       uint32_t n_samples)
41
-{
42
-   uint32_t i, n_channels = conv->n_channels;
43
-   for (i = 0; i < n_channels; i++)
44
-       spa_memcpy(dsti, srci, n_samples * 3);
45
-}
46
-
47
-void
48
-conv_copy24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
49
-       uint32_t n_samples)
50
-{
51
-   spa_memcpy(dst0, src0, n_samples * 3 * conv->n_channels);
52
-}
53
-
54
-void
55
-conv_copy32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
56
-       uint32_t n_samples)
57
-{
58
-   uint32_t i, n_channels = conv->n_channels;
59
-   for (i = 0; i < n_channels; i++)
60
-       spa_memcpy(dsti, srci, n_samples * sizeof(int32_t));
61
-}
62
-
63
-void
64
-conv_copy32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
65
-       uint32_t n_samples)
66
-{
67
-   spa_memcpy(dst0, src0, n_samples * sizeof(int32_t) * conv->n_channels);
68
-}
69
-
70
-void
71
-conv_copy64d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
72
-       uint32_t n_samples)
73
-{
74
-   uint32_t i, n_channels = conv->n_channels;
75
-   for (i = 0; i < n_channels; i++)
76
-       spa_memcpy(dsti, srci, n_samples * sizeof(int64_t));
77
-}
78
-
79
-void
80
-conv_copy64_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
81
-       uint32_t n_samples)
82
-{
83
-   spa_memcpy(dst0, src0, n_samples * sizeof(int64_t) * conv->n_channels);
84
-}
85
-
86
-void
87
-conv_u8d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
88
-       uint32_t n_samples)
89
-{
90
-   uint32_t i, j, n_channels = conv->n_channels;
91
-
92
-   for (i = 0; i < n_channels; i++) {
93
-       const uint8_t *s = srci;
94
-       float *d = dsti;
95
-
96
-       for (j = 0; j < n_samples; j++)
97
-           dj = U8_TO_F32(sj);
98
-   }
99
-}
100
-
101
-void
102
-conv_u8_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
103
-       uint32_t n_samples)
104
-{
105
-   uint32_t i, n_channels = conv->n_channels;
106
-   const uint8_t *s = src0;
107
-   float *d = dst0;
108
-
109
-   n_samples *= n_channels;
110
-
111
-   for (i = 0; i < n_samples; i++)
112
-       di = U8_TO_F32(si);
113
-}
114
-
115
-void
116
-conv_u8_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
117
-       uint32_t n_samples)
118
-{
119
-   const uint8_t *s = src0;
120
-   float **d = (float **) dst;
121
-   uint32_t i, j, n_channels = conv->n_channels;
122
-
123
-   for (j = 0; j < n_samples; j++) {
124
-       for (i = 0; i < n_channels; i++)
125
-           dij = U8_TO_F32(*s++);
126
-   }
127
-}
128
-
129
-void
130
-conv_u8d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
131
-       uint32_t n_samples)
132
-{
133
-   const uint8_t **s = (const uint8_t **) src;
134
-   float *d = dst0;
135
-   uint32_t i, j, n_channels = conv->n_channels;
136
-
137
-   for (j = 0; j < n_samples; j++) {
138
-       for (i = 0; i < n_channels; i++)
139
-           *d++ = U8_TO_F32(sij);
140
-   }
141
-}
142
-
143
-void
144
-conv_s8d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
145
-       uint32_t n_samples)
146
-{
147
-   uint32_t i, j, n_channels = conv->n_channels;
148
-
149
-   for (i = 0; i < n_channels; i++) {
150
-       const int8_t *s = srci;
151
-       float *d = dsti;
152
-       for (j = 0; j < n_samples; j++)
153
-           dj = S8_TO_F32(sj);
154
-   }
155
-}
156
-
157
-void
158
-conv_s8_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
159
-       uint32_t n_samples)
160
-{
161
-   uint32_t i, n_channels = conv->n_channels;
162
-   const int8_t *s = src0;
163
-   float *d = dst0;
164
-
165
-   n_samples *= n_channels;
166
-
167
-   for (i = 0; i < n_samples; i++)
168
-       di = S8_TO_F32(si);
169
-}
170
-
171
-void
172
-conv_s8_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
173
-       uint32_t n_samples)
174
-{
175
-   const int8_t *s = src0;
176
-   float **d = (float **) dst;
177
-   uint32_t i, j, n_channels = conv->n_channels;
178
-
179
-   for (j = 0; j < n_samples; j++) {
180
-       for (i = 0; i < n_channels; i++)
181
-           dij = S8_TO_F32(*s++);
182
-   }
183
-}
184
-
185
-void
186
-conv_s8d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
187
-       uint32_t n_samples)
188
-{
189
-   const int8_t **s = (const int8_t **) src;
190
-   float *d = dst0;
191
-   uint32_t i, j, n_channels = conv->n_channels;
192
-
193
-   for (j = 0; j < n_samples; j++) {
194
-       for (i = 0; i < n_channels; i++)
195
-           *d++ = S8_TO_F32(sij);
196
-   }
197
-}
198
-
199
-void
200
-conv_alaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
201
-       uint32_t n_samples)
202
-{
203
-   const uint8_t *s = src0;
204
-   float **d = (float **) dst;
205
-   uint32_t i, j, n_channels = conv->n_channels;
206
-
207
-   for (j = 0; j < n_samples; j++) {
208
-       for (i = 0; i < n_channels; i++)
209
-           dij = alaw_to_f32(*s++);
210
-   }
211
-}
212
-
213
-void
214
-conv_ulaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
215
-       uint32_t n_samples)
216
-{
217
-   const uint8_t *s = src0;
218
-   float **d = (float **) dst;
219
-   uint32_t i, j, n_channels = conv->n_channels;
220
-
221
-   for (j = 0; j < n_samples; j++) {
222
-       for (i = 0; i < n_channels; i++)
223
-           dij = ulaw_to_f32(*s++);
224
-   }
225
-}
226
-
227
-void
228
-conv_u16_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
229
-       uint32_t n_samples)
230
-{
231
-   uint32_t i, n_channels = conv->n_channels;
232
-   const uint16_t *s = src0;
233
-   float *d = dst0;
234
-
235
-   n_samples *= n_channels;
236
-
237
-   for (i = 0; i < n_samples; i++)
238
-       di = U16_TO_F32(si);
239
-}
240
-
241
-void
242
-conv_u16_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
243
-       uint32_t n_samples)
244
-{
245
-   const uint16_t *s = src0;
246
-   float **d = (float **) dst;
247
-   uint32_t i, j, n_channels = conv->n_channels;
248
-
249
-   for (j = 0; j < n_samples; j++) {
250
-       for (i = 0; i < n_channels; i++)
251
-           dij = U16_TO_F32(*s++);
252
-   }
253
-}
254
-
255
-void
256
-conv_s16d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
257
-       uint32_t n_samples)
258
-{
259
-   uint32_t i, j, n_channels = conv->n_channels;
260
-
261
-   for (i = 0; i < n_channels; i++) {
262
-       const int16_t *s = srci;
263
-       float *d = dsti;
264
-       for (j = 0; j < n_samples; j++)
265
-           dj = S16_TO_F32(sj);
266
-   }
267
-}
268
-
269
-void
270
-conv_s16_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
271
-       uint32_t n_samples)
272
-{
273
-   uint32_t i, n_channels = conv->n_channels;
274
-   const int16_t *s = src0;
275
-   float *d = dst0;
276
-
277
-   n_samples *= n_channels;
278
-
279
-   for (i = 0; i < n_samples; i++)
280
-       di = S16_TO_F32(si);
281
-}
282
-
283
-void
284
-conv_s16_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
285
-       uint32_t n_samples)
286
-{
287
-   const int16_t *s = src0;
288
-   float **d = (float **) dst;
289
-   uint32_t i, j, n_channels = conv->n_channels;
290
-
291
-   for (j = 0; j < n_samples; j++) {
292
-       for (i = 0; i < n_channels; i++)
293
-           dij = S16_TO_F32(*s++);
294
-   }
295
-}
296
-
297
-void
298
-conv_s16s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
299
-       uint32_t n_samples)
300
-{
301
-   const int16_t *s = src0;
302
-   float **d = (float **) dst;
303
-   uint32_t i, j, n_channels = conv->n_channels;
304
-
305
-   for (j = 0; j < n_samples; j++) {
306
-       for (i = 0; i < n_channels; i++)
307
-           dij = S16S_TO_F32(*s++);
308
-   }
309
-}
310
-
311
-void
312
-conv_s16d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
313
-       uint32_t n_samples)
314
-{
315
-   const int16_t **s = (const int16_t **) src;
316
-   float *d = dst0;
317
-   uint32_t i, j, n_channels = conv->n_channels;
318
-
319
-   for (j = 0; j < n_samples; j++) {
320
-       for (i = 0; i < n_channels; i++)
321
-           *d++ = S16_TO_F32(sij);
322
-   }
323
-}
324
-
325
-void
326
-conv_u32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
327
-       uint32_t n_samples)
328
-{
329
-   uint32_t i, n_channels = conv->n_channels;
330
-   const uint32_t *s = src0;
331
-   float *d = dst0;
332
-
333
-   n_samples *= n_channels;
334
-
335
-   for (i = 0; i < n_samples; i++)
336
-       di = U32_TO_F32(si);
337
-}
338
-
339
-void
340
-conv_u32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
341
-       uint32_t n_samples)
342
-{
343
-   const uint32_t *s = src0;
344
-   float **d = (float **) dst;
345
-   uint32_t i, j, n_channels = conv->n_channels;
346
-
347
-   for (j = 0; j < n_samples; j++) {
348
-       for (i = 0; i < n_channels; i++)
349
-           dij = U32_TO_F32(*s++);
350
-   }
351
-}
352
-
353
-void
354
-conv_s32d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
355
-       uint32_t n_samples)
356
-{
357
-   uint32_t i, j, n_channels = conv->n_channels;
358
-
359
-   for (i = 0; i < n_channels; i++) {
360
-       const int32_t *s = srci;
361
-       float *d = dsti;
362
-
363
-       for (j = 0; j < n_samples; j++)
364
-           dj = S32_TO_F32(sj);
365
-   }
366
-}
367
-
368
-void
369
-conv_s32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
370
-       uint32_t n_samples)
371
-{
372
-   uint32_t i, n_channels = conv->n_channels;
373
-   const int32_t *s = src0;
374
-   float *d = dst0;
375
-
376
-   n_samples *= n_channels;
377
-
378
-   for (i = 0; i < n_samples; i++)
379
-       di = S32_TO_F32(si);
380
-}
381
-
382
-void
383
-conv_s32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
384
-       uint32_t n_samples)
385
-{
386
-   const int32_t *s = src0;
387
-   float **d = (float **) dst;
388
-   uint32_t i, j, n_channels = conv->n_channels;
389
-
390
-   for (j = 0; j < n_samples; j++) {
391
-       for (i = 0; i < n_channels; i++)
392
-           dij = S32_TO_F32(*s++);
393
-   }
394
-}
395
-
396
-void
397
-conv_s32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
398
-       uint32_t n_samples)
399
-{
400
-   const int32_t *s = src0;
401
-   float **d = (float **) dst;
402
-   uint32_t i, j, n_channels = conv->n_channels;
403
+#define MAKE_COPY(size)                                \
404
+void conv_copy ##size## d_c(struct convert *conv,              \
405
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
406
+       uint32_t n_samples)                     \
407
+{                                      \
408
+   uint32_t i, n_channels = conv->n_channels;              \
409
+   for (i = 0; i < n_channels; i++)                    \
410
+       spa_memcpy(dsti, srci, n_samples * (size>>3));      \
411
+}                                      \
412
+void conv_copy ##size## _c(struct convert *conv,               \
413
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
414
+       uint32_t n_samples)                     \
415
+{                                      \
416
+   spa_memcpy(dst0, src0, n_samples * conv->n_channels * (size>>3));   \
417
+}
418
+
419
+MAKE_COPY(8);
420
+MAKE_COPY(16);
421
+MAKE_COPY(24);
422
+MAKE_COPY(32);
423
+MAKE_COPY(64);
424
+
425
+#define MAKE_D_TO_D(sname,stype,dname,dtype,func)              \
426
+void conv_ ##sname## d_to_ ##dname## d_c(struct convert *conv,         \
427
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
428
+                uint32_t n_samples)                        \
429
+{                                      \
430
+   uint32_t i, j, n_channels = conv->n_channels;               \
431
+   for (i = 0; i < n_channels; i++) {                  \
432
+       const stype *s = srci;                  \
433
+       dtype *d = dsti;                        \
434
+       for (j = 0; j < n_samples; j++)                 \
435
+           dj = func (sj);                 \
436
+   }                                   \
437
+}
438
+
439
+#define MAKE_I_TO_I(sname,stype,dname,dtype,func)              \
440
+void conv_ ##sname## _to_ ##dname## _c(struct convert *conv,           \
441
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
442
+                uint32_t n_samples)                        \
443
+{                                      \
444
+   uint32_t j;                             \
445
+   const stype *s = src0;                      \
446
+   dtype *d = dst0;                            \
447
+   n_samples *= conv->n_channels;                      \
448
+   for (j = 0; j < n_samples; j++)                     \
449
+       dj = func (sj);                     \
450
+}
451
+
452
+#define MAKE_I_TO_D(sname,stype,dname,dtype,func)              \
453
+void conv_ ##sname## _to_ ##dname## d_c(struct convert *conv,          \
454
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
455
+                uint32_t n_samples)                        \
456
+{                                      \
457
+   const stype *s = src0;                      \
458
+   dtype **d = (dtype**)dst;                       \
459
+   uint32_t i, j, n_channels = conv->n_channels;               \
460
+   for (j = 0; j < n_samples; j++) {                   \
461
+       for (i = 0; i < n_channels; i++)                \
462
+           dij = func (*s++);                  \
463
+   }                                   \
464
+}
465
+
466
+#define MAKE_D_TO_I(sname,stype,dname,dtype,func)              \
467
+void conv_ ##sname## d_to_ ##dname## _c(struct convert *conv,          \
468
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
469
+                uint32_t n_samples)                        \
470
+{                                      \
471
+   const stype **s = (const stype **)src;                  \
472
+   dtype *d = dst0;                            \
473
+   uint32_t i, j, n_channels = conv->n_channels;               \
474
+   for (j = 0; j < n_samples; j++) {                   \
475
+       for (i = 0; i < n_channels; i++)                \
476
+           *d++ = func (sij);                  \
477
+   }                                   \
478
+}
479
+
480
+/* to f32 */
481
+MAKE_D_TO_D(u8, uint8_t, f32, float, U8_TO_F32);
482
+MAKE_I_TO_I(u8, uint8_t, f32, float, U8_TO_F32);
483
+MAKE_I_TO_D(u8, uint8_t, f32, float, U8_TO_F32);
484
+MAKE_D_TO_I(u8, uint8_t, f32, float, U8_TO_F32);
485
+
486
+MAKE_D_TO_D(s8, int8_t, f32, float, S8_TO_F32);
487
+MAKE_I_TO_I(s8, int8_t, f32, float, S8_TO_F32);
488
+MAKE_I_TO_D(s8, int8_t, f32, float, S8_TO_F32);
489
+MAKE_D_TO_I(s8, int8_t, f32, float, S8_TO_F32);
490
+
491
+MAKE_I_TO_D(alaw, uint8_t, f32, float, alaw_to_f32);
492
+MAKE_I_TO_D(ulaw, uint8_t, f32, float, ulaw_to_f32);
493
+
494
+MAKE_I_TO_I(u16, uint16_t, f32, float, U16_TO_F32);
495
+MAKE_I_TO_D(u16, uint16_t, f32, float, U16_TO_F32);
496
+
497
+MAKE_D_TO_D(s16, int16_t, f32, float, S16_TO_F32);
498
+MAKE_I_TO_I(s16, int16_t, f32, float, S16_TO_F32);
499
+MAKE_I_TO_D(s16, int16_t, f32, float, S16_TO_F32);
500
+MAKE_D_TO_I(s16, int16_t, f32, float, S16_TO_F32);
501
+MAKE_I_TO_D(s16s, uint16_t, f32, float, S16S_TO_F32);
502
+
503
+MAKE_I_TO_I(u32, uint32_t, f32, float, U32_TO_F32);
504
+MAKE_I_TO_D(u32, uint32_t, f32, float, U32_TO_F32);
505
+
506
+MAKE_D_TO_D(s32, int32_t, f32, float, S32_TO_F32);
507
+MAKE_I_TO_I(s32, int32_t, f32, float, S32_TO_F32);
508
+MAKE_I_TO_D(s32, int32_t, f32, float, S32_TO_F32);
509
+MAKE_D_TO_I(s32, int32_t, f32, float, S32_TO_F32);
510
+MAKE_I_TO_D(s32s, uint32_t, f32, float, S32S_TO_F32);
511
+
512
+MAKE_I_TO_I(u24, uint24_t, f32, float, U24_TO_F32);
513
+MAKE_I_TO_D(u24, uint24_t, f32, float, U24_TO_F32);
514
+
515
+MAKE_D_TO_D(s24, int24_t, f32, float, S24_TO_F32);
516
+MAKE_I_TO_I(s24, int24_t, f32, float, S24_TO_F32);
517
+MAKE_I_TO_D(s24, int24_t, f32, float, S24_TO_F32);
518
+MAKE_D_TO_I(s24, int24_t, f32, float, S24_TO_F32);
519
+MAKE_I_TO_D(s24s, int24_t, f32, float, S24S_TO_F32);
520
+
521
+MAKE_I_TO_I(u24_32, uint32_t, f32, float, U24_32_TO_F32);
522
+MAKE_I_TO_D(u24_32, uint32_t, f32, float, U24_32_TO_F32);
523
+
524
+MAKE_D_TO_D(s24_32, int32_t, f32, float, S24_32_TO_F32);
525
+MAKE_I_TO_I(s24_32, int32_t, f32, float, S24_32_TO_F32);
526
+MAKE_I_TO_D(s24_32, int32_t, f32, float, S24_32_TO_F32);
527
+MAKE_D_TO_I(s24_32, int32_t, f32, float, S24_32_TO_F32);
528
+MAKE_I_TO_D(s24_32s, uint32_t, f32, float, S24_32S_TO_F32);
529
+
530
+MAKE_D_TO_D(f64, double, f32, float, (float));
531
+MAKE_I_TO_I(f64, double, f32, float, (float));
532
+MAKE_I_TO_D(f64, double, f32, float, (float));
533
+MAKE_D_TO_I(f64, double, f32, float, (float));
534
+MAKE_I_TO_D(f64s, double, f32, float, bswap_64); /* FIXME */
535
+
536
+
537
+/* from f32 */
538
+MAKE_D_TO_D(f32, float, u8, uint8_t, F32_TO_U8);
539
+MAKE_I_TO_I(f32, float, u8, uint8_t, F32_TO_U8);
540
+MAKE_I_TO_D(f32, float, u8, uint8_t, F32_TO_U8);
541
+MAKE_D_TO_I(f32, float, u8, uint8_t, F32_TO_U8);
542
+
543
+MAKE_D_TO_D(f32, float, s8, int8_t, F32_TO_S8);
544
+MAKE_I_TO_I(f32, float, s8, int8_t, F32_TO_S8);
545
+MAKE_I_TO_D(f32, float, s8, int8_t, F32_TO_S8);
546
+MAKE_D_TO_I(f32, float, s8, int8_t, F32_TO_S8);
547
+
548
+MAKE_D_TO_I(f32, float, alaw, uint8_t, f32_to_alaw);
549
+MAKE_D_TO_I(f32, float, ulaw, uint8_t, f32_to_ulaw);
550
+
551
+MAKE_I_TO_I(f32, float, u16, uint16_t, F32_TO_U16);
552
+MAKE_D_TO_I(f32, float, u16, uint16_t, F32_TO_U16);
553
+
554
+MAKE_D_TO_D(f32, float, s16, int16_t, F32_TO_S16);
555
+MAKE_I_TO_I(f32, float, s16, int16_t, F32_TO_S16);
556
+MAKE_I_TO_D(f32, float, s16, int16_t, F32_TO_S16);
557
+MAKE_D_TO_I(f32, float, s16, int16_t, F32_TO_S16);
558
+MAKE_D_TO_I(f32, float, s16s, uint16_t, F32_TO_S16S);
559
+
560
+MAKE_I_TO_I(f32, float, u32, uint32_t, F32_TO_U32);
561
+MAKE_D_TO_I(f32, float, u32, uint32_t, F32_TO_U32);
562
+
563
+MAKE_D_TO_D(f32, float, s32, int32_t, F32_TO_S32);
564
+MAKE_I_TO_I(f32, float, s32, int32_t, F32_TO_S32);
565
+MAKE_I_TO_D(f32, float, s32, int32_t, F32_TO_S32);
566
+MAKE_D_TO_I(f32, float, s32, int32_t, F32_TO_S32);
567
+MAKE_D_TO_I(f32, float, s32s, uint32_t, F32_TO_S32S);
568
+
569
+MAKE_I_TO_I(f32, float, u24, uint24_t, F32_TO_U24);
570
+MAKE_D_TO_I(f32, float, u24, uint24_t, F32_TO_U24);
571
+
572
+MAKE_D_TO_D(f32, float, s24, int24_t, F32_TO_S24);
573
+MAKE_I_TO_I(f32, float, s24, int24_t, F32_TO_S24);
574
+MAKE_I_TO_D(f32, float, s24, int24_t, F32_TO_S24);
575
+MAKE_D_TO_I(f32, float, s24, int24_t, F32_TO_S24);
576
+MAKE_D_TO_I(f32, float, s24s, int24_t, F32_TO_S24S);
577
+
578
+MAKE_I_TO_I(f32, float, u24_32, uint32_t, F32_TO_U24_32);
579
+MAKE_D_TO_I(f32, float, u24_32, uint32_t, F32_TO_U24_32);
580
+
581
+MAKE_D_TO_D(f32, float, s24_32, int32_t, F32_TO_S24_32);
582
+MAKE_I_TO_I(f32, float, s24_32, int32_t, F32_TO_S24_32);
583
+MAKE_I_TO_D(f32, float, s24_32, int32_t, F32_TO_S24_32);
584
+MAKE_D_TO_I(f32, float, s24_32, int32_t, F32_TO_S24_32);
585
+MAKE_D_TO_I(f32, float, s24_32s, uint32_t, F32_TO_S24_32S);
586
+
587
+MAKE_D_TO_D(f32, float, f64, double, (double));
588
+MAKE_I_TO_I(f32, float, f64, double, (double));
589
+MAKE_I_TO_D(f32, float, f64, double, (double));
590
+MAKE_D_TO_I(f32, float, f64, double, (double));
591
+MAKE_D_TO_I(f32, float, f64s, double, bswap_32); /* FIXME */
592
 
593
-   for (j = 0; j < n_samples; j++) {
594
-       for (i = 0; i < n_channels; i++)
595
-           dij = S32S_TO_F32(*s++);
596
-   }
597
-}
598
-
599
-void
600
-conv_s32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
601
-       uint32_t n_samples)
602
-{
603
-   const int32_t **s = (const int32_t **) src;
604
-   float *d = dst0;
605
-   uint32_t i, j, n_channels = conv->n_channels;
606
-
607
-   for (j = 0; j < n_samples; j++) {
608
-       for (i = 0; i < n_channels; i++)
609
-           *d++ = S32_TO_F32(sij);
610
-   }
611
-}
612
-
613
-void
614
-conv_u24_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
615
-       uint32_t n_samples)
616
-{
617
-   uint32_t i, n_channels = conv->n_channels;
618
-   const uint8_t *s = src0;
619
-   float *d = dst0;
620
-
621
-   n_samples *= n_channels;
622
-
623
-   for (i = 0; i < n_samples; i++) {
624
-       di = U24_TO_F32(read_u24(s));
625
-       s += 3;
626
-   }
627
-}
628
-
629
-void
630
-conv_u24_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
631
-       uint32_t n_samples)
632
-{
633
-   const uint8_t *s = src0;
634
-   float **d = (float **) dst;
635
-   uint32_t i, j, n_channels = conv->n_channels;
636
-
637
-   for (j = 0; j < n_samples; j++) {
638
-       for (i = 0; i < n_channels; i++) {
639
-           dij = U24_TO_F32(read_u24(s));
640
-           s += 3;
641
-       }
642
-   }
643
-}
644
-
645
-void
646
-conv_s24d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
647
-       uint32_t n_samples)
648
-{
649
-   uint32_t i, j, n_channels = conv->n_channels;
650
-
651
-   for (i = 0; i < n_channels; i++) {
652
-       const int8_t *s = srci;
653
-       float *d = dsti;
654
-
655
-       for (j = 0; j < n_samples; j++) {
656
-           dj = S24_TO_F32(read_s24(s));
657
-           s += 3;
658
-       }
659
-   }
660
-}
661
-
662
-void
663
-conv_s24_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
664
-       uint32_t n_samples)
665
-{
666
-   uint32_t i, n_channels = conv->n_channels;
667
-   const int8_t *s = src0;
668
-   float *d = dst0;
669
-
670
-   n_samples *= n_channels;
671
-
672
-   for (i = 0; i < n_samples; i++) {
673
-       di = S24_TO_F32(read_s24(s));
674
-       s += 3;
675
-   }
676
-}
677
-
678
-void
679
-conv_s24_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
680
-       uint32_t n_samples)
681
-{
682
-   const uint8_t *s = src0;
683
-   float **d = (float **) dst;
684
-   uint32_t i, j, n_channels = conv->n_channels;
685
-
686
-   for (j = 0; j < n_samples; j++) {
687
-       for (i = 0; i < n_channels; i++) {
688
-           dij = S24_TO_F32(read_s24(s));
689
-           s += 3;
690
-       }
691
-   }
692
-}
693
-
694
-void
695
-conv_s24s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
696
-       uint32_t n_samples)
697
-{
698
-   const uint8_t *s = src0;
699
-   float **d = (float **) dst;
700
-   uint32_t i, j, n_channels = conv->n_channels;
701
-
702
-   for (j = 0; j < n_samples; j++) {
703
-       for (i = 0; i < n_channels; i++) {
704
-           dij = S24_TO_F32(read_s24s(s));
705
-           s += 3;
706
-       }
707
-   }
708
-}
709
-
710
-void
711
-conv_s24d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
712
-       uint32_t n_samples)
713
-{
714
-   const uint8_t **s = (const uint8_t **) src;
715
-   float *d = dst0;
716
-   uint32_t i, j, n_channels = conv->n_channels;
717
-
718
-   for (j = 0; j < n_samples; j++) {
719
-       for (i = 0; i < n_channels; i++) {
720
-           *d++ = S24_TO_F32(read_s24(&sij*3));
721
-       }
722
-   }
723
-}
724
-
725
-void
726
-conv_u24_32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
727
-       uint32_t n_samples)
728
-{
729
-   uint32_t i, n_channels = conv->n_channels;
730
-   const uint32_t *s = src0;
731
-   float *d = dst0;
732
-
733
-   n_samples *= n_channels;
734
-
735
-   for (i = 0; i < n_samples; i++) {
736
-       di = U24_32_TO_F32(si);
737
-   }
738
-}
739
-
740
-void
741
-conv_u24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
742
-       uint32_t n_samples)
743
-{
744
-   const uint32_t *s = src0;
745
-   float **d = (float **) dst;
746
-   uint32_t i, j, n_channels = conv->n_channels;
747
-
748
-   for (j = 0; j < n_samples; j++) {
749
-       for (i = 0; i < n_channels; i++)
750
-           dij = U24_32_TO_F32(*s++);
751
-   }
752
-}
753
-
754
-void
755
-conv_s24_32d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
756
-       uint32_t n_samples)
757
-{
758
-   uint32_t i, j, n_channels = conv->n_channels;
759
-
760
-   for (i = 0; i < n_channels; i++) {
761
-       const int32_t *s = srci;
762
-       float *d = dsti;
763
-
764
-       for (j = 0; j < n_samples; j++)
765
-           dj = S24_32_TO_F32(sj);
766
-   }
767
-}
768
-
769
-void
770
-conv_s24_32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
771
-       uint32_t n_samples)
772
-{
773
-   uint32_t i, n_channels = conv->n_channels;
774
-   const int32_t *s = src0;
775
-   float *d = dst0;
776
-
777
-   n_samples *= n_channels;
778
-
779
-   for (i = 0; i < n_samples; i++) {
780
-       di = S24_32_TO_F32(si);
781
-   }
782
-}
783
-
784
-void
785
-conv_s24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
786
-       uint32_t n_samples)
787
-{
788
-   const int32_t *s = src0;
789
-   float **d = (float **) dst;
790
-   uint32_t i, j, n_channels = conv->n_channels;
791
-
792
-   for (j = 0; j < n_samples; j++) {
793
-       for (i = 0; i < n_channels; i++)
794
-           dij = S24_32_TO_F32(*s++);
795
-   }
796
-}
797
-
798
-void
799
-conv_s24_32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
800
-       uint32_t n_samples)
801
-{
802
-   const int32_t *s = src0;
803
-   float **d = (float **) dst;
804
-   uint32_t i, j, n_channels = conv->n_channels;
805
-
806
-   for (j = 0; j < n_samples; j++) {
807
-       for (i = 0; i < n_channels; i++)
808
-           dij = S24_32S_TO_F32(*s++);
809
-   }
810
-}
811
-
812
-void
813
-conv_s24_32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
814
-       uint32_t n_samples)
815
-{
816
-   const int32_t **s = (const int32_t **) src;
817
-   float *d = dst0;
818
-   uint32_t i, j, n_channels = conv->n_channels;
819
-
820
-   for (j = 0; j < n_samples; j++) {
821
-       for (i = 0; i < n_channels; i++)
822
-           *d++ = S24_32_TO_F32(sij);
823
-   }
824
-}
825
-
826
-void
827
-conv_f64d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
828
-       uint32_t n_samples)
829
-{
830
-   uint32_t i, j, n_channels = conv->n_channels;
831
-
832
-   for (i = 0; i < n_channels; i++) {
833
-       const double *s = srci;
834
-       float *d = dsti;
835
-
836
-       for (j = 0; j < n_samples; j++)
837
-           dj = sj;
838
-   }
839
-}
840
-
841
-void
842
-conv_f64_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
843
-       uint32_t n_samples)
844
-{
845
-   uint32_t i, n_channels = conv->n_channels;
846
-   const double *s = src0;
847
-   float *d = dst0;
848
-
849
-   n_samples *= n_channels;
850
-
851
-   for (i = 0; i < n_samples; i++)
852
-       di = si;
853
-}
854
-
855
-void
856
-conv_f64_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
857
-       uint32_t n_samples)
858
-{
859
-   const double *s = src0;
860
-   float **d = (float **) dst;
861
-   uint32_t i, j, n_channels = conv->n_channels;
862
-
863
-   for (j = 0; j < n_samples; j++) {
864
-       for (i = 0; i < n_channels; i++)
865
-           dij = *s++;
866
-   }
867
-}
868
-
869
-void
870
-conv_f64s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
871
-       uint32_t n_samples)
872
-{
873
-   const double *s = src0;
874
-   float **d = (float **) dst;
875
-   uint32_t i, j, n_channels = conv->n_channels;
876
-
877
-   for (j = 0; j < n_samples; j++) {
878
-       for (i = 0; i < n_channels; i++)
879
-           dij = bswap_64(*s++);
880
-   }
881
-}
882
-
883
-void
884
-conv_f64d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
885
-       uint32_t n_samples)
886
-{
887
-   const double **s = (const double **) src;
888
-   float *d = dst0;
889
-   uint32_t i, j, n_channels = conv->n_channels;
890
-
891
-   for (j = 0; j < n_samples; j++) {
892
-       for (i = 0; i < n_channels; i++)
893
-           *d++ = sij;
894
-   }
895
-}
896
 
897
 static inline int32_t
898
 lcnoise(uint32_t *state)
899
@@ -753,6 +241,62 @@
900
        dithern = lcnoise(state) * scale;
901
 }
902
 
903
+#define MAKE_D_dither(dname,dtype,func)                    \
904
+void conv_f32d_to_ ##dname## d_dither_c(struct convert *conv,          \
905
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
906
+                uint32_t n_samples)                        \
907
+{                                      \
908
+   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;    \
909
+   float *dither = conv->dither;                       \
910
+   update_dither_c(conv, SPA_MIN(n_samples, dither_size));         \
911
+   for (i = 0; i < n_channels; i++) {                  \
912
+       const float *s = srci;                  \
913
+       dtype *d = dsti;                        \
914
+       for (j = 0; j < n_samples;) {                   \
915
+           chunk = SPA_MIN(n_samples - j, dither_size);        \
916
+           for (k = 0; k < chunk; k++, j++)            \
917
+               dj = func (sj, ditherk);            \
918
+       }                               \
919
+   }                                   \
920
+}
921
+
922
+#define MAKE_I_dither(dname,dtype,func)                    \
923
+void conv_f32d_to_ ##dname## _dither_c(struct convert *conv,           \
924
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
925
+                uint32_t n_samples)                        \
926
+{                                      \
927
+   const float **s = (const float **) src;                 \
928
+   dtype *d = dst0;                            \
929
+   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;    \
930
+   float *dither = conv->dither;                       \
931
+   update_dither_c(conv, SPA_MIN(n_samples, dither_size));         \
932
+   for (j = 0; j < n_samples;) {                       \
933
+       chunk = SPA_MIN(n_samples - j, dither_size);            \
934
+       for (k = 0; k < chunk; k++, j++) {              \
935
+           for (i = 0; i < n_channels; i++)            \
936
+               *d++ = func (sij, ditherk);     \
937
+       }                               \
938
+   }                                   \
939
+}
940
+
941
+MAKE_D_dither(u8, uint8_t, F32_TO_U8_D);
942
+MAKE_I_dither(u8, uint8_t, F32_TO_U8_D);
943
+MAKE_D_dither(s8, int8_t, F32_TO_S8_D);
944
+MAKE_I_dither(s8, int8_t, F32_TO_S8_D);
945
+MAKE_D_dither(s16, int16_t, F32_TO_S16_D);
946
+MAKE_I_dither(s16, int16_t, F32_TO_S16_D);
947
+MAKE_I_dither(s16s, uint16_t, F32_TO_S16S_D);
948
+MAKE_D_dither(s32, int32_t, F32_TO_S32_D);
949
+MAKE_I_dither(s32, int32_t, F32_TO_S32_D);
950
+MAKE_I_dither(s32s, uint32_t, F32_TO_S32S_D);
951
+MAKE_D_dither(s24, int24_t, F32_TO_S24_D);
952
+MAKE_I_dither(s24, int24_t, F32_TO_S24_D);
953
+MAKE_I_dither(s24s, int24_t, F32_TO_S24_D);
954
+MAKE_D_dither(s24_32, int32_t, F32_TO_S24_32_D);
955
+MAKE_I_dither(s24_32, int32_t, F32_TO_S24_32_D);
956
+MAKE_I_dither(s24_32s, int32_t, F32_TO_S24_32S_D);
957
+
958
+
959
 #define SHAPER5(type,s,scale,offs,sh,min,max,d)            \
960
 ({                             \
961
    type t;                         \
962
@@ -773,1299 +317,75 @@
963
 #define F32_TO_S16_SH(s,sh,d)  SHAPER5(int16_t, s, S16_SCALE, 0, sh, S16_MIN, S16_MAX, d)
964
 #define F32_TO_S16S_SH(s,sh,d) bswap_16(F32_TO_S16_SH(s,sh,d))
965
 
966
-void
967
-conv_f32d_to_u8d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
968
-       uint32_t n_samples)
969
-{
970
-   uint32_t i, j, n_channels = conv->n_channels;
971
-
972
-   for (i = 0; i < n_channels; i++) {
973
-       const float *s = srci;
974
-       uint8_t *d = dsti;
975
-
976
-       for (j = 0; j < n_samples; j++)
977
-           dj = F32_TO_U8(sj);
978
-   }
979
-}
980
-
981
-void
982
-conv_f32d_to_u8d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
983
-       uint32_t n_samples)
984
-{
985
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
986
-   float *dither = conv->dither;
987
-
988
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
989
-
990
-   for (i = 0; i < n_channels; i++) {
991
-       const float *s = srci;
992
-       uint8_t *d = dsti;
993
-
994
-       for (j = 0; j < n_samples;) {
995
-           chunk = SPA_MIN(n_samples - j, dither_size);
996
-           for (k = 0; k < chunk; k++, j++)
997
-               dj = F32_TO_U8_D(sj, ditherk);
998
-       }
999
-   }
1000
-}
1001
-
1002
-void
1003
-conv_f32d_to_u8d_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1004
-       uint32_t n_samples)
1005
-{
1006
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1007
-   float *dither = conv->dither;
1008
-
1009
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1010
-
1011
-   for (i = 0; i < n_channels; i++) {
1012
-       const float *s = srci;
1013
-       uint8_t *d = dsti;
1014
-       struct shaper *sh = &conv->shaperi;
1015
-       uint32_t idx = sh->idx;
1016
-
1017
-       for (j = 0; j < n_samples;) {
1018
-           chunk = SPA_MIN(n_samples - j, dither_size);
1019
-           for (k = 0; k < chunk; k++, j++)
1020
-               dj = F32_TO_U8_SH(sj, sh, ditherk);
1021
-       }
1022
-       sh->idx = idx;
1023
-   }
1024
-}
1025
-
1026
-void
1027
-conv_f32_to_u8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1028
-       uint32_t n_samples)
1029
-{
1030
-   uint32_t i, n_channels = conv->n_channels;
1031
-   const float *s = src0;
1032
-   uint8_t *d = dst0;
1033
-
1034
-   n_samples *= n_channels;
1035
-
1036
-   for (i = 0; i < n_samples; i++)
1037
-       di = F32_TO_U8(si);
1038
-}
1039
-
1040
-void
1041
-conv_f32_to_u8d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1042
-       uint32_t n_samples)
1043
-{
1044
-   const float *s = src0;
1045
-   uint8_t **d = (uint8_t **) dst;
1046
-   uint32_t i, j, n_channels = conv->n_channels;
1047
-
1048
-   for (j = 0; j < n_samples; j++) {
1049
-       for (i = 0; i < n_channels; i++)
1050
-           dij = F32_TO_U8(*s++);
1051
-   }
1052
-}
1053
-
1054
-void
1055
-conv_f32d_to_u8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1056
-       uint32_t n_samples)
1057
-{
1058
-   const float **s = (const float **) src;
1059
-   uint8_t *d = dst0;
1060
-   uint32_t i, j, n_channels = conv->n_channels;
1061
-
1062
-   for (j = 0; j < n_samples; j++) {
1063
-       for (i = 0; i < n_channels; i++)
1064
-           *d++ = F32_TO_U8(sij);
1065
-   }
1066
-}
1067
-
1068
-void
1069
-conv_f32d_to_u8_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1070
-       uint32_t n_samples)
1071
-{
1072
-   const float **s = (const float **) src;
1073
-   uint8_t *d = dst0;
1074
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1075
-   float *dither = conv->dither;
1076
-
1077
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1078
-
1079
-   for (j = 0; j < n_samples;) {
1080
-       chunk = SPA_MIN(n_samples - j, dither_size);
1081
-       for (k = 0; k < chunk; k++, j++) {
1082
-           for (i = 0; i < n_channels; i++)
1083
-               *d++ = F32_TO_U8_D(sij, ditherk);
1084
-       }
1085
-   }
1086
-}
1087
-
1088
-void
1089
-conv_f32d_to_u8_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1090
-       uint32_t n_samples)
1091
-{
1092
-   uint8_t *d0 = dst0;
1093
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1094
-   float *dither = conv->dither;
1095
-
1096
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1097
-
1098
-   for (i = 0; i < n_channels; i++) {
1099
-       const float *s = srci;
1100
-       uint8_t *d = &d0i;
1101
-       struct shaper *sh = &conv->shaperi;
1102
-       uint32_t idx = sh->idx;
1103
-
1104
-       for (j = 0; j < n_samples;) {
1105
-           chunk = SPA_MIN(n_samples - j, dither_size);
1106
-           for (k = 0; k < chunk; k++, j++)
1107
-               dj * n_channels = F32_TO_U8_SH(sj, sh, ditherk);
1108
-       }
1109
-       sh->idx = idx;
1110
-   }
1111
-}
1112
-
1113
-void
1114
-conv_f32d_to_s8d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1115
-       uint32_t n_samples)
1116
-{
1117
-   uint32_t i, j, n_channels = conv->n_channels;
1118
-
1119
-   for (i = 0; i < n_channels; i++) {
1120
-       const float *s = srci;
1121
-       int8_t *d = dsti;
1122
-
1123
-       for (j = 0; j < n_samples; j++)
1124
-           dj = F32_TO_S8(sj);
1125
-   }
1126
-}
1127
-
1128
-void
1129
-conv_f32d_to_s8d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1130
-       uint32_t n_samples)
1131
-{
1132
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1133
-   float *dither = conv->dither;
1134
-
1135
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1136
-
1137
-   for (i = 0; i < n_channels; i++) {
1138
-       const float *s = srci;
1139
-       int8_t *d = dsti;
1140
-
1141
-       for (j = 0; j < n_samples;) {
1142
-           chunk = SPA_MIN(n_samples - j, dither_size);
1143
-           for (k = 0; k < chunk; k++, j++)
1144
-               dj = F32_TO_S8_D(sj, ditherk);
1145
-       }
1146
-   }
1147
-}
1148
-
1149
-void
1150
-conv_f32d_to_s8d_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1151
-       uint32_t n_samples)
1152
-{
1153
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1154
-   float *dither = conv->dither;
1155
-
1156
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1157
-
1158
-   for (i = 0; i < n_channels; i++) {
1159
-       const float *s = srci;
1160
-       int8_t *d = dsti;
1161
-       struct shaper *sh = &conv->shaperi;
1162
-       uint32_t idx = sh->idx;
1163
-
1164
-       for (j = 0; j < n_samples;) {
1165
-           chunk = SPA_MIN(n_samples - j, dither_size);
1166
-           for (k = 0; k < chunk; k++, j++)
1167
-               dj = F32_TO_S8_SH(sj, sh, ditherk);
1168
-       }
1169
-       sh->idx = idx;
1170
-   }
1171
-}
1172
-
1173
-void
1174
-conv_f32_to_s8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1175
-       uint32_t n_samples)
1176
-{
1177
-   uint32_t i, n_channels = conv->n_channels;
1178
-   const float *s = src0;
1179
-   int8_t *d = dst0;
1180
-
1181
-   n_samples *= n_channels;
1182
-
1183
-   for (i = 0; i < n_samples; i++)
1184
-       di = F32_TO_S8(si);
1185
-}
1186
-
1187
-void
1188
-conv_f32_to_s8d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1189
-       uint32_t n_samples)
1190
-{
1191
-   const float *s = src0;
1192
-   int8_t **d = (int8_t **) dst;
1193
-   uint32_t i, j, n_channels = conv->n_channels;
1194
-
1195
-   for (j = 0; j < n_samples; j++) {
1196
-       for (i = 0; i < n_channels; i++)
1197
-           dij = F32_TO_S8(*s++);
1198
-   }
1199
-}
1200
-
1201
-void
1202
-conv_f32d_to_s8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1203
-       uint32_t n_samples)
1204
-{
1205
-   const float **s = (const float **) src;
1206
-   int8_t *d = dst0;
1207
-   uint32_t i, j, n_channels = conv->n_channels;
1208
-
1209
-   for (j = 0; j < n_samples; j++) {
1210
-       for (i = 0; i < n_channels; i++)
1211
-           *d++ = F32_TO_S8(sij);
1212
-   }
1213
-}
1214
-
1215
-void
1216
-conv_f32d_to_s8_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1217
-       uint32_t n_samples)
1218
-{
1219
-   const float **s = (const float **) src;
1220
-   int8_t *d = dst0;
1221
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1222
-   float *dither = conv->dither;
1223
-
1224
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1225
-
1226
-   for (j = 0; j < n_samples;) {
1227
-       chunk = SPA_MIN(n_samples - j, dither_size);
1228
-       for (k = 0; k < chunk; k++, j++) {
1229
-           for (i = 0; i < n_channels; i++)
1230
-               *d++ = F32_TO_S8_D(sij, ditherk);
1231
-       }
1232
-   }
1233
-}
1234
-
1235
-void
1236
-conv_f32d_to_s8_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1237
-       uint32_t n_samples)
1238
-{
1239
-   int8_t *d0 = dst0;
1240
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1241
-   float *dither = conv->dither;
1242
-
1243
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1244
-
1245
-   for (i = 0; i < n_channels; i++) {
1246
-       const float *s = srci;
1247
-       int8_t *d = &d0i;
1248
-       struct shaper *sh = &conv->shaperi;
1249
-       uint32_t idx = sh->idx;
1250
-
1251
-       for (j = 0; j < n_samples;) {
1252
-           chunk = SPA_MIN(n_samples - j, dither_size);
1253
-           for (k = 0; k < chunk; k++, j++)
1254
-               dj * n_channels = F32_TO_S8_SH(sj, sh, ditherk);
1255
-       }
1256
-       sh->idx = idx;
1257
-   }
1258
-}
1259
-
1260
-void
1261
-conv_f32d_to_alaw_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1262
-       uint32_t n_samples)
1263
-{
1264
-   const float **s = (const float **) src;
1265
-   int8_t *d = dst0;
1266
-   uint32_t i, j, n_channels = conv->n_channels;
1267
-
1268
-   for (j = 0; j < n_samples; j++) {
1269
-       for (i = 0; i < n_channels; i++)
1270
-           *d++ = f32_to_alaw(sij);
1271
-   }
1272
-}
1273
-
1274
-void
1275
-conv_f32d_to_ulaw_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1276
-       uint32_t n_samples)
1277
-{
1278
-   const float **s = (const float **) src;
1279
-   int8_t *d = dst0;
1280
-   uint32_t i, j, n_channels = conv->n_channels;
1281
-
1282
-   for (j = 0; j < n_samples; j++) {
1283
-       for (i = 0; i < n_channels; i++)
1284
-           *d++ = f32_to_ulaw(sij);
1285
-   }
1286
-}
1287
-
1288
-void
1289
-conv_f32_to_u16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1290
-       uint32_t n_samples)
1291
-{
1292
-   uint32_t i, n_channels = conv->n_channels;
1293
-   const float *s = src0;
1294
-   uint16_t *d = dst0;
1295
-
1296
-   n_samples *= n_channels;
1297
-
1298
-   for (i = 0; i < n_samples; i++)
1299
-       di = F32_TO_U16(si);
1300
-}
1301
-void
1302
-conv_f32d_to_u16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1303
-       uint32_t n_samples)
1304
-{
1305
-   const float **s = (const float **) src;
1306
-   uint16_t *d = dst0;
1307
-   uint32_t i, j, n_channels = conv->n_channels;
1308
-
1309
-   for (j = 0; j < n_samples; j++) {
1310
-       for (i = 0; i < n_channels; i++)
1311
-           *d++ = F32_TO_U16(sij);
1312
-   }
1313
-}
1314
-
1315
-void
1316
-conv_f32d_to_s16d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1317
-       uint32_t n_samples)
1318
-{
1319
-   uint32_t i, j, n_channels = conv->n_channels;
1320
-
1321
-   for (i = 0; i < n_channels; i++) {
1322
-       const float *s = srci;
1323
-       int16_t *d = dsti;
1324
-
1325
-       for (j = 0; j < n_samples; j++)
1326
-           dj = F32_TO_S16(sj);
1327
-   }
1328
-}
1329
-
1330
-void
1331
-conv_f32d_to_s16d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1332
-       uint32_t n_samples)
1333
-{
1334
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1335
-   float *dither = conv->dither;
1336
-
1337
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1338
-
1339
-   for (i = 0; i < n_channels; i++) {
1340
-       const float *s = srci;
1341
-       int16_t *d = dsti;
1342
-
1343
-       for (j = 0; j < n_samples;) {
1344
-           chunk = SPA_MIN(n_samples - j, dither_size);
1345
-           for (k = 0; k < chunk; k++, j++)
1346
-               dj = F32_TO_S16_D(sj, ditherk);
1347
-       }
1348
-   }
1349
-}
1350
-
1351
-
1352
-void
1353
-conv_f32d_to_s16d_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1354
-       uint32_t n_samples)
1355
-{
1356
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1357
-   float *dither = conv->dither;
1358
-
1359
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1360
-
1361
-   for (i = 0; i < n_channels; i++) {
1362
-       const float *s = srci;
1363
-       int16_t *d = dsti;
1364
-       struct shaper *sh = &conv->shaperi;
1365
-       uint32_t idx = sh->idx;
1366
-
1367
-       for (j = 0; j < n_samples;) {
1368
-           chunk = SPA_MIN(n_samples - j, dither_size);
1369
-           for (k = 0; k < chunk; k++, j++)
1370
-               dj = F32_TO_S16_SH(sj, sh, ditherk);
1371
-       }
1372
-       sh->idx = idx;
1373
-   }
1374
-}
1375
-
1376
-void
1377
-conv_f32_to_s16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1378
-       uint32_t n_samples)
1379
-{
1380
-   uint32_t i, n_channels = conv->n_channels;
1381
-   const float *s = src0;
1382
-   int16_t *d = dst0;
1383
-
1384
-   n_samples *= n_channels;
1385
-
1386
-   for (i = 0; i < n_samples; i++)
1387
-       di = F32_TO_S16(si);
1388
-}
1389
-
1390
-void
1391
-conv_f32_to_s16d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1392
-       uint32_t n_samples)
1393
-{
1394
-   const float *s = src0;
1395
-   int16_t **d = (int16_t **) dst;
1396
-   uint32_t i, j, n_channels = conv->n_channels;
1397
-
1398
-   for (j = 0; j < n_samples; j++) {
1399
-       for (i = 0; i < n_channels; i++)
1400
-           dij = F32_TO_S16(*s++);
1401
-   }
1402
-}
1403
-
1404
-void
1405
-conv_f32d_to_s16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1406
-       uint32_t n_samples)
1407
-{
1408
-   const float **s = (const float **) src;
1409
-   int16_t *d = dst0;
1410
-   uint32_t i, j, n_channels = conv->n_channels;
1411
-
1412
-   for (j = 0; j < n_samples; j++) {
1413
-       for (i = 0; i < n_channels; i++)
1414
-           *d++ = F32_TO_S16(sij);
1415
-   }
1416
-}
1417
-
1418
-void
1419
-conv_f32d_to_s16_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1420
-       uint32_t n_samples)
1421
-{
1422
-   const float **s = (const float **) src;
1423
-   int16_t *d = dst0;
1424
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1425
-   float *dither = conv->dither;
1426
-
1427
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1428
-
1429
-   for (j = 0; j < n_samples;) {
1430
-       chunk = SPA_MIN(n_samples - j, dither_size);
1431
-       for (k = 0; k < chunk; k++, j++) {
1432
-           for (i = 0; i < n_channels; i++)
1433
-               *d++ = F32_TO_S16_D(sij, ditherk);
1434
-       }
1435
-   }
1436
-}
1437
-
1438
-void
1439
-conv_f32d_to_s16_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1440
-       uint32_t n_samples)
1441
-{
1442
-   int16_t *d0 = dst0;
1443
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1444
-   float *dither = conv->dither;
1445
-
1446
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1447
-
1448
-   for (i = 0; i < n_channels; i++) {
1449
-       const float *s = srci;
1450
-       int16_t *d = &d0i;
1451
-       struct shaper *sh = &conv->shaperi;
1452
-       uint32_t idx = sh->idx;
1453
-
1454
-       for (j = 0; j < n_samples;) {
1455
-           chunk = SPA_MIN(n_samples - j, dither_size);
1456
-           for (k = 0; k < chunk; k++, j++)
1457
-               dj * n_channels = F32_TO_S16_SH(sj, sh, ditherk);
1458
-       }
1459
-       sh->idx = idx;
1460
-   }
1461
-}
1462
-
1463
-void
1464
-conv_f32d_to_s16s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1465
-       uint32_t n_samples)
1466
-{
1467
-   const float **s = (const float **) src;
1468
-   int16_t *d = dst0;
1469
-   uint32_t i, j, n_channels = conv->n_channels;
1470
-
1471
-   for (j = 0; j < n_samples; j++) {
1472
-       for (i = 0; i < n_channels; i++)
1473
-           *d++ = F32_TO_S16S(sij);
1474
-   }
1475
-}
1476
-
1477
-void
1478
-conv_f32d_to_s16s_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1479
-       uint32_t n_samples)
1480
-{
1481
-   const float **s = (const float **) src;
1482
-   uint16_t *d = dst0;
1483
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1484
-   float *dither = conv->dither;
1485
-
1486
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1487
-
1488
-   for (j = 0; j < n_samples;) {
1489
-       chunk = SPA_MIN(n_samples - j, dither_size);
1490
-       for (k = 0; k < chunk; k++, j++) {
1491
-           for (i = 0; i < n_channels; i++)
1492
-               *d++ = F32_TO_S16S_D(sij, ditherk);
1493
-       }
1494
-   }
1495
-}
1496
-
1497
-void
1498
-conv_f32d_to_s16s_shaped_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1499
-       uint32_t n_samples)
1500
-{
1501
-   int16_t *d0 = dst0;
1502
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1503
-   float *dither = conv->dither;
1504
-
1505
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1506
-
1507
-   for (i = 0; i < n_channels; i++) {
1508
-       const float *s = srci;
1509
-       int16_t *d = &d0i;
1510
-       struct shaper *sh = &conv->shaperi;
1511
-       uint32_t idx = sh->idx;
1512
-
1513
-       for (j = 0; j < n_samples;) {
1514
-           chunk = SPA_MIN(n_samples - j, dither_size);
1515
-           for (k = 0; k < chunk; k++, j++)
1516
-               dj * n_channels = F32_TO_S16S_SH(sj, sh, ditherk);
1517
-       }
1518
-       sh->idx = idx;
1519
-   }
1520
-}
1521
-void
1522
-conv_f32_to_u32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1523
-       uint32_t n_samples)
1524
-{
1525
-   uint32_t i, n_channels = conv->n_channels;
1526
-   const float *s = src0;
1527
-   uint32_t *d = dst0;
1528
-
1529
-   n_samples *= n_channels;
1530
-
1531
-   for (i = 0; i < n_samples; i++)
1532
-       di = F32_TO_U32(si);
1533
-}
1534
-
1535
-void
1536
-conv_f32d_to_u32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1537
-       uint32_t n_samples)
1538
-{
1539
-   const float **s = (const float **) src;
1540
-   uint32_t *d = dst0;
1541
-   uint32_t i, j, n_channels = conv->n_channels;
1542
-
1543
-   for (j = 0; j < n_samples; j++) {
1544
-       for (i = 0; i < n_channels; i++)
1545
-           *d++ = F32_TO_U32(sij);
1546
-   }
1547
-}
1548
-
1549
-void
1550
-conv_f32d_to_s32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1551
-       uint32_t n_samples)
1552
-{
1553
-   uint32_t i, j, n_channels = conv->n_channels;
1554
-
1555
-   for (i = 0; i < n_channels; i++) {
1556
-       const float *s = srci;
1557
-       int32_t *d = dsti;
1558
-
1559
-       for (j = 0; j < n_samples; j++)
1560
-           dj = F32_TO_S32(sj);
1561
-   }
1562
-}
1563
-
1564
-void
1565
-conv_f32d_to_s32d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1566
-       uint32_t n_samples)
1567
-{
1568
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1569
-   float *dither = conv->dither;
1570
-
1571
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1572
-
1573
-   for (i = 0; i < n_channels; i++) {
1574
-       const float *s = srci;
1575
-       int32_t *d = dsti;
1576
-
1577
-       for (j = 0; j < n_samples;) {
1578
-           chunk = SPA_MIN(n_samples - j, dither_size);
1579
-           for (k = 0; k < chunk; k++, j++)
1580
-               dj = F32_TO_S32_D(sj, ditherk);
1581
-       }
1582
-   }
1583
-}
1584
-
1585
-void
1586
-conv_f32_to_s32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1587
-       uint32_t n_samples)
1588
-{
1589
-   uint32_t i, n_channels = conv->n_channels;
1590
-   const float *s = src0;
1591
-   int32_t *d = dst0;
1592
-
1593
-   n_samples *= n_channels;
1594
-
1595
-   for (i = 0; i < n_samples; i++)
1596
-       di = F32_TO_S32(si);
1597
-}
1598
-
1599
-void
1600
-conv_f32_to_s32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1601
-       uint32_t n_samples)
1602
-{
1603
-   const float *s = src0;
1604
-   int32_t **d = (int32_t **) dst;
1605
-   uint32_t i, j, n_channels = conv->n_channels;
1606
-
1607
-   for (j = 0; j < n_samples; j++) {
1608
-       for (i = 0; i < n_channels; i++)
1609
-           dij = F32_TO_S32(*s++);
1610
-   }
1611
-}
1612
-
1613
-void
1614
-conv_f32d_to_s32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1615
-       uint32_t n_samples)
1616
-{
1617
-   const float **s = (const float **) src;
1618
-   int32_t *d = dst0;
1619
-   uint32_t i, j, n_channels = conv->n_channels;
1620
-
1621
-   for (j = 0; j < n_samples; j++) {
1622
-       for (i = 0; i < n_channels; i++)
1623
-           *d++ = F32_TO_S32(sij);
1624
-   }
1625
-}
1626
-
1627
-void
1628
-conv_f32d_to_s32_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1629
-       uint32_t n_samples)
1630
-{
1631
-   const float **s = (const float **) src;
1632
-   int32_t *d = dst0;
1633
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1634
-   float *dither = conv->dither;
1635
-
1636
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1637
-
1638
-   for (j = 0; j < n_samples;) {
1639
-       chunk = SPA_MIN(n_samples - j, dither_size);
1640
-       for (k = 0; k < chunk; k++, j++) {
1641
-           for (i = 0; i < n_channels; i++)
1642
-               *d++ = F32_TO_S32_D(sij, ditherk);
1643
-       }
1644
-   }
1645
-}
1646
-
1647
-void
1648
-conv_f32d_to_s32s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1649
-       uint32_t n_samples)
1650
-{
1651
-   const float **s = (const float **) src;
1652
-   uint32_t *d = dst0;
1653
-   uint32_t i, j, n_channels = conv->n_channels;
1654
-
1655
-   for (j = 0; j < n_samples; j++) {
1656
-       for (i = 0; i < n_channels; i++)
1657
-           *d++ = F32_TO_S32S(sij);
1658
-   }
1659
-}
1660
-
1661
-void
1662
-conv_f32d_to_s32s_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1663
-       uint32_t n_samples)
1664
-{
1665
-   const float **s = (const float **) src;
1666
-   uint32_t *d = dst0;
1667
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1668
-   float *dither = conv->dither;
1669
-
1670
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1671
-
1672
-   for (j = 0; j < n_samples;) {
1673
-       chunk = SPA_MIN(n_samples - j, dither_size);
1674
-       for (k = 0; k < chunk; k++, j++) {
1675
-           for (i = 0; i < n_channels; i++)
1676
-               *d++ = F32_TO_S32S_D(sij, ditherk);
1677
-       }
1678
-   }
1679
-}
1680
-
1681
-void
1682
-conv_f32d_to_f64d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1683
-       uint32_t n_samples)
1684
-{
1685
-   uint32_t i, j, n_channels = conv->n_channels;
1686
-
1687
-   for (i = 0; i < n_channels; i++) {
1688
-       const float *s = srci;
1689
-       double *d = dsti;
1690
-
1691
-       for (j = 0; j < n_samples; j++)
1692
-           dj = sj;
1693
-   }
1694
-}
1695
-
1696
-void
1697
-conv_f32_to_f64_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1698
-       uint32_t n_samples)
1699
-{
1700
-   uint32_t i, n_channels = conv->n_channels;
1701
-   const float *s = src0;
1702
-   double *d = dst0;
1703
-
1704
-   n_samples *= n_channels;
1705
-
1706
-   for (i = 0; i < n_samples; i++)
1707
-       di = si;
1708
-}
1709
-
1710
-void
1711
-conv_f32_to_f64d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1712
-       uint32_t n_samples)
1713
-{
1714
-   const float *s = src0;
1715
-   double **d = (double **) dst;
1716
-   uint32_t i, j, n_channels = conv->n_channels;
1717
-
1718
-   for (j = 0; j < n_samples; j++) {
1719
-       for (i = 0; i < n_channels; i++)
1720
-           dij = *s++;
1721
-   }
1722
-}
1723
-
1724
-void
1725
-conv_f32d_to_f64_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1726
-       uint32_t n_samples)
1727
-{
1728
-   const float **s = (const float **) src;
1729
-   double *d = dst0;
1730
-   uint32_t i, j, n_channels = conv->n_channels;
1731
-
1732
-   for (j = 0; j < n_samples; j++) {
1733
-       for (i = 0; i < n_channels; i++)
1734
-           *d++ = sij;
1735
-   }
1736
-}
1737
-
1738
-void
1739
-conv_f32d_to_f64s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1740
-       uint32_t n_samples)
1741
-{
1742
-   const float **s = (const float **) src;
1743
-   double *d = dst0;
1744
-   uint32_t i, j, n_channels = conv->n_channels;
1745
-
1746
-   for (j = 0; j < n_samples; j++) {
1747
-       for (i = 0; i < n_channels; i++)
1748
-           *d++ = bswap_32(sij);
1749
-   }
1750
-}
1751
-
1752
-void
1753
-conv_f32_to_u24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1754
-       uint32_t n_samples)
1755
-{
1756
-   uint32_t i, n_channels = conv->n_channels;
1757
-   const float *s = src0;
1758
-   uint8_t *d = dst0;
1759
-
1760
-   n_samples *= n_channels;
1761
-
1762
-   for (i = 0; i < n_samples; i++) {
1763
-       write_u24(d, F32_TO_U24(si));
1764
-       d += 3;
1765
-   }
1766
-}
1767
-
1768
-void
1769
-conv_f32d_to_u24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1770
-       uint32_t n_samples)
1771
-{
1772
-   const float **s = (const float **) src;
1773
-   uint8_t *d = dst0;
1774
-   uint32_t i, j, n_channels = conv->n_channels;
1775
-
1776
-   for (j = 0; j < n_samples; j++) {
1777
-       for (i = 0; i < n_channels; i++) {
1778
-           write_u24(d, F32_TO_U24(sij));
1779
-           d += 3;
1780
-       }
1781
-   }
1782
-}
1783
-
1784
-void
1785
-conv_f32d_to_s24d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1786
-       uint32_t n_samples)
1787
-{
1788
-   uint32_t i, j, n_channels = conv->n_channels;
1789
-
1790
-   for (i = 0; i < n_channels; i++) {
1791
-       const float *s = srci;
1792
-       uint8_t *d = dsti;
1793
-
1794
-       for (j = 0; j < n_samples; j++) {
1795
-           write_s24(d, F32_TO_S24(sj));
1796
-           d += 3;
1797
-       }
1798
-   }
1799
-}
1800
-
1801
-void
1802
-conv_f32d_to_s24d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1803
-       uint32_t n_samples)
1804
-{
1805
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1806
-   float *dither = conv->dither;
1807
-
1808
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1809
-
1810
-   for (i = 0; i < n_channels; i++) {
1811
-       const float *s = srci;
1812
-       uint8_t *d = dsti;
1813
-
1814
-       for (j = 0; j < n_samples;) {
1815
-           chunk = SPA_MIN(n_samples - j, dither_size);
1816
-           for (k = 0; k < chunk; k++, j++) {
1817
-               write_s24(d, F32_TO_S24_D(sj, ditherk));
1818
-               d += 3;
1819
-           }
1820
-       }
1821
-   }
1822
-}
1823
-
1824
-void
1825
-conv_f32_to_s24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1826
-       uint32_t n_samples)
1827
-{
1828
-   uint32_t i, n_channels = conv->n_channels;
1829
-   const float *s = src0;
1830
-   uint8_t *d = dst0;
1831
-
1832
-   n_samples *= n_channels;
1833
-
1834
-   for (i = 0; i < n_samples; i++) {
1835
-       write_s24(d, F32_TO_S24(si));
1836
-       d += 3;
1837
-   }
1838
-}
1839
-
1840
-void
1841
-conv_f32_to_s24d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1842
-       uint32_t n_samples)
1843
-{
1844
-   const float *s = src0;
1845
-   uint8_t **d = (uint8_t **) dst;
1846
-   uint32_t i, j, n_channels = conv->n_channels;
1847
-
1848
-   for (j = 0; j < n_samples; j++) {
1849
-       for (i = 0; i < n_channels; i++) {
1850
-           write_s24(&dij*3, F32_TO_S24(*s++));
1851
-       }
1852
-   }
1853
-}
1854
-
1855
-void
1856
-conv_f32d_to_s24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1857
-       uint32_t n_samples)
1858
-{
1859
-   const float **s = (const float **) src;
1860
-   uint8_t *d = dst0;
1861
-   uint32_t i, j, n_channels = conv->n_channels;
1862
-
1863
-   for (j = 0; j < n_samples; j++) {
1864
-       for (i = 0; i < n_channels; i++) {
1865
-           write_s24(d, F32_TO_S24(sij));
1866
-           d += 3;
1867
-       }
1868
-   }
1869
-}
1870
-
1871
-void
1872
-conv_f32d_to_s24_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1873
-       uint32_t n_samples)
1874
-{
1875
-   const float **s = (const float **) src;
1876
-   uint8_t *d = dst0;
1877
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1878
-   float *dither = conv->dither;
1879
-
1880
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1881
-
1882
-   for (j = 0; j < n_samples;) {
1883
-       chunk = SPA_MIN(n_samples - j, dither_size);
1884
-       for (k = 0; k < chunk; k++, j++) {
1885
-           for (i = 0; i < n_channels; i++) {
1886
-               write_s24(d, F32_TO_S24_D(sij, ditherk));
1887
-               d += 3;
1888
-           }
1889
-       }
1890
-   }
1891
-}
1892
-
1893
-void
1894
-conv_f32d_to_s24s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1895
-       uint32_t n_samples)
1896
-{
1897
-   const float **s = (const float **) src;
1898
-   uint8_t *d = dst0;
1899
-   uint32_t i, j, n_channels = conv->n_channels;
1900
-
1901
-   for (j = 0; j < n_samples; j++) {
1902
-       for (i = 0; i < n_channels; i++) {
1903
-           write_s24s(d, F32_TO_S24(sij));
1904
-           d += 3;
1905
-       }
1906
-   }
1907
-}
1908
-
1909
-void
1910
-conv_f32d_to_s24s_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1911
-       uint32_t n_samples)
1912
-{
1913
-   const float **s = (const float **) src;
1914
-   uint8_t *d = dst0;
1915
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1916
-   float *dither = conv->dither;
1917
-
1918
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1919
-
1920
-   for (j = 0; j < n_samples;) {
1921
-       chunk = SPA_MIN(n_samples - j, dither_size);
1922
-       for (k = 0; k < chunk; k++, j++) {
1923
-           for (i = 0; i < n_channels; i++) {
1924
-               write_s24s(d, F32_TO_S24_D(sij, ditherk));
1925
-               d += 3;
1926
-           }
1927
-       }
1928
-   }
1929
-}
1930
-
1931
-void
1932
-conv_f32d_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1933
-       uint32_t n_samples)
1934
-{
1935
-   uint32_t i, j, n_channels = conv->n_channels;
1936
-
1937
-   for (i = 0; i < n_channels; i++) {
1938
-       const float *s = srci;
1939
-       int32_t *d = dsti;
1940
-
1941
-       for (j = 0; j < n_samples; j++)
1942
-           dj = F32_TO_S24_32(sj);
1943
-   }
1944
-}
1945
-
1946
-void
1947
-conv_f32d_to_s24_32d_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1948
-       uint32_t n_samples)
1949
-{
1950
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
1951
-   float *dither = conv->dither;
1952
-
1953
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
1954
-
1955
-   for (i = 0; i < n_channels; i++) {
1956
-       const float *s = srci;
1957
-       int32_t *d = dsti;
1958
-
1959
-       for (j = 0; j < n_samples;) {
1960
-           chunk = SPA_MIN(n_samples - j, dither_size);
1961
-           for (k = 0; k < chunk; k++, j++)
1962
-               dj = F32_TO_S24_32_D(sj, ditherk);
1963
-       }
1964
-   }
1965
-}
1966
-
1967
-void
1968
-conv_f32_to_u24_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1969
-       uint32_t n_samples)
1970
-{
1971
-   uint32_t i, n_channels = conv->n_channels;
1972
-   const float *s = src0;
1973
-   uint32_t *d = dst0;
1974
-
1975
-   n_samples *= n_channels;
1976
-
1977
-   for (i = 0; i < n_samples; i++)
1978
-       di = F32_TO_U24_32(si);
1979
-}
1980
-
1981
-void
1982
-conv_f32d_to_u24_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1983
-       uint32_t n_samples)
1984
-{
1985
-   const float **s = (const float **) src;
1986
-   uint32_t *d = dst0;
1987
-   uint32_t i, j, n_channels = conv->n_channels;
1988
-
1989
-   for (j = 0; j < n_samples; j++) {
1990
-       for (i = 0; i < n_channels; i++)
1991
-           *d++ = F32_TO_U24_32(sij);
1992
-   }
1993
-}
1994
-
1995
-void
1996
-conv_f32_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
1997
-       uint32_t n_samples)
1998
-{
1999
-   uint32_t i, n_channels = conv->n_channels;
2000
-   const float *s = src0;
2001
-   int32_t *d = dst0;
2002
-
2003
-   n_samples *= n_channels;
2004
-
2005
-   for (i = 0; i < n_samples; i++)
2006
-       di = F32_TO_S24_32(si);
2007
-}
2008
-
2009
-void
2010
-conv_f32_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2011
-       uint32_t n_samples)
2012
-{
2013
-   const float *s = src0;
2014
-   int32_t **d = (int32_t **) dst;
2015
-   uint32_t i, j, n_channels = conv->n_channels;
2016
-
2017
-   for (j = 0; j < n_samples; j++) {
2018
-       for (i = 0; i < n_channels; i++)
2019
-           dij = F32_TO_S24_32(*s++);
2020
-   }
2021
-}
2022
-
2023
-void
2024
-conv_f32d_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2025
-       uint32_t n_samples)
2026
-{
2027
-   const float **s = (const float **) src;
2028
-   int32_t *d = dst0;
2029
-   uint32_t i, j, n_channels = conv->n_channels;
2030
-
2031
-   for (j = 0; j < n_samples; j++) {
2032
-       for (i = 0; i < n_channels; i++)
2033
-           *d++ = F32_TO_S24_32(sij);
2034
-   }
2035
-}
2036
-
2037
-void
2038
-conv_f32d_to_s24_32_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2039
-       uint32_t n_samples)
2040
-{
2041
-   const float **s = (const float **) src;
2042
-   int32_t *d = dst0;
2043
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
2044
-   float *dither = conv->dither;
2045
-
2046
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
2047
-
2048
-   for (j = 0; j < n_samples;) {
2049
-       chunk = SPA_MIN(n_samples - j, dither_size);
2050
-       for (k = 0; k < chunk; k++, j++) {
2051
-           for (i = 0; i < n_channels; i++)
2052
-               *d++ = F32_TO_S24_32_D(sij, ditherk);
2053
-       }
2054
-   }
2055
-}
2056
-
2057
-void
2058
-conv_f32d_to_s24_32s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2059
-       uint32_t n_samples)
2060
-{
2061
-   const float **s = (const float **) src;
2062
-   int32_t *d = dst0;
2063
-   uint32_t i, j, n_channels = conv->n_channels;
2064
-
2065
-   for (j = 0; j < n_samples; j++) {
2066
-       for (i = 0; i < n_channels; i++)
2067
-           *d++ = F32_TO_S24_32S(sij);
2068
-   }
2069
-}
2070
-
2071
-void
2072
-conv_f32d_to_s24_32s_dither_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2073
-       uint32_t n_samples)
2074
-{
2075
-   const float **s = (const float **) src;
2076
-   int32_t *d = dst0;
2077
-   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;
2078
-   float *dither = conv->dither;
2079
-
2080
-   update_dither_c(conv, SPA_MIN(n_samples, dither_size));
2081
-
2082
-   for (j = 0; j < n_samples;) {
2083
-       chunk = SPA_MIN(n_samples - j, dither_size);
2084
-       for (k = 0; k < chunk; k++, j++) {
2085
-           for (i = 0; i < n_channels; i++)
2086
-               *d++ = F32_TO_S24_32S_D(sij, ditherk);
2087
-       }
2088
-   }
2089
-}
2090
-
2091
-void
2092
-conv_deinterleave_8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2093
-       uint32_t n_samples)
2094
-{
2095
-   const uint8_t *s = src0;
2096
-   uint8_t **d = (uint8_t **) dst;
2097
-   uint32_t i, j, n_channels = conv->n_channels;
2098
-
2099
-   for (j = 0; j < n_samples; j++) {
2100
-       for (i = 0; i < n_channels; i++)
2101
-           dij = *s++;
2102
-   }
2103
-}
2104
-
2105
-void
2106
-conv_deinterleave_16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2107
-       uint32_t n_samples)
2108
-{
2109
-   const uint16_t *s = src0;
2110
-   uint16_t **d = (uint16_t **) dst;
2111
-   uint32_t i, j, n_channels = conv->n_channels;
2112
-
2113
-   for (j = 0; j < n_samples; j++) {
2114
-       for (i = 0; i < n_channels; i++)
2115
-           dij = *s++;
2116
-   }
2117
-}
2118
-
2119
-void
2120
-conv_deinterleave_24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2121
-       uint32_t n_samples)
2122
-{
2123
-   const uint8_t *s = src0;
2124
-   uint8_t **d = (uint8_t **) dst;
2125
-   uint32_t i, j, n_channels = conv->n_channels;
2126
-
2127
-   for (j = 0; j < n_samples; j++) {
2128
-       for (i = 0; i < n_channels; i++) {
2129
-           write_s24(&dij*3, read_s24(s));
2130
-           s += 3;
2131
-       }
2132
-   }
2133
-}
2134
-
2135
-void
2136
-conv_deinterleave_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2137
-       uint32_t n_samples)
2138
-{
2139
-   const uint32_t *s = src0;
2140
-   uint32_t **d = (uint32_t **) dst;
2141
-   uint32_t i, j, n_channels = conv->n_channels;
2142
-
2143
-   for (j = 0; j < n_samples; j++) {
2144
-       for (i = 0; i < n_channels; i++)
2145
-           dij = *s++;
2146
-   }
2147
-}
2148
-
2149
-void
2150
-conv_deinterleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2151
-       uint32_t n_samples)
2152
-{
2153
-   const uint32_t *s = src0;
2154
-   uint32_t **d = (uint32_t **) dst;
2155
-   uint32_t i, j, n_channels = conv->n_channels;
2156
-
2157
-   for (j = 0; j < n_samples; j++) {
2158
-       for (i = 0; i < n_channels; i++)
2159
-           dij = bswap_32(*s++);
2160
-   }
2161
-}
2162
-
2163
-void
2164
-conv_deinterleave_64_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2165
-       uint32_t n_samples)
2166
-{
2167
-   const uint64_t *s = src0;
2168
-   uint64_t **d = (uint64_t **) dst;
2169
-   uint32_t i, j, n_channels = conv->n_channels;
2170
-
2171
-   for (j = 0; j < n_samples; j++) {
2172
-       for (i = 0; i < n_channels; i++)
2173
-           dij = *s++;
2174
-   }
2175
-}
2176
-
2177
-void
2178
-conv_interleave_8_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2179
-       uint32_t n_samples)
2180
-{
2181
-   const int8_t **s = (const int8_t **) src;
2182
-   uint8_t *d = dst0;
2183
-   uint32_t i, j, n_channels = conv->n_channels;
2184
-
2185
-   for (j = 0; j < n_samples; j++) {
2186
-       for (i = 0; i < n_channels; i++)
2187
-           *d++ = sij;
2188
-   }
2189
-}
2190
-
2191
-void
2192
-conv_interleave_16_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2193
-       uint32_t n_samples)
2194
-{
2195
-   const int16_t **s = (const int16_t **) src;
2196
-   uint16_t *d = dst0;
2197
-   uint32_t i, j, n_channels = conv->n_channels;
2198
-
2199
-   for (j = 0; j < n_samples; j++) {
2200
-       for (i = 0; i < n_channels; i++)
2201
-           *d++ = sij;
2202
-   }
2203
-}
2204
-
2205
-void
2206
-conv_interleave_24_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2207
-       uint32_t n_samples)
2208
-{
2209
-   const int8_t **s = (const int8_t **) src;
2210
-   uint8_t *d = dst0;
2211
-   uint32_t i, j, n_channels = conv->n_channels;
2212
-
2213
-   for (j = 0; j < n_samples; j++) {
2214
-       for (i = 0; i < n_channels; i++) {
2215
-           write_s24(d, read_s24(&sij*3));
2216
-           d += 3;
2217
-       }
2218
-   }
2219
-}
2220
-
2221
-void
2222
-conv_interleave_32_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2223
-       uint32_t n_samples)
2224
-{
2225
-   const int32_t **s = (const int32_t **) src;
2226
-   uint32_t *d = dst0;
2227
-   uint32_t i, j, n_channels = conv->n_channels;
2228
-
2229
-   for (j = 0; j < n_samples; j++) {
2230
-       for (i = 0; i < n_channels; i++)
2231
-           *d++ = sij;
2232
-   }
2233
-}
2234
-
2235
-void
2236
-conv_interleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2237
-       uint32_t n_samples)
2238
-{
2239
-   const int32_t **s = (const int32_t **) src;
2240
-   uint32_t *d = dst0;
2241
-   uint32_t i, j, n_channels = conv->n_channels;
2242
-
2243
-   for (j = 0; j < n_samples; j++) {
2244
-       for (i = 0; i < n_channels; i++)
2245
-           *d++ = bswap_32(sij);
2246
-   }
2247
-}
2248
-
2249
-void
2250
-conv_interleave_64_c(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
2251
-       uint32_t n_samples)
2252
-{
2253
-   const int64_t **s = (const int64_t **) src;
2254
-   uint64_t *d = dst0;
2255
-   uint32_t i, j, n_channels = conv->n_channels;
2256
-
2257
-   for (j = 0; j < n_samples; j++) {
2258
-       for (i = 0; i < n_channels; i++)
2259
-           *d++ = sij;
2260
-   }
2261
-}
2262
+#define MAKE_D_shaped(dname,dtype,func)                    \
2263
+void conv_f32d_to_ ##dname## d_shaped_c(struct convert *conv,          \
2264
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
2265
+                uint32_t n_samples)                        \
2266
+{                                      \
2267
+   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;    \
2268
+   float *dither = conv->dither;                       \
2269
+   update_dither_c(conv, SPA_MIN(n_samples, dither_size));         \
2270
+   for (i = 0; i < n_channels; i++) {                  \
2271
+       const float *s = srci;                  \
2272
+       dtype *d = dsti;                        \
2273
+       struct shaper *sh = &conv->shaperi;             \
2274
+       uint32_t idx = sh->idx;                     \
2275
+       for (j = 0; j < n_samples;) {                   \
2276
+           chunk = SPA_MIN(n_samples - j, dither_size);        \
2277
+           for (k = 0; k < chunk; k++, j++)            \
2278
+               dj = func (sj, sh, ditherk);        \
2279
+       }                               \
2280
+       sh->idx = idx;                          \
2281
+   }                                   \
2282
+}
2283
+
2284
+#define MAKE_I_shaped(dname,dtype,func)                    \
2285
+void conv_f32d_to_ ##dname## _shaped_c(struct convert *conv,           \
2286
+       void * SPA_RESTRICT dst, const void * SPA_RESTRICT src, \
2287
+                uint32_t n_samples)                        \
2288
+{                                      \
2289
+   dtype *d0 = dst0;                           \
2290
+   uint32_t i, j, k, chunk, n_channels = conv->n_channels, dither_size = conv->dither_size;    \
2291
+   float *dither = conv->dither;                       \
2292
+   update_dither_c(conv, SPA_MIN(n_samples, dither_size));         \
2293
+   for (i = 0; i < n_channels; i++) {                  \
2294
+       const float *s = srci;                  \
2295
+       dtype *d = &d0i;                        \
2296
+       struct shaper *sh = &conv->shaperi;             \
2297
+       uint32_t idx = sh->idx;                     \
2298
+       for (j = 0; j < n_samples;) {                   \
2299
+           chunk = SPA_MIN(n_samples - j, dither_size);        \
2300
+           for (k = 0; k < chunk; k++, j++)            \
2301
+               dj*n_channels = func (sj, sh, ditherk); \
2302
+       }                               \
2303
+       sh->idx = idx;                          \
2304
+   }                                   \
2305
+}
2306
+
2307
+MAKE_D_shaped(u8, uint8_t, F32_TO_U8_SH);
2308
+MAKE_I_shaped(u8, uint8_t, F32_TO_U8_SH);
2309
+MAKE_D_shaped(s8, int8_t, F32_TO_S8_SH);
2310
+MAKE_I_shaped(s8, int8_t, F32_TO_S8_SH);
2311
+MAKE_D_shaped(s16, int16_t, F32_TO_S16_SH);
2312
+MAKE_I_shaped(s16, int16_t, F32_TO_S16_SH);
2313
+MAKE_I_shaped(s16s, uint16_t, F32_TO_S16S_SH);
2314
+
2315
+#define MAKE_DEINTERLEAVE(size,type,func)                  \
2316
+   MAKE_I_TO_D(size,type,size,type,func)
2317
+
2318
+MAKE_DEINTERLEAVE(8, uint8_t, (uint8_t));
2319
+MAKE_DEINTERLEAVE(16, uint16_t, (uint16_t));
2320
+MAKE_DEINTERLEAVE(24, uint24_t, (uint24_t));
2321
+MAKE_DEINTERLEAVE(32, uint32_t, (uint32_t));
2322
+MAKE_DEINTERLEAVE(32s, uint32_t, bswap_32);
2323
+MAKE_DEINTERLEAVE(64, uint64_t, (uint64_t));
2324
+
2325
+#define MAKE_INTERLEAVE(size,type,func)                        \
2326
+   MAKE_D_TO_I(size,type,size,type,func)
2327
+
2328
+MAKE_INTERLEAVE(8, uint8_t, (uint8_t));
2329
+MAKE_INTERLEAVE(16, uint16_t, (uint16_t));
2330
+MAKE_INTERLEAVE(24, uint24_t, (uint24_t));
2331
+MAKE_INTERLEAVE(32, uint32_t, (uint32_t));
2332
+MAKE_INTERLEAVE(32s, uint32_t, bswap_32);
2333
+MAKE_INTERLEAVE(64, uint64_t, (uint64_t));
2334
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops-sse2.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops-sse2.c Changed
499
 
1
@@ -132,7 +132,7 @@
2
 conv_s24_to_f32d_1s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
3
        uint32_t n_channels, uint32_t n_samples)
4
 {
5
-   const uint8_t *s = src;
6
+   const int24_t *s = src;
7
    float *d0 = dst0;
8
    uint32_t n, unrolled;
9
    __m128i in;
10
@@ -149,21 +149,21 @@
11
    for(n = 0; n < unrolled; n += 4) {
12
        in = _mm_setr_epi32(
13
            *((uint32_t*)&s0 * n_channels),
14
-           *((uint32_t*)&s3 * n_channels),
15
-           *((uint32_t*)&s6 * n_channels),
16
-           *((uint32_t*)&s9 * n_channels));
17
+           *((uint32_t*)&s1 * n_channels),
18
+           *((uint32_t*)&s2 * n_channels),
19
+           *((uint32_t*)&s3 * n_channels));
20
        in = _mm_slli_epi32(in, 8);
21
        in = _mm_srai_epi32(in, 8);
22
        out = _mm_cvtepi32_ps(in);
23
        out = _mm_mul_ps(out, factor);
24
        _mm_store_ps(&d0n, out);
25
-       s += 12 * n_channels;
26
+       s += 4 * n_channels;
27
    }
28
    for(; n < n_samples; n++) {
29
-       out = _mm_cvtsi32_ss(factor, read_s24(s));
30
+       out = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
31
        out = _mm_mul_ss(out, factor);
32
        _mm_store_ss(&d0n, out);
33
-       s += 3 * n_channels;
34
+       s += n_channels;
35
    }
36
 }
37
 
38
@@ -171,7 +171,7 @@
39
 conv_s24_to_f32d_2s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
40
        uint32_t n_channels, uint32_t n_samples)
41
 {
42
-   const uint8_t *s = src;
43
+   const int24_t *s = src;
44
    float *d0 = dst0, *d1 = dst1;
45
    uint32_t n, unrolled;
46
    __m128i in2;
47
@@ -190,14 +190,14 @@
48
    for(n = 0; n < unrolled; n += 4) {
49
        in0 = _mm_setr_epi32(
50
            *((uint32_t*)&s0 + 0*n_channels),
51
-           *((uint32_t*)&s0 + 3*n_channels),
52
-           *((uint32_t*)&s0 + 6*n_channels),
53
-           *((uint32_t*)&s0 + 9*n_channels));
54
+           *((uint32_t*)&s0 + 1*n_channels),
55
+           *((uint32_t*)&s0 + 2*n_channels),
56
+           *((uint32_t*)&s0 + 3*n_channels));
57
        in1 = _mm_setr_epi32(
58
-           *((uint32_t*)&s3 + 0*n_channels),
59
-           *((uint32_t*)&s3 + 3*n_channels),
60
-           *((uint32_t*)&s3 + 6*n_channels),
61
-           *((uint32_t*)&s3 + 9*n_channels));
62
+           *((uint32_t*)&s1 + 0*n_channels),
63
+           *((uint32_t*)&s1 + 1*n_channels),
64
+           *((uint32_t*)&s1 + 2*n_channels),
65
+           *((uint32_t*)&s1 + 3*n_channels));
66
 
67
        in0 = _mm_slli_epi32(in0, 8);
68
        in1 = _mm_slli_epi32(in1, 8);
69
@@ -214,23 +214,23 @@
70
        _mm_store_ps(&d0n, out0);
71
        _mm_store_ps(&d1n, out1);
72
 
73
-       s += 12 * n_channels;
74
+       s += 4 * n_channels;
75
    }
76
    for(; n < n_samples; n++) {
77
-       out0 = _mm_cvtsi32_ss(factor, read_s24(s));
78
-       out1 = _mm_cvtsi32_ss(factor, read_s24(s+3));
79
+       out0 = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
80
+       out1 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+1)));
81
        out0 = _mm_mul_ss(out0, factor);
82
        out1 = _mm_mul_ss(out1, factor);
83
        _mm_store_ss(&d0n, out0);
84
        _mm_store_ss(&d1n, out1);
85
-       s += 3 * n_channels;
86
+       s += n_channels;
87
    }
88
 }
89
 static void
90
 conv_s24_to_f32d_4s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
91
        uint32_t n_channels, uint32_t n_samples)
92
 {
93
-   const uint8_t *s = src;
94
+   const int24_t *s = src;
95
    float *d0 = dst0, *d1 = dst1, *d2 = dst2, *d3 = dst3;
96
    uint32_t n, unrolled;
97
    __m128i in4;
98
@@ -251,24 +251,24 @@
99
    for(n = 0; n < unrolled; n += 4) {
100
        in0 = _mm_setr_epi32(
101
            *((uint32_t*)&s0 + 0*n_channels),
102
-           *((uint32_t*)&s0 + 3*n_channels),
103
-           *((uint32_t*)&s0 + 6*n_channels),
104
-           *((uint32_t*)&s0 + 9*n_channels));
105
+           *((uint32_t*)&s0 + 1*n_channels),
106
+           *((uint32_t*)&s0 + 2*n_channels),
107
+           *((uint32_t*)&s0 + 3*n_channels));
108
        in1 = _mm_setr_epi32(
109
-           *((uint32_t*)&s3 + 0*n_channels),
110
-           *((uint32_t*)&s3 + 3*n_channels),
111
-           *((uint32_t*)&s3 + 6*n_channels),
112
-           *((uint32_t*)&s3 + 9*n_channels));
113
+           *((uint32_t*)&s1 + 0*n_channels),
114
+           *((uint32_t*)&s1 + 1*n_channels),
115
+           *((uint32_t*)&s1 + 2*n_channels),
116
+           *((uint32_t*)&s1 + 3*n_channels));
117
        in2 = _mm_setr_epi32(
118
-           *((uint32_t*)&s6 + 0*n_channels),
119
-           *((uint32_t*)&s6 + 3*n_channels),
120
-           *((uint32_t*)&s6 + 6*n_channels),
121
-           *((uint32_t*)&s6 + 9*n_channels));
122
+           *((uint32_t*)&s2 + 0*n_channels),
123
+           *((uint32_t*)&s2 + 1*n_channels),
124
+           *((uint32_t*)&s2 + 2*n_channels),
125
+           *((uint32_t*)&s2 + 3*n_channels));
126
        in3 = _mm_setr_epi32(
127
-           *((uint32_t*)&s9 + 0*n_channels),
128
-           *((uint32_t*)&s9 + 3*n_channels),
129
-           *((uint32_t*)&s9 + 6*n_channels),
130
-           *((uint32_t*)&s9 + 9*n_channels));
131
+           *((uint32_t*)&s3 + 0*n_channels),
132
+           *((uint32_t*)&s3 + 1*n_channels),
133
+           *((uint32_t*)&s3 + 2*n_channels),
134
+           *((uint32_t*)&s3 + 3*n_channels));
135
 
136
        in0 = _mm_slli_epi32(in0, 8);
137
        in1 = _mm_slli_epi32(in1, 8);
138
@@ -295,13 +295,13 @@
139
        _mm_store_ps(&d2n, out2);
140
        _mm_store_ps(&d3n, out3);
141
 
142
-       s += 12 * n_channels;
143
+       s += 4 * n_channels;
144
    }
145
    for(; n < n_samples; n++) {
146
-       out0 = _mm_cvtsi32_ss(factor, read_s24(s));
147
-       out1 = _mm_cvtsi32_ss(factor, read_s24(s+3));
148
-       out2 = _mm_cvtsi32_ss(factor, read_s24(s+6));
149
-       out3 = _mm_cvtsi32_ss(factor, read_s24(s+9));
150
+       out0 = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
151
+       out1 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+1)));
152
+       out2 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+2)));
153
+       out3 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+3)));
154
        out0 = _mm_mul_ss(out0, factor);
155
        out1 = _mm_mul_ss(out1, factor);
156
        out2 = _mm_mul_ss(out2, factor);
157
@@ -310,7 +310,7 @@
158
        _mm_store_ss(&d1n, out1);
159
        _mm_store_ss(&d2n, out2);
160
        _mm_store_ss(&d3n, out3);
161
-       s += 3 * n_channels;
162
+       s += n_channels;
163
    }
164
 }
165
 
166
@@ -338,7 +338,7 @@
167
    float *d0 = dst0;
168
    uint32_t n, unrolled;
169
    __m128i in;
170
-   __m128 out, factor = _mm_set1_ps(1.0f / S24_SCALE);
171
+   __m128 out, factor = _mm_set1_ps(1.0f / S32_SCALE);
172
 
173
    if (SPA_IS_ALIGNED(d0, 16))
174
        unrolled = n_samples & ~3;
175
@@ -350,14 +350,13 @@
176
                    s1*n_channels,
177
                    s2*n_channels,
178
                    s3*n_channels);
179
-       in = _mm_srai_epi32(in, 8);
180
        out = _mm_cvtepi32_ps(in);
181
        out = _mm_mul_ps(out, factor);
182
        _mm_store_ps(&d0n, out);
183
        s += 4*n_channels;
184
    }
185
    for(; n < n_samples; n++) {
186
-       out = _mm_cvtsi32_ss(factor, s0>>8);
187
+       out = _mm_cvtsi32_ss(factor, s0);
188
        out = _mm_mul_ss(out, factor);
189
        _mm_store_ss(&d0n, out);
190
        s += n_channels;
191
@@ -395,7 +394,7 @@
192
    for(n = 0; n < unrolled; n += 4) {
193
        in0 = _mm_mul_ps(_mm_load_ps(&s0n), scale);
194
        in0 = _mm_min_ps(in0, int_max);
195
-       out0 = _mm_cvtps_epi32(in0);
196
+       out0 = _mm_cvttps_epi32(in0);
197
        out1 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(0, 3, 2, 1));
198
        out2 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(1, 0, 3, 2));
199
        out3 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(2, 1, 0, 3));
200
@@ -440,8 +439,8 @@
201
        in0 = _mm_min_ps(in0, int_max);
202
        in1 = _mm_min_ps(in1, int_max);
203
 
204
-       out0 = _mm_cvtps_epi32(in0);
205
-       out1 = _mm_cvtps_epi32(in1);
206
+       out0 = _mm_cvttps_epi32(in0);
207
+       out1 = _mm_cvttps_epi32(in1);
208
 
209
        t0 = _mm_unpacklo_epi32(out0, out1);
210
        t1 = _mm_unpackhi_epi32(out0, out1);
211
@@ -460,7 +459,7 @@
212
 
213
        in0 = _mm_mul_ps(in0, scale);
214
        in0 = _mm_min_ps(in0, int_max);
215
-       out0 = _mm_cvtps_epi32(in0);
216
+       out0 = _mm_cvttps_epi32(in0);
217
        _mm_storel_epi64((__m128i*)d, out0);
218
        d += n_channels;
219
    }
220
@@ -499,10 +498,10 @@
221
 
222
        _MM_TRANSPOSE4_PS(in0, in1, in2, in3);
223
 
224
-       out0 = _mm_cvtps_epi32(in0);
225
-       out1 = _mm_cvtps_epi32(in1);
226
-       out2 = _mm_cvtps_epi32(in2);
227
-       out3 = _mm_cvtps_epi32(in3);
228
+       out0 = _mm_cvttps_epi32(in0);
229
+       out1 = _mm_cvttps_epi32(in1);
230
+       out2 = _mm_cvttps_epi32(in2);
231
+       out3 = _mm_cvttps_epi32(in3);
232
 
233
        _mm_storeu_si128((__m128i*)(d + 0*n_channels), out0);
234
        _mm_storeu_si128((__m128i*)(d + 1*n_channels), out1);
235
@@ -522,7 +521,7 @@
236
 
237
        in0 = _mm_mul_ps(in0, scale);
238
        in0 = _mm_min_ps(in0, int_max);
239
-       out0 = _mm_cvtps_epi32(in0);
240
+       out0 = _mm_cvttps_epi32(in0);
241
        _mm_storeu_si128((__m128i*)d, out0);
242
        d += n_channels;
243
    }
244
@@ -590,7 +589,7 @@
245
        in0 = _mm_mul_ps(_mm_load_ps(&sn), scale);
246
        in0 = _mm_add_ps(in0, _mm_load_ps(&dithern));
247
        in0 = _mm_min_ps(in0, int_max);
248
-       out0 = _mm_cvtps_epi32(in0);
249
+       out0 = _mm_cvttps_epi32(in0);
250
        out1 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(0, 3, 2, 1));
251
        out2 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(1, 0, 3, 2));
252
        out3 = _mm_shuffle_epi32(out0, _MM_SHUFFLE(2, 1, 0, 3));
253
@@ -699,7 +698,7 @@
254
 }
255
 
256
 void
257
-conv_interleave_32_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
258
+conv_32d_to_32_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
259
        uint32_t n_samples)
260
 {
261
    int32_t *d = dst0;
262
@@ -797,7 +796,7 @@
263
 }
264
 
265
 void
266
-conv_interleave_32s_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
267
+conv_32sd_to_32s_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
268
        uint32_t n_samples)
269
 {
270
    int32_t *d = dst0;
271
@@ -878,7 +877,7 @@
272
 }
273
 
274
 void
275
-conv_deinterleave_32_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
276
+conv_32_to_32d_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
277
        uint32_t n_samples)
278
 {
279
    const float *s = src0;
280
@@ -965,7 +964,7 @@
281
 }
282
 
283
 void
284
-conv_deinterleave_32s_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
285
+conv_32s_to_32sd_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
286
        uint32_t n_samples)
287
 {
288
    const float *s = src0;
289
@@ -986,8 +985,9 @@
290
    uint32_t n, unrolled;
291
    __m128 in2;
292
    __m128i out2;
293
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
294
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
295
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
296
+   __m128 int_max = _mm_set1_ps(S16_MAX);
297
+        __m128 int_min = _mm_set1_ps(S16_MIN);
298
 
299
    if (SPA_IS_ALIGNED(s, 16))
300
        unrolled = n_samples & ~7;
301
@@ -995,16 +995,16 @@
302
        unrolled = 0;
303
 
304
    for(n = 0; n < unrolled; n += 8) {
305
-       in0 = _mm_mul_ps(_mm_load_ps(&sn), int_max);
306
-       in1 = _mm_mul_ps(_mm_load_ps(&sn+4), int_max);
307
-       out0 = _mm_cvtps_epi32(in0);
308
-       out1 = _mm_cvtps_epi32(in1);
309
+       in0 = _mm_mul_ps(_mm_load_ps(&sn), int_scale);
310
+       in1 = _mm_mul_ps(_mm_load_ps(&sn+4), int_scale);
311
+       out0 = _mm_cvttps_epi32(in0);
312
+       out1 = _mm_cvttps_epi32(in1);
313
        out0 = _mm_packs_epi32(out0, out1);
314
        _mm_storeu_si128((__m128i*)(d+0), out0);
315
        d += 8;
316
    }
317
    for(; n < n_samples; n++) {
318
-       in0 = _mm_mul_ss(_mm_load_ss(&sn), int_max);
319
+       in0 = _mm_mul_ss(_mm_load_ss(&sn), int_scale);
320
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
321
        *d++ = _mm_cvtss_si32(in0);
322
    }
323
@@ -1035,8 +1035,9 @@
324
    uint32_t n, unrolled;
325
    __m128 in2;
326
    __m128i out2;
327
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
328
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
329
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
330
+   __m128 int_max = _mm_set1_ps(S16_MAX);
331
+        __m128 int_min = _mm_set1_ps(S16_MIN);
332
 
333
    if (SPA_IS_ALIGNED(s0, 16))
334
        unrolled = n_samples & ~7;
335
@@ -1044,10 +1045,10 @@
336
        unrolled = 0;
337
 
338
    for(n = 0; n < unrolled; n += 8) {
339
-       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_max);
340
-       in1 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_max);
341
-       out0 = _mm_cvtps_epi32(in0);
342
-       out1 = _mm_cvtps_epi32(in1);
343
+       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_scale);
344
+       in1 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_scale);
345
+       out0 = _mm_cvttps_epi32(in0);
346
+       out1 = _mm_cvttps_epi32(in1);
347
        out0 = _mm_packs_epi32(out0, out1);
348
 
349
        d0*n_channels = _mm_extract_epi16(out0, 0);
350
@@ -1061,9 +1062,9 @@
351
        d += 8*n_channels;
352
    }
353
    for(; n < n_samples; n++) {
354
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
355
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
356
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
357
-       *d = _mm_cvtss_si32(in0);
358
+       *d = _mm_cvttss_si32(in0);
359
        d += n_channels;
360
    }
361
 }
362
@@ -1077,8 +1078,9 @@
363
    uint32_t n, unrolled;
364
    __m128 in2;
365
    __m128i out4, t2;
366
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
367
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
368
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
369
+   __m128 int_max = _mm_set1_ps(S16_MAX);
370
+        __m128 int_min = _mm_set1_ps(S16_MIN);
371
 
372
    if (SPA_IS_ALIGNED(s0, 16) &&
373
        SPA_IS_ALIGNED(s1, 16))
374
@@ -1087,11 +1089,11 @@
375
        unrolled = 0;
376
 
377
    for(n = 0; n < unrolled; n += 4) {
378
-       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_max);
379
-       in1 = _mm_mul_ps(_mm_load_ps(&s1n), int_max);
380
+       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_scale);
381
+       in1 = _mm_mul_ps(_mm_load_ps(&s1n), int_scale);
382
 
383
-       t0 = _mm_cvtps_epi32(in0);
384
-       t1 = _mm_cvtps_epi32(in1);
385
+       t0 = _mm_cvttps_epi32(in0);
386
+       t1 = _mm_cvttps_epi32(in1);
387
 
388
        t0 = _mm_packs_epi32(t0, t0);
389
        t1 = _mm_packs_epi32(t1, t1);
390
@@ -1108,8 +1110,8 @@
391
        d += 4*n_channels;
392
    }
393
    for(; n < n_samples; n++) {
394
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
395
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
396
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
397
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
398
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
399
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
400
        d0 = _mm_cvtss_si32(in0);
401
@@ -1127,8 +1129,9 @@
402
    uint32_t n, unrolled;
403
    __m128 in4;
404
    __m128i out4, t4;
405
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
406
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
407
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
408
+   __m128 int_max = _mm_set1_ps(S16_MAX);
409
+        __m128 int_min = _mm_set1_ps(S16_MIN);
410
 
411
    if (SPA_IS_ALIGNED(s0, 16) &&
412
        SPA_IS_ALIGNED(s1, 16) &&
413
@@ -1139,15 +1142,15 @@
414
        unrolled = 0;
415
 
416
    for(n = 0; n < unrolled; n += 4) {
417
-       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_max);
418
-       in1 = _mm_mul_ps(_mm_load_ps(&s1n), int_max);
419
-       in2 = _mm_mul_ps(_mm_load_ps(&s2n), int_max);
420
-       in3 = _mm_mul_ps(_mm_load_ps(&s3n), int_max);
421
+       in0 = _mm_mul_ps(_mm_load_ps(&s0n), int_scale);
422
+       in1 = _mm_mul_ps(_mm_load_ps(&s1n), int_scale);
423
+       in2 = _mm_mul_ps(_mm_load_ps(&s2n), int_scale);
424
+       in3 = _mm_mul_ps(_mm_load_ps(&s3n), int_scale);
425
 
426
-       t0 = _mm_cvtps_epi32(in0);
427
-       t1 = _mm_cvtps_epi32(in1);
428
-       t2 = _mm_cvtps_epi32(in2);
429
-       t3 = _mm_cvtps_epi32(in3);
430
+       t0 = _mm_cvttps_epi32(in0);
431
+       t1 = _mm_cvttps_epi32(in1);
432
+       t2 = _mm_cvttps_epi32(in2);
433
+       t3 = _mm_cvttps_epi32(in3);
434
 
435
        t0 = _mm_packs_epi32(t0, t2);
436
        t1 = _mm_packs_epi32(t1, t3);
437
@@ -1165,10 +1168,10 @@
438
        d += 4*n_channels;
439
    }
440
    for(; n < n_samples; n++) {
441
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
442
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
443
-       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_max);
444
-       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_max);
445
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
446
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
447
+       in2 = _mm_mul_ss(_mm_load_ss(&s2n), int_scale);
448
+       in3 = _mm_mul_ss(_mm_load_ss(&s3n), int_scale);
449
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
450
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
451
        in2 = _mm_min_ss(int_max, _mm_max_ss(in2, int_min));
452
@@ -1205,8 +1208,9 @@
453
    uint32_t n, unrolled;
454
    __m128 in4;
455
    __m128i out4;
456
-   __m128 int_max = _mm_set1_ps(S16_MAX_F);
457
-        __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
458
+   __m128 int_scale = _mm_set1_ps(S16_SCALE);
459
+   __m128 int_max = _mm_set1_ps(S16_MAX);
460
+        __m128 int_min = _mm_set1_ps(S16_MIN);
461
 
462
    if (SPA_IS_ALIGNED(s0, 16) &&
463
        SPA_IS_ALIGNED(s1, 16))
464
@@ -1215,15 +1219,15 @@
465
        unrolled = 0;
466
 
467
    for(n = 0; n < unrolled; n += 8) {
468
-       in0 = _mm_mul_ps(_mm_load_ps(&s0n+0), int_max);
469
-       in1 = _mm_mul_ps(_mm_load_ps(&s1n+0), int_max);
470
-       in2 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_max);
471
-       in3 = _mm_mul_ps(_mm_load_ps(&s1n+4), int_max);
472
+       in0 = _mm_mul_ps(_mm_load_ps(&s0n+0), int_scale);
473
+       in1 = _mm_mul_ps(_mm_load_ps(&s1n+0), int_scale);
474
+       in2 = _mm_mul_ps(_mm_load_ps(&s0n+4), int_scale);
475
+       in3 = _mm_mul_ps(_mm_load_ps(&s1n+4), int_scale);
476
 
477
-       out0 = _mm_cvtps_epi32(in0);
478
-       out1 = _mm_cvtps_epi32(in1);
479
-       out2 = _mm_cvtps_epi32(in2);
480
-       out3 = _mm_cvtps_epi32(in3);
481
+       out0 = _mm_cvttps_epi32(in0);
482
+       out1 = _mm_cvttps_epi32(in1);
483
+       out2 = _mm_cvttps_epi32(in2);
484
+       out3 = _mm_cvttps_epi32(in3);
485
 
486
        out0 = _mm_packs_epi32(out0, out2);
487
        out1 = _mm_packs_epi32(out1, out3);
488
@@ -1237,8 +1241,8 @@
489
        d += 16;
490
    }
491
    for(; n < n_samples; n++) {
492
-       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_max);
493
-       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_max);
494
+       in0 = _mm_mul_ss(_mm_load_ss(&s0n), int_scale);
495
+       in1 = _mm_mul_ss(_mm_load_ss(&s1n), int_scale);
496
        in0 = _mm_min_ss(int_max, _mm_max_ss(in0, int_min));
497
        in1 = _mm_min_ss(int_max, _mm_max_ss(in1, int_min));
498
        d0 = _mm_cvtss_si32(in0);
499
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops-sse41.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops-sse41.c Changed
38
 
1
@@ -30,7 +30,7 @@
2
 conv_s24_to_f32d_1s_sse41(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
3
        uint32_t n_channels, uint32_t n_samples)
4
 {
5
-   const uint8_t *s = src;
6
+   const int24_t *s = src;
7
    float *d0 = dst0;
8
    uint32_t n, unrolled;
9
    __m128i in = _mm_setzero_si128();
10
@@ -43,21 +43,21 @@
11
 
12
    for(n = 0; n < unrolled; n += 4) {
13
        in = _mm_insert_epi32(in, *((uint32_t*)&s0 * n_channels), 0);
14
-       in = _mm_insert_epi32(in, *((uint32_t*)&s3 * n_channels), 1);
15
-       in = _mm_insert_epi32(in, *((uint32_t*)&s6 * n_channels), 2);
16
-       in = _mm_insert_epi32(in, *((uint32_t*)&s9 * n_channels), 3);
17
+       in = _mm_insert_epi32(in, *((uint32_t*)&s1 * n_channels), 1);
18
+       in = _mm_insert_epi32(in, *((uint32_t*)&s2 * n_channels), 2);
19
+       in = _mm_insert_epi32(in, *((uint32_t*)&s3 * n_channels), 3);
20
        in = _mm_slli_epi32(in, 8);
21
        in = _mm_srai_epi32(in, 8);
22
        out = _mm_cvtepi32_ps(in);
23
        out = _mm_mul_ps(out, factor);
24
        _mm_store_ps(&d0n, out);
25
-       s += 12 * n_channels;
26
+       s += 4 * n_channels;
27
    }
28
    for(; n < n_samples; n++) {
29
-       out = _mm_cvtsi32_ss(factor, read_s24(s));
30
+       out = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
31
        out = _mm_mul_ss(out, factor);
32
        _mm_store_ss(&d0n, out);
33
-       s += 3 * n_channels;
34
+       s += n_channels;
35
    }
36
 }
37
 
38
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops-ssse3.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops-ssse3.c Changed
51
 
1
@@ -30,7 +30,7 @@
2
 conv_s24_to_f32d_4s_ssse3(void *data, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
3
        uint32_t n_channels, uint32_t n_samples)
4
 {
5
-   const uint8_t *s = src;
6
+   const int24_t *s = src;
7
    float *d0 = dst0, *d1 = dst1, *d2 = dst2, *d3 = dst3;
8
    uint32_t n, unrolled;
9
    __m128i in4;
10
@@ -48,9 +48,9 @@
11
 
12
    for(n = 0; n < unrolled; n += 4) {
13
                 in0 = _mm_loadu_si128((__m128i*)(s + 0*n_channels));
14
-                in1 = _mm_loadu_si128((__m128i*)(s + 3*n_channels));
15
-                in2 = _mm_loadu_si128((__m128i*)(s + 6*n_channels));
16
-                in3 = _mm_loadu_si128((__m128i*)(s + 9*n_channels));
17
+                in1 = _mm_loadu_si128((__m128i*)(s + 1*n_channels));
18
+                in2 = _mm_loadu_si128((__m128i*)(s + 2*n_channels));
19
+                in3 = _mm_loadu_si128((__m128i*)(s + 3*n_channels));
20
        in0 = _mm_shuffle_epi8(in0, mask);
21
        in1 = _mm_shuffle_epi8(in1, mask);
22
        in2 = _mm_shuffle_epi8(in2, mask);
23
@@ -74,13 +74,13 @@
24
        _mm_store_ps(&d1n, out1);
25
        _mm_store_ps(&d2n, out2);
26
        _mm_store_ps(&d3n, out3);
27
-       s += 12 * n_channels;
28
+       s += 4 * n_channels;
29
    }
30
    for(; n < n_samples; n++) {
31
-       out0 = _mm_cvtsi32_ss(factor, read_s24(s));
32
-       out1 = _mm_cvtsi32_ss(factor, read_s24(s+3));
33
-       out2 = _mm_cvtsi32_ss(factor, read_s24(s+6));
34
-       out3 = _mm_cvtsi32_ss(factor, read_s24(s+9));
35
+       out0 = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
36
+       out1 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+1)));
37
+       out2 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+2)));
38
+       out3 = _mm_cvtsi32_ss(factor, s24_to_s32(*(s+3)));
39
        out0 = _mm_mul_ss(out0, factor);
40
        out1 = _mm_mul_ss(out1, factor);
41
        out2 = _mm_mul_ss(out2, factor);
42
@@ -89,7 +89,7 @@
43
        _mm_store_ss(&d1n, out1);
44
        _mm_store_ss(&d2n, out2);
45
        _mm_store_ss(&d3n, out3);
46
-       s += 3 * n_channels;
47
+       s += n_channels;
48
    }
49
 }
50
 
51
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops.c Changed
110
 
1
@@ -96,22 +96,22 @@
2
    MAKE(F32, F32, 0, conv_copy32_c),
3
    MAKE(F32P, F32P, 0, conv_copy32d_c),
4
 #if defined (HAVE_SSE2)
5
-   MAKE(F32, F32P, 0, conv_deinterleave_32_sse2, SPA_CPU_FLAG_SSE2),
6
+   MAKE(F32, F32P, 0, conv_32_to_32d_sse2, SPA_CPU_FLAG_SSE2),
7
 #endif
8
-   MAKE(F32, F32P, 0, conv_deinterleave_32_c),
9
+   MAKE(F32, F32P, 0, conv_32_to_32d_c),
10
 #if defined (HAVE_SSE2)
11
-   MAKE(F32P, F32, 0, conv_interleave_32_sse2, SPA_CPU_FLAG_SSE2),
12
+   MAKE(F32P, F32, 0, conv_32d_to_32_sse2, SPA_CPU_FLAG_SSE2),
13
 #endif
14
-   MAKE(F32P, F32, 0, conv_interleave_32_c),
15
+   MAKE(F32P, F32, 0, conv_32d_to_32_c),
16
 
17
 #if defined (HAVE_SSE2)
18
-   MAKE(F32_OE, F32P, 0, conv_deinterleave_32s_sse2, SPA_CPU_FLAG_SSE2),
19
+   MAKE(F32_OE, F32P, 0, conv_32s_to_32sd_sse2, SPA_CPU_FLAG_SSE2),
20
 #endif
21
-   MAKE(F32_OE, F32P, 0, conv_deinterleave_32s_c),
22
+   MAKE(F32_OE, F32P, 0, conv_32s_to_32sd_c),
23
 #if defined (HAVE_SSE2)
24
-   MAKE(F32P, F32_OE, 0, conv_interleave_32s_sse2, SPA_CPU_FLAG_SSE2),
25
+   MAKE(F32P, F32_OE, 0, conv_32sd_to_32s_sse2, SPA_CPU_FLAG_SSE2),
26
 #endif
27
-   MAKE(F32P, F32_OE, 0, conv_interleave_32s_c),
28
+   MAKE(F32P, F32_OE, 0, conv_32sd_to_32s_c),
29
 
30
    MAKE(U32, F32, 0, conv_u32_to_f32_c),
31
    MAKE(U32, F32P, 0, conv_u32_to_f32d_c),
32
@@ -287,14 +287,14 @@
33
    /* u8 */
34
    MAKE(U8, U8, 0, conv_copy8_c),
35
    MAKE(U8P, U8P, 0, conv_copy8d_c),
36
-   MAKE(U8, U8P, 0, conv_deinterleave_8_c),
37
-   MAKE(U8P, U8, 0, conv_interleave_8_c),
38
+   MAKE(U8, U8P, 0, conv_8_to_8d_c),
39
+   MAKE(U8P, U8, 0, conv_8d_to_8_c),
40
 
41
    /* s8 */
42
    MAKE(S8, S8, 0, conv_copy8_c),
43
    MAKE(S8P, S8P, 0, conv_copy8d_c),
44
-   MAKE(S8, S8P, 0, conv_deinterleave_8_c),
45
-   MAKE(S8P, S8, 0, conv_interleave_8_c),
46
+   MAKE(S8, S8P, 0, conv_8_to_8d_c),
47
+   MAKE(S8P, S8, 0, conv_8d_to_8_c),
48
 
49
    /* alaw */
50
    MAKE(ALAW, ALAW, 0, conv_copy8_c),
51
@@ -304,44 +304,44 @@
52
    /* s16 */
53
    MAKE(S16, S16, 0, conv_copy16_c),
54
    MAKE(S16P, S16P, 0, conv_copy16d_c),
55
-   MAKE(S16, S16P, 0, conv_deinterleave_16_c),
56
-   MAKE(S16P, S16, 0, conv_interleave_16_c),
57
+   MAKE(S16, S16P, 0, conv_16_to_16d_c),
58
+   MAKE(S16P, S16, 0, conv_16d_to_16_c),
59
 
60
    /* s32 */
61
    MAKE(S32, S32, 0, conv_copy32_c),
62
    MAKE(S32P, S32P, 0, conv_copy32d_c),
63
 #if defined (HAVE_SSE2)
64
-   MAKE(S32, S32P, 0, conv_deinterleave_32_sse2, SPA_CPU_FLAG_SSE2),
65
+   MAKE(S32, S32P, 0, conv_32_to_32d_sse2, SPA_CPU_FLAG_SSE2),
66
 #endif
67
-   MAKE(S32, S32P, 0, conv_deinterleave_32_c),
68
+   MAKE(S32, S32P, 0, conv_32_to_32d_c),
69
 #if defined (HAVE_SSE2)
70
-   MAKE(S32P, S32, 0, conv_interleave_32_sse2, SPA_CPU_FLAG_SSE2),
71
+   MAKE(S32P, S32, 0, conv_32d_to_32_sse2, SPA_CPU_FLAG_SSE2),
72
 #endif
73
-   MAKE(S32P, S32, 0, conv_interleave_32_c),
74
+   MAKE(S32P, S32, 0, conv_32d_to_32_c),
75
 
76
    /* s24 */
77
    MAKE(S24, S24, 0, conv_copy24_c),
78
    MAKE(S24P, S24P, 0, conv_copy24d_c),
79
-   MAKE(S24, S24P, 0, conv_deinterleave_24_c),
80
-   MAKE(S24P, S24, 0, conv_interleave_24_c),
81
+   MAKE(S24, S24P, 0, conv_24_to_24d_c),
82
+   MAKE(S24P, S24, 0, conv_24d_to_24_c),
83
 
84
    /* s24_32 */
85
    MAKE(S24_32, S24_32, 0, conv_copy32_c),
86
    MAKE(S24_32P, S24_32P, 0, conv_copy32d_c),
87
 #if defined (HAVE_SSE2)
88
-   MAKE(S24_32, S24_32P, 0, conv_deinterleave_32_sse2, SPA_CPU_FLAG_SSE2),
89
+   MAKE(S24_32, S24_32P, 0, conv_32_to_32d_sse2, SPA_CPU_FLAG_SSE2),
90
 #endif
91
-   MAKE(S24_32, S24_32P, 0, conv_deinterleave_32_c),
92
+   MAKE(S24_32, S24_32P, 0, conv_32_to_32d_c),
93
 #if defined (HAVE_SSE2)
94
-   MAKE(S24_32P, S24_32, 0, conv_interleave_32_sse2, SPA_CPU_FLAG_SSE2),
95
+   MAKE(S24_32P, S24_32, 0, conv_32d_to_32_sse2, SPA_CPU_FLAG_SSE2),
96
 #endif
97
-   MAKE(S24_32P, S24_32, 0, conv_interleave_32_c),
98
+   MAKE(S24_32P, S24_32, 0, conv_32d_to_32_c),
99
 
100
    /* F64 */
101
    MAKE(F64, F64, 0, conv_copy64_c),
102
    MAKE(F64P, F64P, 0, conv_copy64d_c),
103
-   MAKE(F64, F64P, 0, conv_deinterleave_64_c),
104
-   MAKE(F64P, F64, 0, conv_interleave_64_c),
105
+   MAKE(F64, F64P, 0, conv_64_to_64d_c),
106
+   MAKE(F64P, F64, 0, conv_64d_to_64_c),
107
 };
108
 #undef MAKE
109
 
110
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/fmt-ops.h -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/fmt-ops.h Changed
287
 
1
@@ -39,35 +39,33 @@
2
 
3
 #define U8_MIN         0u
4
 #define U8_MAX         255u
5
-#define U8_SCALE       127.5f
6
+#define U8_SCALE       128.f
7
 #define U8_OFFS            128.f
8
-#define U8_TO_F32(v)       ((((uint8_t)(v)) * (1.0f / U8_OFFS)) - 1.0f)
9
+#define U8_TO_F32(v)       ((((uint8_t)(v)) * (1.0f / U8_SCALE)) - 1.0f)
10
 #define F32_TO_U8(v)       (uint8_t)SPA_CLAMP((v) * U8_SCALE + U8_OFFS, U8_MIN, U8_MAX)
11
 #define F32_TO_U8_D(v,d)   (uint8_t)SPA_CLAMP((v) * U8_SCALE + U8_OFFS + (d), U8_MIN, U8_MAX)
12
 
13
-#define S8_MIN         -127
14
+#define S8_MIN         -128
15
 #define S8_MAX         127
16
-#define S8_MAX_F       127.0f
17
-#define S8_SCALE       127.0f
18
+#define S8_SCALE       128.0f
19
 #define S8_TO_F32(v)       (((int8_t)(v)) * (1.0f / S8_SCALE))
20
 #define F32_TO_S8(v)       (int8_t)SPA_CLAMP((v) * S8_SCALE, S8_MIN, S8_MAX)
21
 #define F32_TO_S8_D(v,d)   (int8_t)SPA_CLAMP((v) * S8_SCALE + (d), S8_MIN, S8_MAX)
22
 
23
 #define U16_MIN            0u
24
 #define U16_MAX            65535u
25
-#define U16_SCALE      32767.5f
26
+#define U16_SCALE      32768.f
27
 #define U16_OFFS       32768.f
28
-#define U16_TO_F32(v)      ((((uint16_t)(v)) * (1.0f / U16_OFFS)) - 1.0)
29
-#define U16S_TO_F32(v)     (((uint16_t)bswap_16((uint16_t)(v)) * (1.0f / U16_OFFS)) - 1.0)
30
+#define U16_TO_F32(v)      ((((uint16_t)(v)) * (1.0f / U16_SCALE)) - 1.0f)
31
+#define U16S_TO_F32(v)     (((uint16_t)bswap_16((uint16_t)(v)) * (1.0f / U16_OFFS)) - 1.0f)
32
 #define F32_TO_U16(v)      (uint16_t)SPA_CLAMP((v) * U16_SCALE + U16_OFFS, U16_MIN, U16_MAX)
33
 #define F32_TO_U16_D(v,d)  (uint16_t)SPA_CLAMP((v) * U16_SCALE + U16_OFFS + (d), U16_MIN, U16_MAX)
34
 #define F32_TO_U16S(v)     bswap_16(F32_TO_U16(v))
35
 #define F32_TO_U16S_D(v,d) bswap_16(F32_TO_U16_D(v,d))
36
 
37
-#define S16_MIN            -32767
38
+#define S16_MIN            -32768
39
 #define S16_MAX            32767
40
-#define S16_MAX_F      32767.0f
41
-#define S16_SCALE      32767.0f
42
+#define S16_SCALE      32768.0f
43
 #define S16_TO_F32(v)      (((int16_t)(v)) * (1.0f / S16_SCALE))
44
 #define S16S_TO_F32(v)     (((int16_t)bswap_16(v)) * (1.0f / S16_SCALE))
45
 #define F32_TO_S16(v)      (int16_t)SPA_CLAMP((v) * S16_SCALE, S16_MIN, S16_MAX)
46
@@ -77,31 +75,31 @@
47
 
48
 #define U24_MIN            0u
49
 #define U24_MAX            16777215u
50
-#define U24_SCALE      8388607.5f
51
+#define U24_SCALE      8388608.f
52
 #define U24_OFFS       8388608.f
53
-#define U24_TO_F32(v)      ((((uint32_t)(v)) * (1.0f / U24_OFFS)) - 1.0)
54
-#define F32_TO_U24(v)      (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS, U24_MIN, U24_MAX)
55
-#define F32_TO_U24_D(v,d)  (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS + (d), U24_MIN, U24_MAX)
56
+#define U24_TO_F32(v)      ((u24_to_u32(v) * (1.0f / U24_SCALE)) - 1.0f)
57
+#define F32_TO_U24(v)      u32_to_u24(SPA_CLAMP((v) * U24_SCALE + U24_OFFS, U24_MIN, U24_MAX))
58
+#define F32_TO_U24_D(v,d)  u32_to_u24(SPA_CLAMP((v) * U24_SCALE + U24_OFFS + (d), U24_MIN, U24_MAX))
59
 
60
-#define S24_MIN            -8388607
61
+#define S24_MIN            -8388608
62
 #define S24_MAX            8388607
63
-#define S24_MAX_F      8388607.0f
64
-#define S24_SCALE      8388607.0f
65
-#define S24_TO_F32(v)      (((int32_t)(v)) * (1.0f / S24_SCALE))
66
-#define F32_TO_S24(v)      (int32_t)SPA_CLAMP((v) * S24_SCALE, S24_MIN, S24_MAX)
67
-#define F32_TO_S24_D(v,d)  (int32_t)SPA_CLAMP((v) * S24_SCALE + (d), S24_MIN, S24_MAX)
68
+#define S24_SCALE      8388608.0f
69
+#define S24_TO_F32(v)      (s24_to_s32(v) * (1.0f / S24_SCALE))
70
+#define S24S_TO_F32(v)     (s24_to_s32(bswap_s24(v)) * (1.0f / S24_SCALE))
71
+#define F32_TO_S24(v)      s32_to_s24(SPA_CLAMP((v) * S24_SCALE, S24_MIN, S24_MAX))
72
+#define F32_TO_S24S(v)     bswap_s24(F32_TO_S24(v))
73
+#define F32_TO_S24_D(v,d)  s32_to_s24(SPA_CLAMP((v) * S24_SCALE + (d), S24_MIN, S24_MAX))
74
 
75
 #define U32_MIN            0u
76
-#define U32_MAX            4294967040u
77
-#define U32_SCALE      2147483520.f
78
-#define U32_OFFS       2147483520.f
79
-#define U32_TO_F32(v)      ((((uint32_t)(v)) * (1.0f / U32_OFFS)) - 1.0)
80
+#define U32_MAX            4294967295
81
+#define U32_SCALE      2147483648.f
82
+#define U32_OFFS       2147483648.f
83
+#define U32_TO_F32(v)      ((((uint32_t)(v)) * (1.0f / U32_SCALE)) - 1.0f)
84
 #define F32_TO_U32(v)      (uint32_t)SPA_CLAMP((v) * U32_SCALE + U32_OFFS, U32_MIN, U32_MAX)
85
 #define F32_TO_U32_D(v,d)  (uint32_t)SPA_CLAMP((v) * U32_SCALE + U32_OFFS + (d), U32_MIN, U32_MAX)
86
 
87
-#define S32_MIN            -2147483520
88
+#define S32_MIN            -2147483648
89
 #define S32_MAX            2147483520
90
-#define S32_MAX_F      2147483520.f
91
 #define S32_SCALE      2147483648.f
92
 #define S32_TO_F32(v)      (((int32_t)(v)) * (1.0f / S32_SCALE))
93
 #define S32S_TO_F32(v)     (((int32_t)bswap_32(v)) * (1.0f / S32_SCALE))
94
@@ -112,88 +110,75 @@
95
 
96
 #define U24_32_TO_F32(v)   U32_TO_F32((v)<<8)
97
 #define U24_32S_TO_F32(v)  U32_TO_F32(((int32_t)bswap_32(v))<<8)
98
-#define F32_TO_U24_32(v)   F32_TO_U24(v)
99
-#define F32_TO_U24_32S(v)  bswap_32(F32_TO_U24(v))
100
-#define F32_TO_U24_32_D(v,d)   F32_TO_U24_D(v,d)
101
-#define F32_TO_U24_32S_D(v,d)  bswap_32(F32_TO_U24_D(v,d))
102
+#define F32_TO_U24_32(v)   (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS, U24_MIN, U24_MAX)
103
+#define F32_TO_U24_32S(v)  bswap_32(F32_TO_U24_32(v))
104
+#define F32_TO_U24_32_D(v,d)   (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS + (d), U24_MIN, U24_MAX)
105
+#define F32_TO_U24_32S_D(v,d)  bswap_32(F32_TO_U24_32_D(v,d))
106
 
107
 #define S24_32_TO_F32(v)   S32_TO_F32((v)<<8)
108
 #define S24_32S_TO_F32(v)  S32_TO_F32(((int32_t)bswap_32(v))<<8)
109
-#define F32_TO_S24_32(v)   F32_TO_S24(v)
110
-#define F32_TO_S24_32S(v)  bswap_32(F32_TO_S24(v))
111
-#define F32_TO_S24_32_D(v,d)   F32_TO_S24_D(v,d)
112
-#define F32_TO_S24_32S_D(v,d)  bswap_32(F32_TO_S24_D(v,d))
113
+#define F32_TO_S24_32(v)   (int32_t)SPA_CLAMP((v) * S24_SCALE, S24_MIN, S24_MAX)
114
+#define F32_TO_S24_32S(v)  bswap_32(F32_TO_S24_32(v))
115
+#define F32_TO_S24_32_D(v,d)   (int32_t)SPA_CLAMP((v) * S24_SCALE + (d), S24_MIN, S24_MAX)
116
+#define F32_TO_S24_32S_D(v,d)  bswap_32(F32_TO_S24_32_D(v,d))
117
 
118
-static inline uint32_t read_u24(const void *src)
119
-{
120
-   const uint8_t *s = src;
121
+typedef struct {
122
 #if __BYTE_ORDER == __LITTLE_ENDIAN
123
-   return (((uint32_t)s2 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s0);
124
+   uint8_t v3;
125
+   uint8_t v2;
126
+   uint8_t v1;
127
 #else
128
-   return (((uint32_t)s0 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s2);
129
+   uint8_t v1;
130
+   uint8_t v2;
131
+   uint8_t v3;
132
 #endif
133
-}
134
+} __attribute__ ((packed)) uint24_t;
135
 
136
-static inline int32_t read_s24(const void *src)
137
-{
138
-   const int8_t *s = src;
139
+typedef struct {
140
 #if __BYTE_ORDER == __LITTLE_ENDIAN
141
-   return (((int32_t)s2 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s0);
142
+   uint8_t v3;
143
+   uint8_t v2;
144
+   int8_t v1;
145
 #else
146
-   return (((int32_t)s0 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s2);
147
+   int8_t v1;
148
+   uint8_t v2;
149
+   uint8_t v3;
150
 #endif
151
+} __attribute__ ((packed)) int24_t;
152
+
153
+static inline uint32_t u24_to_u32(uint24_t src)
154
+{
155
+   return ((uint32_t)src.v1 << 16) | ((uint32_t)src.v2 << 8) | (uint32_t)src.v3;
156
 }
157
 
158
-static inline int32_t read_s24s(const void *src)
159
+#define U32_TO_U24(s) (uint24_t) { .v1 = (uint8_t)(((uint32_t)s) >> 16), \
160
+   .v2 = (uint8_t)(((uint32_t)s) >> 8), .v3 = (uint8_t)((uint32_t)s) }
161
+
162
+static inline uint24_t u32_to_u24(uint32_t src)
163
 {
164
-   const int8_t *s = src;
165
-#if __BYTE_ORDER == __LITTLE_ENDIAN
166
-   return (((int32_t)s0 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s2);
167
-#else
168
-   return (((int32_t)s2 << 16) | ((uint32_t)(uint8_t)s1 << 8) | (uint32_t)(uint8_t)s0);
169
-#endif
170
+   return U32_TO_U24(src);
171
 }
172
 
173
-static inline void write_u24(void *dst, uint32_t val)
174
+static inline int32_t s24_to_s32(int24_t src)
175
 {
176
-   uint8_t *d = dst;
177
-#if __BYTE_ORDER == __LITTLE_ENDIAN
178
-   d0 = (uint8_t) (val);
179
-   d1 = (uint8_t) (val >> 8);
180
-   d2 = (uint8_t) (val >> 16);
181
-#else
182
-   d0 = (uint8_t) (val >> 16);
183
-   d1 = (uint8_t) (val >> 8);
184
-   d2 = (uint8_t) (val);
185
-#endif
186
+   return ((int32_t)src.v1 << 16) | ((uint32_t)src.v2 << 8) | (uint32_t)src.v3;
187
 }
188
 
189
-static inline void write_s24(void *dst, int32_t val)
190
+#define S32_TO_S24(s) (int24_t) { .v1 = (int8_t)(((int32_t)s) >> 16), \
191
+   .v2 = (uint8_t)(((uint32_t)s) >> 8), .v3 = (uint8_t)((uint32_t)s) }
192
+
193
+static inline int24_t s32_to_s24(int32_t src)
194
 {
195
-   uint8_t *d = dst;
196
-#if __BYTE_ORDER == __LITTLE_ENDIAN
197
-   d0 = (uint8_t) (val);
198
-   d1 = (uint8_t) (val >> 8);
199
-   d2 = (uint8_t) (val >> 16);
200
-#else
201
-   d0 = (uint8_t) (val >> 16);
202
-   d1 = (uint8_t) (val >> 8);
203
-   d2 = (uint8_t) (val);
204
-#endif
205
+   return S32_TO_S24(src);
206
 }
207
 
208
-static inline void write_s24s(void *dst, int32_t val)
209
+static inline uint24_t bswap_u24(uint24_t src)
210
 {
211
-   uint8_t *d = dst;
212
-#if __BYTE_ORDER == __LITTLE_ENDIAN
213
-   d0 = (uint8_t) (val >> 16);
214
-   d1 = (uint8_t) (val >> 8);
215
-   d2 = (uint8_t) (val);
216
-#else
217
-   d0 = (uint8_t) (val);
218
-   d1 = (uint8_t) (val >> 8);
219
-   d2 = (uint8_t) (val >> 16);
220
-#endif
221
+   return (uint24_t) { .v1 = src.v3, .v2 = src.v2, .v3 = src.v1 };
222
+}
223
+static inline int24_t bswap_s24(int24_t src)
224
+{
225
+   return (int24_t) { .v1 = src.v3, .v2 = src.v2, .v3 = src.v1 };
226
 }
227
 
228
 #define NS_MAX 8
229
@@ -206,7 +191,6 @@
230
 };
231
 
232
 struct convert {
233
-   uint32_t quantize;
234
    uint32_t noise;
235
 #define DITHER_METHOD_NONE     0
236
 #define DITHER_METHOD_RECTANGULAR  1
237
@@ -383,20 +367,20 @@
238
 DEFINE_FUNCTION(f32_to_f64d, c);
239
 DEFINE_FUNCTION(f32d_to_f64, c);
240
 DEFINE_FUNCTION(f32d_to_f64s, c);
241
-DEFINE_FUNCTION(deinterleave_8, c);
242
-DEFINE_FUNCTION(deinterleave_16, c);
243
-DEFINE_FUNCTION(deinterleave_24, c);
244
-DEFINE_FUNCTION(deinterleave_32, c);
245
-DEFINE_FUNCTION(deinterleave_32s, c);
246
-DEFINE_FUNCTION(deinterleave_64, c);
247
-DEFINE_FUNCTION(deinterleave_64s, c);
248
-DEFINE_FUNCTION(interleave_8, c);
249
-DEFINE_FUNCTION(interleave_16, c);
250
-DEFINE_FUNCTION(interleave_24, c);
251
-DEFINE_FUNCTION(interleave_32, c);
252
-DEFINE_FUNCTION(interleave_32s, c);
253
-DEFINE_FUNCTION(interleave_64, c);
254
-DEFINE_FUNCTION(interleave_64s, c);
255
+DEFINE_FUNCTION(8_to_8d, c);
256
+DEFINE_FUNCTION(16_to_16d, c);
257
+DEFINE_FUNCTION(24_to_24d, c);
258
+DEFINE_FUNCTION(32_to_32d, c);
259
+DEFINE_FUNCTION(32s_to_32sd, c);
260
+DEFINE_FUNCTION(64_to_64d, c);
261
+DEFINE_FUNCTION(64s_to_64sd, c);
262
+DEFINE_FUNCTION(8d_to_8, c);
263
+DEFINE_FUNCTION(16d_to_16, c);
264
+DEFINE_FUNCTION(24d_to_24, c);
265
+DEFINE_FUNCTION(32d_to_32, c);
266
+DEFINE_FUNCTION(32sd_to_32s, c);
267
+DEFINE_FUNCTION(64d_to_64, c);
268
+DEFINE_FUNCTION(64sd_to_64s, c);
269
 
270
 #if defined(HAVE_NEON)
271
 DEFINE_FUNCTION(s16_to_f32d_2, neon);
272
@@ -414,10 +398,10 @@
273
 DEFINE_FUNCTION(f32d_to_s16_2, sse2);
274
 DEFINE_FUNCTION(f32d_to_s16, sse2);
275
 DEFINE_FUNCTION(f32d_to_s16d, sse2);
276
-DEFINE_FUNCTION(deinterleave_32, sse2);
277
-DEFINE_FUNCTION(deinterleave_32s, sse2);
278
-DEFINE_FUNCTION(interleave_32, sse2);
279
-DEFINE_FUNCTION(interleave_32s, sse2);
280
+DEFINE_FUNCTION(32_to_32d, sse2);
281
+DEFINE_FUNCTION(32s_to_32sd, sse2);
282
+DEFINE_FUNCTION(32d_to_32, sse2);
283
+DEFINE_FUNCTION(32sd_to_32s, sse2);
284
 #endif
285
 #if defined(HAVE_SSSE3)
286
 DEFINE_FUNCTION(s24_to_f32d, ssse3);
287
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/resample-native.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/resample-native.c Changed
44
 
1
@@ -58,23 +58,24 @@
2
    return sin(x) / x;
3
 }
4
 
5
-#if 0
6
 static inline double window_blackman(double x, double n_taps)
7
 {
8
-   double alpha = 0.232;
9
+   double alpha = 0.232, r;
10
    x =  2.0 * M_PI * x / n_taps;
11
-   return (1.0 - alpha) / 2.0 + (1.0 / 2.0) * cos(x) +
12
-       (alpha / 2.0) * cos(2 * x);
13
+   r = (1.0 - alpha) / 2.0 + (1.0 / 2.0) * cos(x) +
14
+       (alpha / 2.0) * cos(2.0 * x);
15
+   return r;
16
 }
17
-#else
18
 static inline double window_cosh(double x, double n_taps)
19
 {
20
-   double R = 95.0;
21
+   double R = 190.0, r;
22
    double A = -325.1E-6 * (R * R) + 0.1677 * R - 3.149;
23
-   x =  2.0 * M_PI * x / n_taps;
24
-   return cosh(A * sqrt(1 - pow(x / M_PI, 2))) / cosh(A);
25
+   x =  2.0 * x / n_taps;
26
+   r = cosh(A * sqrt(1 - pow(x, 2))) / cosh(A);
27
+   return r;
28
 }
29
-#endif
30
+
31
+#define window window_blackman
32
 
33
 static int build_filter(float *taps, uint32_t stride, uint32_t n_taps, uint32_t n_phases, double cutoff)
34
 {
35
@@ -86,7 +87,7 @@
36
            /* exploit symmetry in filter taps */
37
            taps(n_phases - i) * stride + n_taps12 + j =
38
                tapsi * stride + (n_taps12 - j - 1) =
39
-                   cutoff * sinc(t * cutoff) * window_cosh(t, n_taps);
40
+                   cutoff * sinc(t * cutoff) * window(t, n_taps);
41
        }
42
    }
43
    return 0;
44
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/test-audioconvert.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/test-audioconvert.c Changed
392
 
1
@@ -36,6 +36,7 @@
2
 #include <spa/param/audio/format.h>
3
 #include <spa/param/audio/format-utils.h>
4
 #include <spa/node/node.h>
5
+#include <spa/node/io.h>
6
 #include <spa/debug/mem.h>
7
 #include <spa/support/log-impl.h>
8
 
9
@@ -71,6 +72,7 @@
10
    size_t size;
11
    int res;
12
    struct spa_support support1;
13
+   struct spa_dict_item items2;
14
    const struct spa_handle_factory *factory;
15
    void *iface;
16
 
17
@@ -86,9 +88,11 @@
18
    ctx->convert_handle = calloc(1, size);
19
    spa_assert_se(ctx->convert_handle != NULL);
20
 
21
+   items0 = SPA_DICT_ITEM_INIT("clock.quantum-limit", "8192");
22
+
23
    res = spa_handle_factory_init(factory,
24
            ctx->convert_handle,
25
-           NULL,
26
+           &SPA_DICT_INIT(items, 1),
27
            support, 1);
28
    spa_assert_se(res >= 0);
29
 
30
@@ -510,6 +514,351 @@
31
    return 0;
32
 }
33
 
34
+static int setup_direction(struct context *ctx, enum spa_direction direction, uint32_t mode,
35
+       struct spa_audio_info_raw *info)
36
+{
37
+   struct spa_pod_builder b = { 0 };
38
+   uint8_t buffer1024;
39
+   struct spa_pod *param, *format;
40
+   int res;
41
+   uint32_t i;
42
+
43
+   spa_pod_builder_init(&b, buffer, sizeof(buffer));
44
+   format = spa_format_audio_raw_build(&b, SPA_PARAM_Format, info);
45
+
46
+   switch (mode) {
47
+   case SPA_PARAM_PORT_CONFIG_MODE_dsp:
48
+       param = spa_pod_builder_add_object(&b,
49
+           SPA_TYPE_OBJECT_ParamPortConfig, SPA_PARAM_PortConfig,
50
+           SPA_PARAM_PORT_CONFIG_direction,    SPA_POD_Id(direction),
51
+           SPA_PARAM_PORT_CONFIG_mode,     SPA_POD_Id(mode),
52
+           SPA_PARAM_PORT_CONFIG_format,       SPA_POD_Pod(format));
53
+       break;
54
+
55
+   case SPA_PARAM_PORT_CONFIG_MODE_convert:
56
+       param = spa_pod_builder_add_object(&b,
57
+           SPA_TYPE_OBJECT_ParamPortConfig, SPA_PARAM_PortConfig,
58
+           SPA_PARAM_PORT_CONFIG_direction,    SPA_POD_Id(direction),
59
+           SPA_PARAM_PORT_CONFIG_mode,     SPA_POD_Id(mode));
60
+       break;
61
+   default:
62
+       return -EINVAL;
63
+   }
64
+   res = spa_node_set_param(ctx->convert_node, SPA_PARAM_PortConfig, 0, param);
65
+   spa_assert_se(res == 0);
66
+
67
+   switch (mode) {
68
+   case SPA_PARAM_PORT_CONFIG_MODE_convert:
69
+       res = spa_node_port_set_param(ctx->convert_node, direction, 0,
70
+           SPA_PARAM_Format, 0, format);
71
+       spa_assert_se(res == 0);
72
+       break;
73
+   case SPA_PARAM_PORT_CONFIG_MODE_dsp:
74
+       spa_pod_builder_init(&b, buffer, sizeof(buffer));
75
+       format = spa_format_audio_dsp_build(&b, SPA_PARAM_Format,
76
+                   &SPA_AUDIO_INFO_DSP_INIT(
77
+               .format = SPA_AUDIO_FORMAT_F32P));
78
+       for (i = 0; i < info->channels; i++) {
79
+           res = spa_node_port_set_param(ctx->convert_node, direction, i,
80
+               SPA_PARAM_Format, 0, format);
81
+           spa_assert_se(res == 0);
82
+       }
83
+       break;
84
+   default:
85
+       return -EINVAL;
86
+   }
87
+   return 0;
88
+}
89
+
90
+struct buffer {
91
+   struct spa_buffer buffer;
92
+        struct spa_data datasMAX_PORTS;
93
+        struct spa_chunk chunksMAX_PORTS;
94
+};
95
+
96
+struct data {
97
+   uint32_t mode;
98
+   struct spa_audio_info_raw info;
99
+   uint32_t ports;
100
+   uint32_t planes;
101
+   const void *dataMAX_PORTS;
102
+   uint32_t size;
103
+};
104
+
105
+static int run_convert(struct context *ctx, struct data *in_data,
106
+       struct data *out_data)
107
+{
108
+   struct spa_command cmd;
109
+   int res;
110
+   uint32_t i, j, k;
111
+   struct buffer in_buffersin_data->ports;
112
+   struct buffer out_buffersout_data->ports;
113
+   struct spa_io_buffers in_ioin_data->ports;
114
+   struct spa_io_buffers out_ioout_data->ports;
115
+
116
+   setup_direction(ctx, SPA_DIRECTION_INPUT, in_data->mode, &in_data->info);
117
+   setup_direction(ctx, SPA_DIRECTION_OUTPUT, out_data->mode, &out_data->info);
118
+
119
+   cmd = SPA_NODE_COMMAND_INIT(SPA_NODE_COMMAND_Start);
120
+   res = spa_node_send_command(ctx->convert_node, &cmd);
121
+   spa_assert_se(res == 0);
122
+
123
+   for (i = 0, k = 0; i < in_data->ports; i++) {
124
+       struct buffer *b = &in_buffersi;
125
+       struct spa_buffer *buffers1;
126
+       spa_zero(*b);
127
+       b->buffer.datas = b->datas;
128
+                b->buffer.n_datas = in_data->planes;
129
+
130
+       for (j = 0; j < in_data->planes; j++, k++) {
131
+           b->datasj.type = SPA_DATA_MemPtr;
132
+           b->datasj.flags = 0;
133
+           b->datasj.fd = -1;
134
+           b->datasj.mapoffset = 0;
135
+           b->datasj.maxsize = in_data->size;
136
+           b->datasj.data = (void *)in_data->datak;
137
+           b->datasj.chunk = &b->chunksj;
138
+           b->datasj.chunk->offset = 0;
139
+           b->datasj.chunk->size = in_data->size;
140
+           b->datasj.chunk->stride = 0;
141
+       }
142
+       buffers0 = &b->buffer;
143
+       res = spa_node_port_use_buffers(ctx->convert_node, SPA_DIRECTION_INPUT, i,
144
+               0, buffers, 1);
145
+       spa_assert_se(res == 0);
146
+
147
+       in_ioi.status = SPA_STATUS_HAVE_DATA;
148
+       in_ioi.buffer_id = 0;
149
+
150
+       res = spa_node_port_set_io(ctx->convert_node, SPA_DIRECTION_INPUT, i,
151
+               SPA_IO_Buffers, &in_ioi, sizeof(in_ioi));
152
+       spa_assert_se(res == 0);
153
+   }
154
+   for (i = 0; i < out_data->ports; i++) {
155
+       struct buffer *b = &out_buffersi;
156
+       struct spa_buffer *buffers1;
157
+       spa_zero(*b);
158
+       b->buffer.datas = b->datas;
159
+                b->buffer.n_datas = out_data->planes;
160
+
161
+       for (j = 0; j < out_data->planes; j++) {
162
+           b->datasj.type = SPA_DATA_MemPtr;
163
+           b->datasj.flags = 0;
164
+           b->datasj.fd = -1;
165
+           b->datasj.mapoffset = 0;
166
+           b->datasj.maxsize = out_data->size;
167
+           b->datasj.data = calloc(1, out_data->size);
168
+           b->datasj.chunk = &b->chunksj;
169
+           b->datasj.chunk->offset = 0;
170
+           b->datasj.chunk->size = 0;
171
+           b->datasj.chunk->stride = 0;
172
+       }
173
+       buffers0 = &b->buffer;
174
+       res = spa_node_port_use_buffers(ctx->convert_node,
175
+               SPA_DIRECTION_OUTPUT, i, 0, buffers, 1);
176
+       spa_assert_se(res == 0);
177
+
178
+       out_ioi.status = SPA_STATUS_NEED_DATA;
179
+       out_ioi.buffer_id = -1;
180
+
181
+       res = spa_node_port_set_io(ctx->convert_node, SPA_DIRECTION_OUTPUT, i,
182
+               SPA_IO_Buffers, &out_ioi, sizeof(out_ioi));
183
+       spa_assert_se(res == 0);
184
+   }
185
+
186
+   res = spa_node_process(ctx->convert_node);
187
+   spa_assert_se(res == (SPA_STATUS_NEED_DATA | SPA_STATUS_HAVE_DATA));
188
+
189
+   for (i = 0, k = 0; i < out_data->ports; i++) {
190
+       struct buffer *b = &out_buffersi;
191
+
192
+       spa_assert_se(out_ioi.status == SPA_STATUS_HAVE_DATA);
193
+       spa_assert_se(out_ioi.buffer_id == 0);
194
+
195
+       for (j = 0; j < out_data->planes; j++, k++) {
196
+           spa_assert_se(b->datasj.chunk->offset == 0);
197
+           spa_assert_se(b->datasj.chunk->size == out_data->size);
198
+
199
+           res = memcmp(b->datasj.data, out_data->datak, out_data->size);
200
+           if (res != 0) {
201
+               fprintf(stderr, "error plane %d\n", j);
202
+               spa_debug_mem(0, b->datasj.data, out_data->size);
203
+               spa_debug_mem(0, out_data->dataj, out_data->size);
204
+           }
205
+           spa_assert_se(res == 0);
206
+
207
+           free(b->datasj.data);
208
+       }
209
+   }
210
+   cmd = SPA_NODE_COMMAND_INIT(SPA_NODE_COMMAND_Suspend);
211
+   res = spa_node_send_command(ctx->convert_node, &cmd);
212
+   spa_assert_se(res == 0);
213
+
214
+   return 0;
215
+}
216
+
217
+static const float data_f32p_1 = { 0.1f, 0.1f, 0.1f, 0.1f };
218
+static const float data_f32p_2 = { 0.2f, 0.2f, 0.2f, 0.2f };
219
+static const float data_f32p_3 = { 0.3f, 0.3f, 0.3f, 0.3f };
220
+static const float data_f32p_4 = { 0.4f, 0.4f, 0.4f, 0.4f };
221
+static const float data_f32p_5 = { 0.5f, 0.5f, 0.5f, 0.5f };
222
+static const float data_f32p_6 = { 0.6f, 0.6f, 0.6f, 0.6f };
223
+
224
+static const float data_f32_5p1 = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f,
225
+                     0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f,
226
+                     0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f,
227
+                     0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f };
228
+static const float data_f32_5p1_remapped = { 0.1f, 0.2f, 0.5f, 0.6f, 0.3f, 0.4f,
229
+                     0.1f, 0.2f, 0.5f, 0.6f, 0.3f, 0.4f,
230
+                     0.1f, 0.2f, 0.5f, 0.6f, 0.3f, 0.4f,
231
+                     0.1f, 0.2f, 0.5f, 0.6f, 0.3f, 0.4f };
232
+
233
+struct data dsp_5p1 = {
234
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_dsp,
235
+   .info = SPA_AUDIO_INFO_RAW_INIT(
236
+       .format = SPA_AUDIO_FORMAT_F32,
237
+       .rate = 48000,
238
+       .channels = 6,
239
+       .position = {
240
+           SPA_AUDIO_CHANNEL_FL,
241
+           SPA_AUDIO_CHANNEL_FR,
242
+           SPA_AUDIO_CHANNEL_FC,
243
+           SPA_AUDIO_CHANNEL_LFE,
244
+           SPA_AUDIO_CHANNEL_RL,
245
+           SPA_AUDIO_CHANNEL_RR,
246
+       }),
247
+   .ports = 6,
248
+   .planes = 1,
249
+   .data = { data_f32p_1, data_f32p_2, data_f32p_3, data_f32p_4, data_f32p_5, data_f32p_6, },
250
+   .size = sizeof(float) * 4
251
+};
252
+
253
+struct data dsp_5p1_remapped = {
254
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_dsp,
255
+   .info = SPA_AUDIO_INFO_RAW_INIT(
256
+       .format = SPA_AUDIO_FORMAT_F32,
257
+       .rate = 48000,
258
+       .channels = 6,
259
+       .position = {
260
+           SPA_AUDIO_CHANNEL_FL,
261
+           SPA_AUDIO_CHANNEL_FR,
262
+           SPA_AUDIO_CHANNEL_RL,
263
+           SPA_AUDIO_CHANNEL_RR,
264
+           SPA_AUDIO_CHANNEL_FC,
265
+           SPA_AUDIO_CHANNEL_LFE,
266
+       }),
267
+   .ports = 6,
268
+   .planes = 1,
269
+   .data = { data_f32p_1, data_f32p_2, data_f32p_5, data_f32p_6, data_f32p_3, data_f32p_4, },
270
+   .size = sizeof(float) * 4
271
+};
272
+
273
+struct data conv_f32_48000_5p1 = {
274
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_convert,
275
+   .info = SPA_AUDIO_INFO_RAW_INIT(
276
+       .format = SPA_AUDIO_FORMAT_F32,
277
+       .rate = 48000,
278
+       .channels = 6,
279
+       .position = {
280
+           SPA_AUDIO_CHANNEL_FL,
281
+           SPA_AUDIO_CHANNEL_FR,
282
+           SPA_AUDIO_CHANNEL_FC,
283
+           SPA_AUDIO_CHANNEL_LFE,
284
+           SPA_AUDIO_CHANNEL_RL,
285
+           SPA_AUDIO_CHANNEL_RR,
286
+       }),
287
+   .ports = 1,
288
+   .planes = 1,
289
+   .data = { data_f32_5p1 },
290
+   .size = sizeof(data_f32_5p1)
291
+};
292
+
293
+struct data conv_f32_48000_5p1_remapped = {
294
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_convert,
295
+   .info = SPA_AUDIO_INFO_RAW_INIT(
296
+       .format = SPA_AUDIO_FORMAT_F32,
297
+       .rate = 48000,
298
+       .channels = 6,
299
+       .position = {
300
+           SPA_AUDIO_CHANNEL_FL,
301
+           SPA_AUDIO_CHANNEL_FR,
302
+           SPA_AUDIO_CHANNEL_RL,
303
+           SPA_AUDIO_CHANNEL_RR,
304
+           SPA_AUDIO_CHANNEL_FC,
305
+           SPA_AUDIO_CHANNEL_LFE,
306
+       }),
307
+   .ports = 1,
308
+   .planes = 1,
309
+   .data = { data_f32_5p1_remapped },
310
+   .size = sizeof(data_f32_5p1_remapped)
311
+};
312
+
313
+struct data conv_f32p_48000_5p1 = {
314
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_convert,
315
+   .info = SPA_AUDIO_INFO_RAW_INIT(
316
+       .format = SPA_AUDIO_FORMAT_F32P,
317
+       .rate = 48000,
318
+       .channels = 6,
319
+       .position = {
320
+           SPA_AUDIO_CHANNEL_FL,
321
+           SPA_AUDIO_CHANNEL_FR,
322
+           SPA_AUDIO_CHANNEL_FC,
323
+           SPA_AUDIO_CHANNEL_LFE,
324
+           SPA_AUDIO_CHANNEL_RL,
325
+           SPA_AUDIO_CHANNEL_RR,
326
+       }),
327
+   .ports = 1,
328
+   .planes = 6,
329
+   .data = { data_f32p_1, data_f32p_2, data_f32p_3, data_f32p_4, data_f32p_5, data_f32p_6, },
330
+   .size = sizeof(float) * 4
331
+};
332
+
333
+struct data conv_f32p_48000_5p1_remapped = {
334
+   .mode = SPA_PARAM_PORT_CONFIG_MODE_convert,
335
+   .info = SPA_AUDIO_INFO_RAW_INIT(
336
+       .format = SPA_AUDIO_FORMAT_F32P,
337
+       .rate = 48000,
338
+       .channels = 6,
339
+       .position = {
340
+           SPA_AUDIO_CHANNEL_FL,
341
+           SPA_AUDIO_CHANNEL_FR,
342
+           SPA_AUDIO_CHANNEL_RL,
343
+           SPA_AUDIO_CHANNEL_RR,
344
+           SPA_AUDIO_CHANNEL_FC,
345
+           SPA_AUDIO_CHANNEL_LFE,
346
+       }),
347
+   .ports = 1,
348
+   .planes = 6,
349
+   .data = { data_f32p_1, data_f32p_2, data_f32p_5, data_f32p_6, data_f32p_3, data_f32p_4, },
350
+   .size = sizeof(float) * 4
351
+};
352
+
353
+static int test_convert_remap_dsp(struct context *ctx)
354
+{
355
+   run_convert(ctx, &dsp_5p1, &conv_f32_48000_5p1);
356
+   run_convert(ctx, &dsp_5p1, &conv_f32p_48000_5p1);
357
+   run_convert(ctx, &dsp_5p1, &conv_f32_48000_5p1_remapped);
358
+   run_convert(ctx, &dsp_5p1, &conv_f32p_48000_5p1_remapped);
359
+   run_convert(ctx, &dsp_5p1_remapped, &conv_f32_48000_5p1);
360
+   run_convert(ctx, &dsp_5p1_remapped, &conv_f32p_48000_5p1);
361
+   run_convert(ctx, &dsp_5p1_remapped, &conv_f32_48000_5p1_remapped);
362
+   run_convert(ctx, &dsp_5p1_remapped, &conv_f32p_48000_5p1_remapped);
363
+   return 0;
364
+}
365
+
366
+static int test_convert_remap_conv(struct context *ctx)
367
+{
368
+   run_convert(ctx, &conv_f32_48000_5p1, &dsp_5p1);
369
+   run_convert(ctx, &conv_f32_48000_5p1, &dsp_5p1_remapped);
370
+   run_convert(ctx, &conv_f32p_48000_5p1, &dsp_5p1);
371
+   run_convert(ctx, &conv_f32p_48000_5p1, &dsp_5p1_remapped);
372
+   run_convert(ctx, &conv_f32_48000_5p1_remapped, &dsp_5p1);
373
+   run_convert(ctx, &conv_f32_48000_5p1_remapped, &dsp_5p1_remapped);
374
+   run_convert(ctx, &conv_f32p_48000_5p1_remapped, &dsp_5p1);
375
+   run_convert(ctx, &conv_f32p_48000_5p1_remapped, &dsp_5p1_remapped);
376
+   return 0;
377
+}
378
+
379
 int main(int argc, char *argv)
380
 {
381
    struct context ctx;
382
@@ -531,6 +880,9 @@
383
    test_set_in_format2(&ctx);
384
    test_set_out_format(&ctx);
385
 
386
+   test_convert_remap_dsp(&ctx);
387
+   test_convert_remap_conv(&ctx);
388
+
389
    clean_context(&ctx);
390
 
391
    return 0;
392
pipewire-0.3.53.tar.gz/spa/plugins/audioconvert/test-fmt-ops.c -> pipewire-0.3.54.tar.gz/spa/plugins/audioconvert/test-fmt-ops.c Changed
505
 
1
@@ -50,7 +50,7 @@
2
 {
3
    int res = memcmp(m1, m2, size);
4
    if (res != 0) {
5
-       fprintf(stderr, "%d %d:\n", i, j);
6
+       fprintf(stderr, "%d %d %zd:\n", i, j, size);
7
        spa_debug_mem(0, m1, size);
8
        spa_debug_mem(0, m2, size);
9
    }
10
@@ -81,19 +81,19 @@
11
        tp0 = temp_in;
12
        switch(in_size) {
13
        case 1:
14
-           conv_interleave_8_c(&conv, tp, ip, N_SAMPLES);
15
+           conv_8d_to_8_c(&conv, tp, ip, N_SAMPLES);
16
            break;
17
        case 2:
18
-           conv_interleave_16_c(&conv, tp, ip, N_SAMPLES);
19
+           conv_16d_to_16_c(&conv, tp, ip, N_SAMPLES);
20
            break;
21
        case 3:
22
-           conv_interleave_24_c(&conv, tp, ip, N_SAMPLES);
23
+           conv_24d_to_24_c(&conv, tp, ip, N_SAMPLES);
24
            break;
25
        case 4:
26
-           conv_interleave_32_c(&conv, tp, ip, N_SAMPLES);
27
+           conv_32d_to_32_c(&conv, tp, ip, N_SAMPLES);
28
            break;
29
        case 8:
30
-           conv_interleave_64_c(&conv, tp, ip, N_SAMPLES);
31
+           conv_64d_to_64_c(&conv, tp, ip, N_SAMPLES);
32
            break;
33
        default:
34
            fprintf(stderr, "unknown size %zd\n", in_size);
35
@@ -125,10 +125,40 @@
36
    }
37
 }
38
 
39
+static void test_f32_s8(void)
40
+{
41
+   static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
42
+   static const int8_t out = { 0, 127, -128, 64, 192, 127, -128 };
43
+
44
+   run_test("test_f32_s8", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
45
+           true, true, conv_f32_to_s8_c);
46
+   run_test("test_f32d_s8", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
47
+           false, true, conv_f32d_to_s8_c);
48
+   run_test("test_f32_s8d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
49
+           true, false, conv_f32_to_s8d_c);
50
+   run_test("test_f32d_s8d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
51
+           false, false, conv_f32d_to_s8d_c);
52
+}
53
+
54
+static void test_s8_f32(void)
55
+{
56
+   static const int8_t in = { 0, 127, -128, 64, 192, };
57
+   static const float out = { 0.0f, 0.9921875f, -1.0f, 0.5f, -0.5f, };
58
+
59
+   run_test("test_s8_f32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
60
+           true, true, conv_s8_to_f32_c);
61
+   run_test("test_s8d_f32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
62
+           false, true, conv_s8d_to_f32_c);
63
+   run_test("test_s8_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
64
+           true, false, conv_s8_to_f32d_c);
65
+   run_test("test_s8d_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
66
+           false, false, conv_s8d_to_f32d_c);
67
+}
68
+
69
 static void test_f32_u8(void)
70
 {
71
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
72
-   static const uint8_t out = { 128, 255, 0, 191, 64, 255, 0, };
73
+   static const uint8_t out = { 128, 255, 0, 192, 64, 255, 0, };
74
 
75
    run_test("test_f32_u8", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
76
            true, true, conv_f32_to_u8_c);
77
@@ -158,7 +188,7 @@
78
 static void test_f32_u16(void)
79
 {
80
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
81
-   static const uint16_t out = { 32767, 65535, 0, 49150, 16383, 65535, 0 };
82
+   static const uint16_t out = { 32768, 65535, 0, 49152, 16384, 65535, 0 };
83
 
84
    run_test("test_f32_u16", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
85
            true, true, conv_f32_to_u16_c);
86
@@ -168,8 +198,8 @@
87
 
88
 static void test_u16_f32(void)
89
 {
90
-   static const uint16_t in = { 32767, 65535, 0, 49150, 16383, };
91
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999847412f, -0.4999847412f };
92
+   static const uint16_t in = { 32768, 65535, 0, 49152, 16384, };
93
+   static const float out = { 0.0f, 0.999969482422f, -1.0f, 0.5f, -0.5f };
94
 
95
    run_test("test_u16_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
96
            true, false, conv_u16_to_f32d_c);
97
@@ -180,7 +210,7 @@
98
 static void test_f32_s16(void)
99
 {
100
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
101
-   static const int16_t out = { 0, 32767, -32767, 16383, -16383, 32767, -32767 };
102
+   static const int16_t out = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
103
 
104
    run_test("test_f32_s16", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
105
            true, true, conv_f32_to_s16_c);
106
@@ -192,16 +222,26 @@
107
            false, false, conv_f32d_to_s16d_c);
108
 #if defined(HAVE_SSE2)
109
    if (cpu_flags & SPA_CPU_FLAG_SSE2) {
110
+       run_test("test_f32_s16_sse2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
111
+           true, true, conv_f32_to_s16_sse2);
112
        run_test("test_f32d_s16_sse2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
113
            false, true, conv_f32d_to_s16_sse2);
114
+       run_test("test_f32d_s16d_sse2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
115
+           false, false, conv_f32d_to_s16d_sse2);
116
+   }
117
+#endif
118
+#if defined(HAVE_AVX2)
119
+   if (cpu_flags & SPA_CPU_FLAG_AVX2) {
120
+       run_test("test_f32d_s16_avx2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
121
+           false, true, conv_f32d_to_s16_avx2);
122
    }
123
 #endif
124
 }
125
 
126
 static void test_s16_f32(void)
127
 {
128
-   static const int16_t in = { 0, 32767, -32767, 16383, -16383, };
129
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999847412f, -0.4999847412f };
130
+   static const int16_t in = { 0, 32767, -32768, 16384, -16384, };
131
+   static const float out = { 0.0f, 0.999969482422f, -1.0f, 0.5f, -0.5f };
132
 
133
    run_test("test_s16_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
134
            true, false, conv_s16_to_f32d_c);
135
@@ -217,13 +257,19 @@
136
            true, false, conv_s16_to_f32d_sse2);
137
    }
138
 #endif
139
+#if defined(HAVE_AVX2)
140
+   if (cpu_flags & SPA_CPU_FLAG_AVX2) {
141
+       run_test("test_s16_f32d_avx2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
142
+           true, false, conv_s16_to_f32d_avx2);
143
+   }
144
+#endif
145
 }
146
 
147
 static void test_f32_u32(void)
148
 {
149
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
150
-   static const uint32_t out = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100,
151
-                   0x7fffff00, 0x80000100 };
152
+   static const uint32_t out = { 0x80000000, 0xffffffff, 0x0, 0xc0000000, 0x40000000,
153
+                   0xffffffff, 0x0 };
154
 
155
    run_test("test_f32_u32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
156
            true, true, conv_f32_to_u32_c);
157
@@ -233,8 +279,8 @@
158
 
159
 static void test_u32_f32(void)
160
 {
161
-   static const uint32_t in = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100 };
162
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
163
+   static const uint32_t in = { 0x80000000, 0xffffffff, 0x0, 0xc0000000, 0x40000000 };
164
+   static const float out = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, };
165
 
166
    run_test("test_u32_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
167
            true, false, conv_u32_to_f32d_c);
168
@@ -245,8 +291,8 @@
169
 static void test_f32_s32(void)
170
 {
171
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
172
-   static const int32_t out = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100,
173
-                   0x7fffff00, 0x80000100 };
174
+   static const int32_t out = { 0, 0x7fffff80, 0x80000000, 0x40000000, 0xc0000000,
175
+                   0x7fffff80, 0x80000000 };
176
 
177
    run_test("test_f32_s32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
178
            true, true, conv_f32_to_s32_c);
179
@@ -262,12 +308,18 @@
180
            false, true, conv_f32d_to_s32_sse2);
181
    }
182
 #endif
183
+#if defined(HAVE_AVX2)
184
+   if (cpu_flags & SPA_CPU_FLAG_AVX2) {
185
+       run_test("test_f32d_s32_avx2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
186
+           false, true, conv_f32d_to_s32_avx2);
187
+   }
188
+#endif
189
 }
190
 
191
 static void test_s32_f32(void)
192
 {
193
-   static const int32_t in = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100 };
194
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
195
+   static const int32_t in = { 0, 0x7fffff80, 0x80000000, 0x40000000, 0xc0000000 };
196
+   static const float out = { 0.0f, 0.999999940395f, -1.0f, 0.5, -0.5, };
197
 
198
    run_test("test_s32_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
199
            true, false, conv_s32_to_f32d_c);
200
@@ -283,18 +335,20 @@
201
            true, false, conv_s32_to_f32d_sse2);
202
    }
203
 #endif
204
+#if defined(HAVE_AVX2)
205
+   if (cpu_flags & SPA_CPU_FLAG_AVX2) {
206
+       run_test("test_s32_f32d_avx2", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
207
+           true, false, conv_s32_to_f32d_avx2);
208
+   }
209
+#endif
210
 }
211
 
212
 static void test_f32_u24(void)
213
 {
214
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
215
-#if __BYTE_ORDER == __LITTLE_ENDIAN
216
-   static const uint8_t out = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
217
-       0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80 };
218
-#else
219
-   static const uint8_t out = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
220
-       0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01 };
221
-#endif
222
+   static const uint24_t out = { U32_TO_U24(0x00800000), U32_TO_U24(0xffffff),
223
+       U32_TO_U24(0x000000), U32_TO_U24(0xc00000), U32_TO_U24(0x400000),
224
+       U32_TO_U24(0xffffff), U32_TO_U24(0x000000) };
225
 
226
    run_test("test_f32_u24", in, sizeof(in0), out, 3, SPA_N_ELEMENTS(in),
227
            true, true, conv_f32_to_u24_c);
228
@@ -304,14 +358,9 @@
229
 
230
 static void test_u24_f32(void)
231
 {
232
-#if __BYTE_ORDER == __LITTLE_ENDIAN
233
-   static const uint8_t in = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
234
-       0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0,  };
235
-#else
236
-   static const uint8_t in = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
237
-       0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01,  };
238
-#endif
239
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
240
+   static const uint24_t in = { U32_TO_U24(0x00800000), U32_TO_U24(0xffffff),
241
+       U32_TO_U24(0x000000), U32_TO_U24(0xc00000), U32_TO_U24(0x400000) };
242
+   static const float out = { 0.0f, 0.999999880791f, -1.0f, 0.5, -0.5, };
243
 
244
    run_test("test_u24_f32d", in, 3, out, sizeof(out0), SPA_N_ELEMENTS(out),
245
            true, false, conv_u24_to_f32d_c);
246
@@ -322,13 +371,9 @@
247
 static void test_f32_s24(void)
248
 {
249
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
250
-#if __BYTE_ORDER == __LITTLE_ENDIAN
251
-   static const uint8_t out = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
252
-       0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80 };
253
-#else
254
-   static const uint8_t out = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
255
-       0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01 };
256
-#endif
257
+   static const int24_t out = { S32_TO_S24(0), S32_TO_S24(0x7fffff),
258
+       S32_TO_S24(0xff800000), S32_TO_S24(0x400000), S32_TO_S24(0xc00000),
259
+       S32_TO_S24(0x7fffff), S32_TO_S24(0xff800000) };
260
 
261
    run_test("test_f32_s24", in, sizeof(in0), out, 3, SPA_N_ELEMENTS(in),
262
            true, true, conv_f32_to_s24_c);
263
@@ -342,14 +387,9 @@
264
 
265
 static void test_s24_f32(void)
266
 {
267
-#if __BYTE_ORDER == __LITTLE_ENDIAN
268
-   static const uint8_t in = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
269
-       0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0,  };
270
-#else
271
-   static const uint8_t in = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
272
-       0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01,  };
273
-#endif
274
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
275
+   static const int24_t in = { S32_TO_S24(0), S32_TO_S24(0x7fffff),
276
+       S32_TO_S24(0xff800000), S32_TO_S24(0x400000), S32_TO_S24(0xc00000) };
277
+   static const float out = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
278
 
279
    run_test("test_s24_f32d", in, 3, out, sizeof(out0), SPA_N_ELEMENTS(out),
280
            true, false, conv_s24_to_f32d_c);
281
@@ -377,13 +417,19 @@
282
            true, false, conv_s24_to_f32d_sse41);
283
    }
284
 #endif
285
+#if defined(HAVE_AVX2)
286
+   if (cpu_flags & SPA_CPU_FLAG_AVX2) {
287
+       run_test("test_s24_f32d_avx2", in, 3, out, sizeof(out0), SPA_N_ELEMENTS(out),
288
+           true, false, conv_s24_to_f32d_avx2);
289
+   }
290
+#endif
291
 }
292
 
293
 static void test_f32_u24_32(void)
294
 {
295
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
296
-   static const uint32_t out = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001,
297
-                   0x7fffff, 0xff800001 };
298
+   static const uint32_t out = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000,
299
+                   0xffffff, 0x000000 };
300
 
301
    run_test("test_f32_u24_32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
302
            true, true, conv_f32_to_u24_32_c);
303
@@ -393,8 +439,8 @@
304
 
305
 static void test_u24_32_f32(void)
306
 {
307
-   static const uint32_t in = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001 };
308
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
309
+   static const uint32_t in = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000 };
310
+   static const float out = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
311
 
312
    run_test("test_u24_32_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
313
            true, false, conv_u24_32_to_f32d_c);
314
@@ -405,8 +451,8 @@
315
 static void test_f32_s24_32(void)
316
 {
317
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
318
-   static const int32_t out = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001,
319
-                   0x7fffff, 0xff800001 };
320
+   static const int32_t out = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000,
321
+                   0x7fffff, 0xff800000 };
322
 
323
    run_test("test_f32_s24_32", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
324
            true, true, conv_f32_to_s24_32_c);
325
@@ -420,8 +466,8 @@
326
 
327
 static void test_s24_32_f32(void)
328
 {
329
-   static const int32_t in = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001 };
330
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
331
+   static const int32_t in = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000 };
332
+   static const float out = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
333
 
334
    run_test("test_s24_32_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
335
            true, false, conv_s24_32_to_f32d_c);
336
@@ -435,8 +481,8 @@
337
 
338
 static void test_f64_f32(void)
339
 {
340
-   static const double in = { 0.0, 1.0, -1.0, 0.4999999404, -0.4999999404, };
341
-   static const float out = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
342
+   static const double in = { 0.0, 1.0, -1.0, 0.5, -0.5, };
343
+   static const float out = { 0.0, 1.0, -1.0, 0.5, -0.5, };
344
 
345
    run_test("test_f64_f32d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
346
            true, false, conv_f64_to_f32d_c);
347
@@ -451,7 +497,7 @@
348
 static void test_f32_f64(void)
349
 {
350
    static const float in = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
351
-   static const double out = { 0.0, 1.0, -1.0, 0.5, -0.5, 1.1, -1.1 };
352
+   static const double out = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
353
 
354
    run_test("test_f32_f64", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
355
            true, true, conv_f32_to_f64_c);
356
@@ -462,11 +508,131 @@
357
    run_test("test_f32d_f64d", in, sizeof(in0), out, sizeof(out0), SPA_N_ELEMENTS(out),
358
            false, false, conv_f32d_to_f64d_c);
359
 }
360
+
361
+static void test_lossless_s8(void)
362
+{
363
+   int8_t i;
364
+
365
+   fprintf(stderr, "test %s:\n", __func__);
366
+   for (i = S8_MIN; i < S8_MAX; i+=1) {
367
+       float v = S8_TO_F32(i);
368
+       int8_t t = F32_TO_S8(v);
369
+       spa_assert_se(i == t);
370
+   }
371
+}
372
+
373
+static void test_lossless_u8(void)
374
+{
375
+   uint8_t i;
376
+
377
+   fprintf(stderr, "test %s:\n", __func__);
378
+   for (i = U8_MIN; i < U8_MAX; i+=1) {
379
+       float v = U8_TO_F32(i);
380
+       uint8_t t = F32_TO_U8(v);
381
+       spa_assert_se(i == t);
382
+   }
383
+}
384
+static void test_lossless_s16(void)
385
+{
386
+   int16_t i;
387
+
388
+   fprintf(stderr, "test %s:\n", __func__);
389
+   for (i = S16_MIN; i < S16_MAX; i+=3) {
390
+       float v = S16_TO_F32(i);
391
+       int16_t t = F32_TO_S16(v);
392
+       spa_assert_se(i == t);
393
+   }
394
+}
395
+
396
+static void test_lossless_u16(void)
397
+{
398
+   uint32_t i;
399
+
400
+   fprintf(stderr, "test %s:\n", __func__);
401
+   for (i = U16_MIN; i < U16_MAX; i+=3) {
402
+       float v = U16_TO_F32(i);
403
+       uint16_t t = F32_TO_U16(v);
404
+       spa_assert_se(i == t);
405
+   }
406
+}
407
+
408
+static void test_lossless_s24(void)
409
+{
410
+   int32_t i;
411
+
412
+   fprintf(stderr, "test %s:\n", __func__);
413
+   for (i = S24_MIN; i < S24_MAX; i+=13) {
414
+       float v = S24_TO_F32(s32_to_s24(i));
415
+       int32_t t = s24_to_s32(F32_TO_S24(v));
416
+       spa_assert_se(i == t);
417
+   }
418
+}
419
+
420
+static void test_lossless_u24(void)
421
+{
422
+   uint32_t i;
423
+
424
+   fprintf(stderr, "test %s:\n", __func__);
425
+   for (i = U24_MIN; i < U24_MAX; i+=11) {
426
+       float v = U24_TO_F32(u32_to_u24(i));
427
+       uint32_t t = u24_to_u32(F32_TO_U24(v));
428
+       spa_assert_se(i == t);
429
+   }
430
+}
431
+
432
+static void test_lossless_s32(void)
433
+{
434
+   int32_t i;
435
+
436
+   fprintf(stderr, "test %s:\n", __func__);
437
+   for (i = S32_MIN; i < S32_MAX; i+=255) {
438
+       float v = S32_TO_F32(i);
439
+       int32_t t = F32_TO_S32(v);
440
+       spa_assert_se(SPA_ABS(i - t) <= 128);
441
+   }
442
+}
443
+
444
+static void test_lossless_u32(void)
445
+{
446
+   uint32_t i;
447
+
448
+   fprintf(stderr, "test %s:\n", __func__);
449
+   for (i = U32_MIN; i < U32_MAX; i+=255) {
450
+       float v = U32_TO_F32(i);
451
+       uint32_t t = F32_TO_U32(v);
452
+       spa_assert_se(i > t ? (i - t) <= 128 : (t - i) <= 128);
453
+   }
454
+}
455
+
456
+static void test_swaps(void)
457
+{
458
+   {
459
+       uint24_t v = U32_TO_U24(0x123456);
460
+       uint24_t t = U32_TO_U24(0x563412);
461
+       uint24_t s = bswap_u24(v);
462
+       spa_assert_se(memcmp(&s, &t, sizeof(t)) == 0);
463
+   }
464
+   {
465
+       int24_t v = S32_TO_S24(0xfffe1dc0);
466
+       int24_t t = S32_TO_S24(0xffc01dfe);
467
+       int24_t s = bswap_s24(v);
468
+       spa_assert_se(memcmp(&s, &t, sizeof(t)) == 0);
469
+   }
470
+   {
471
+       int24_t v = S32_TO_S24(0x123456);
472
+       int24_t t = S32_TO_S24(0x563412);
473
+       int24_t s = bswap_s24(v);
474
+       spa_assert_se(memcmp(&s, &t, sizeof(t)) == 0);
475
+   }
476
+}
477
+
478
 int main(int argc, char *argv)
479
 {
480
    cpu_flags = get_cpu_flags();
481
    printf("got get CPU flags %d\n", cpu_flags);
482
 
483
+   test_f32_s8();
484
+   test_s8_f32();
485
    test_f32_u8();
486
    test_u8_f32();
487
    test_f32_u16();
488
@@ -487,5 +653,16 @@
489
    test_s24_32_f32();
490
    test_f32_f64();
491
    test_f64_f32();
492
+
493
+   test_lossless_s8();
494
+   test_lossless_u8();
495
+   test_lossless_s16();
496
+   test_lossless_u16();
497
+   test_lossless_s24();
498
+   test_lossless_u24();
499
+   test_lossless_s32();
500
+   test_lossless_u32();
501
+
502
+   test_swaps();
503
    return 0;
504
 }
505
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/a2dp-codec-aac.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/a2dp-codec-aac.c Changed
10
 
1
@@ -415,7 +415,7 @@
2
    return this;
3
 
4
 error:
5
-   if (this->aacenc)
6
+   if (this && this->aacenc)
7
        aacEncClose(&this->aacenc);
8
    free(this);
9
    errno = -res;
10
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/a2dp-sink.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/a2dp-sink.c Changed
19
 
1
@@ -743,7 +743,7 @@
2
         * => timeout = (quantum - max_excess)/quantum * packet_time
3
         */
4
        uint64_t max_excess = 2*256;
5
-       uint64_t packet_samples = this->frame_count * this->block_size / port->frame_size;
6
+       uint64_t packet_samples = (uint64_t)this->frame_count * this->block_size / port->frame_size;
7
        uint64_t packet_time = packet_samples * SPA_NSEC_PER_SEC / port->current_format.info.raw.rate;
8
        uint64_t quantum = SPA_LIKELY(this->clock) ? this->clock->duration : 0;
9
        uint64_t timeout = (quantum > max_excess) ?
10
@@ -843,7 +843,7 @@
11
    prev_time = this->current_time;
12
    now_time = this->current_time = this->next_time;
13
 
14
-   spa_log_debug(this->log, "%p: timeout %"PRIu64" %"PRIu64"", this,
15
+   spa_log_debug(this->log, "%p: timer %"PRIu64" %"PRIu64"", this,
16
            now_time, now_time - prev_time);
17
 
18
    if (SPA_LIKELY(this->position)) {
19
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/a2dp-source.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/a2dp-source.c Changed
761
 
1
@@ -60,18 +60,16 @@
2
 #undef SPA_LOG_TOPIC_DEFAULT
3
 #define SPA_LOG_TOPIC_DEFAULT &log_topic
4
 
5
+#include "decode-buffer.h"
6
+
7
 #define DEFAULT_CLOCK_NAME "clock.system.monotonic"
8
 
9
 struct props {
10
-   uint32_t min_latency;
11
-   uint32_t max_latency;
12
    char clock_name64;
13
 };
14
 
15
 #define FILL_FRAMES 2
16
 #define MAX_BUFFERS 32
17
-#define MIN_LATENCY    512
18
-#define MAX_LATENCY    1024
19
 
20
 struct buffer {
21
    uint32_t id;
22
@@ -89,6 +87,7 @@
23
    uint64_t info_all;
24
    struct spa_port_info info;
25
    struct spa_io_buffers *io;
26
+   struct spa_io_rate_match *rate_match;
27
    struct spa_latency_info latency;
28
 #define IDX_EnumFormat 0
29
 #define IDX_Meta   1
30
@@ -105,8 +104,7 @@
31
    struct spa_list free;
32
    struct spa_list ready;
33
 
34
-   struct buffer *current_buffer;
35
-   uint32_t ready_offset;
36
+   struct spa_bt_decode_buffer buffer;
37
 };
38
 
39
 struct impl {
40
@@ -120,6 +118,8 @@
41
    struct spa_hook_list hooks;
42
    struct spa_callbacks callbacks;
43
 
44
+   uint32_t quantum_limit;
45
+
46
    uint64_t info_all;
47
    struct spa_node_info info;
48
 #define IDX_PropInfo   0
49
@@ -137,6 +137,8 @@
50
    unsigned int started:1;
51
    unsigned int transport_acquired:1;
52
    unsigned int following:1;
53
+   unsigned int matching:1;
54
+   unsigned int resampling:1;
55
 
56
    unsigned int is_input:1;
57
    unsigned int is_duplex:1;
58
@@ -144,9 +146,15 @@
59
    int fd;
60
    struct spa_source source;
61
 
62
+   struct spa_source timer_source;
63
+   int timerfd;
64
+
65
    struct spa_io_clock *clock;
66
         struct spa_io_position *position;
67
 
68
+   uint64_t current_time;
69
+   uint64_t next_time;
70
+
71
    const struct a2dp_codec *codec;
72
    bool codec_props_changed;
73
    void *codec_props;
74
@@ -154,10 +162,8 @@
75
    struct spa_audio_info codec_format;
76
 
77
    uint8_t buffer_read4096;
78
-   uint8_t buffer_decoded65536;
79
    struct timespec now;
80
    uint64_t sample_count;
81
-   uint64_t skip_count;
82
 
83
    int duplex_timerfd;
84
    uint64_t duplex_timeout;
85
@@ -165,13 +171,8 @@
86
 
87
 #define CHECK_PORT(this,d,p)    ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
88
 
89
-static const uint32_t default_min_latency = MIN_LATENCY;
90
-static const uint32_t default_max_latency = MAX_LATENCY;
91
-
92
 static void reset_props(struct props *props)
93
 {
94
-   props->min_latency = default_min_latency;
95
-   props->max_latency = default_max_latency;
96
    strncpy(props->clock_name, DEFAULT_CLOCK_NAME, sizeof(props->clock_name));
97
 }
98
 
99
@@ -200,43 +201,19 @@
100
    switch (id) {
101
    case SPA_PARAM_PropInfo:
102
    {
103
-       struct props *p = &this->props;
104
-
105
        switch (result.index) {
106
-       case 0:
107
-           param = spa_pod_builder_add_object(&b,
108
-               SPA_TYPE_OBJECT_PropInfo, id,
109
-               SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_minLatency),
110
-               SPA_PROP_INFO_description, SPA_POD_String("The minimum latency"),
111
-               SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX));
112
-           break;
113
-       case 1:
114
-           param = spa_pod_builder_add_object(&b,
115
-               SPA_TYPE_OBJECT_PropInfo, id,
116
-               SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_maxLatency),
117
-               SPA_PROP_INFO_description, SPA_POD_String("The maximum latency"),
118
-               SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX));
119
-           break;
120
        default:
121
            enum_codec = true;
122
-           index_offset = 2;
123
+           index_offset = 0;
124
        }
125
        break;
126
    }
127
    case SPA_PARAM_Props:
128
    {
129
-       struct props *p = &this->props;
130
-
131
        switch (result.index) {
132
-       case 0:
133
-           param = spa_pod_builder_add_object(&b,
134
-               SPA_TYPE_OBJECT_Props, id,
135
-               SPA_PROP_minLatency, SPA_POD_Int(p->min_latency),
136
-               SPA_PROP_maxLatency, SPA_POD_Int(p->max_latency));
137
-           break;
138
        default:
139
            enum_codec = true;
140
-           index_offset = 1;
141
+           index_offset = 0;
142
        }
143
        break;
144
    }
145
@@ -267,13 +244,38 @@
146
    return 0;
147
 }
148
 
149
-static int do_reassing_follower(struct spa_loop *loop,
150
+static int set_timeout(struct impl *this, uint64_t time)
151
+{
152
+   struct itimerspec ts;
153
+   ts.it_value.tv_sec = time / SPA_NSEC_PER_SEC;
154
+   ts.it_value.tv_nsec = time % SPA_NSEC_PER_SEC;
155
+   ts.it_interval.tv_sec = 0;
156
+   ts.it_interval.tv_nsec = 0;
157
+   return spa_system_timerfd_settime(this->data_system,
158
+           this->timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
159
+}
160
+
161
+static int set_timers(struct impl *this)
162
+{
163
+   struct timespec now;
164
+
165
+   spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &now);
166
+   this->next_time = SPA_TIMESPEC_TO_NSEC(&now);
167
+
168
+   return set_timeout(this, this->following ? 0 : this->next_time);
169
+}
170
+
171
+static int do_reassign_follower(struct spa_loop *loop,
172
            bool async,
173
            uint32_t seq,
174
            const void *data,
175
            size_t size,
176
            void *user_data)
177
 {
178
+   struct impl *this = user_data;
179
+   struct port *port = &this->port;
180
+
181
+   spa_bt_decode_buffer_recover(&port->buffer);
182
    return 0;
183
 }
184
 
185
@@ -309,7 +311,7 @@
186
    if (this->started && following != this->following) {
187
        spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
188
        this->following = following;
189
-       spa_loop_invoke(this->data_loop, do_reassing_follower, 0, NULL, 0, true, this);
190
+       spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
191
    }
192
    return 0;
193
 }
194
@@ -324,10 +326,7 @@
195
    if (param == NULL) {
196
        reset_props(&new_props);
197
    } else {
198
-       spa_pod_parse_object(param,
199
-               SPA_TYPE_OBJECT_Props, NULL,
200
-               SPA_PROP_minLatency, SPA_POD_OPT_Int(&new_props.min_latency),
201
-               SPA_PROP_maxLatency, SPA_POD_OPT_Int(&new_props.max_latency));
202
+       /* noop */
203
    }
204
 
205
    changed = (memcmp(&new_props, &this->props, sizeof(struct props)) != 0);
206
@@ -372,7 +371,6 @@
207
 
208
    spa_list_init(&port->free);
209
    spa_list_init(&port->ready);
210
-   port->current_buffer = NULL;
211
 
212
    for (i = 0; i < port->n_buffers; i++) {
213
        struct buffer *b = &port->buffersi;
214
@@ -449,30 +447,15 @@
215
    return dst_size - avail;
216
 }
217
 
218
-static void skip_ready_buffers(struct impl *this)
219
-{
220
-   struct port *port = &this->port;
221
-
222
-   /* Move all buffers from ready to free */
223
-   while (!spa_list_is_empty(&port->ready)) {
224
-       struct buffer *b;
225
-       b = spa_list_first(&port->ready, struct buffer, link);
226
-       spa_list_remove(&b->link);
227
-       spa_list_append(&port->free, &b->link);
228
-       spa_assert(!b->outstanding);
229
-       this->skip_count += b->buf->datas0.chunk->size / port->frame_size;
230
-   }
231
-}
232
-
233
 static void a2dp_on_ready_read(struct spa_source *source)
234
 {
235
    struct impl *this = source->data;
236
    struct port *port = &this->port;
237
-   struct spa_io_buffers *io = port->io;
238
-   int32_t size_read, decoded, avail;
239
-   struct spa_data *datas;
240
-   struct buffer *buffer;
241
-   uint32_t min_data;
242
+   struct timespec now;
243
+   void *buf;
244
+   int32_t size_read, decoded;
245
+   uint32_t avail;
246
+   uint64_t dt;
247
 
248
    /* make sure the source is an input */
249
    if ((source->rmask & SPA_IO_IN) == 0) {
250
@@ -486,9 +469,6 @@
251
 
252
    spa_log_trace(this->log, "socket poll");
253
 
254
-   /* update the current pts */
255
-   spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &this->now);
256
-
257
    /* read */
258
    size_read = read_data (this);
259
    if (size_read == 0)
260
@@ -497,7 +477,9 @@
261
        spa_log_error(this->log, "failed to read data: %s", spa_strerror(size_read));
262
        goto stop;
263
    }
264
-   spa_log_trace(this->log, "read socket data %d", size_read);
265
+
266
+   /* update the current pts */
267
+   spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &now);
268
 
269
    if (this->codec_props_changed && this->codec_props
270
            && this->codec->update_props) {
271
@@ -505,111 +487,33 @@
272
        this->codec_props_changed = false;
273
    }
274
 
275
-   /* decode */
276
-   decoded = decode_data(this, this->buffer_read, size_read,
277
-           this->buffer_decoded, sizeof (this->buffer_decoded));
278
+   /* decode to buffer */
279
+   buf = spa_bt_decode_buffer_get_write(&port->buffer, &avail);
280
+   spa_log_trace(this->log, "read socket data size:%d, avail:%d", size_read, avail);
281
+   decoded = decode_data(this, this->buffer_read, size_read, buf, avail);
282
    if (decoded < 0) {
283
        spa_log_debug(this->log, "failed to decode data: %d", decoded);
284
        return;
285
    }
286
-   if (decoded == 0)
287
+   if (decoded == 0) {
288
+       spa_log_trace(this->log, "no decoded socket data");
289
        return;
290
-
291
-   spa_log_trace(this->log, "decoded socket data %d", decoded);
292
+   }
293
 
294
    /* discard when not started */
295
    if (!this->started)
296
        return;
297
 
298
-   /* get buffer */
299
-   if (!port->current_buffer) {
300
-       if (spa_list_is_empty(&port->free)) {
301
-           /* xrun, skip ahead */
302
-           skip_ready_buffers(this);
303
-           this->skip_count += decoded / port->frame_size;
304
-           this->sample_count += decoded / port->frame_size;
305
-           return;
306
-       }
307
-       if (this->skip_count > 0) {
308
-           spa_log_info(this->log, "%p: xrun, skipped %"PRIu64" usec",
309
-                        this, (uint64_t)(this->skip_count * SPA_USEC_PER_SEC / port->current_format.info.raw.rate));
310
-           this->skip_count = 0;
311
-       }
312
-
313
-       buffer = spa_list_first(&port->free, struct buffer, link);
314
-       spa_list_remove(&buffer->link);
315
-
316
-       port->current_buffer = buffer;
317
-       port->ready_offset = 0;
318
-       spa_log_trace(this->log, "dequeue %d", buffer->id);
319
-
320
-       if (buffer->h) {
321
-           buffer->h->seq = this->sample_count;
322
-           buffer->h->pts = SPA_TIMESPEC_TO_NSEC(&this->now);
323
-           buffer->h->dts_offset = 0;
324
-       }
325
-   } else {
326
-       buffer = port->current_buffer;
327
-   }
328
-   datas = buffer->buf->datas;
329
-
330
-   /* copy data into buffer */
331
-   avail = SPA_MIN(decoded, (int32_t)(datas0.maxsize - port->ready_offset));
332
-   if (avail < decoded)
333
-       spa_log_warn(this->log, "buffer too small (%d > %d)", decoded, avail);
334
-   memcpy ((uint8_t *)datas0.data + port->ready_offset, this->buffer_decoded, avail);
335
-   port->ready_offset += avail;
336
-   this->sample_count += decoded / port->frame_size;
337
-
338
-   /* send buffer if full */
339
-   min_data = SPA_MIN(this->props.min_latency * port->frame_size, datas0.maxsize / 2);
340
-   if (port->ready_offset >= min_data) {
341
-       uint64_t sample_count;
342
-
343
-       datas0.chunk->offset = 0;
344
-       datas0.chunk->size = port->ready_offset;
345
-       datas0.chunk->stride = port->frame_size;
346
-
347
-       sample_count = datas0.chunk->size / port->frame_size;
348
-
349
-       spa_log_trace(this->log, "queue %d", buffer->id);
350
-       spa_list_append(&port->ready, &buffer->link);
351
-       port->current_buffer = NULL;
352
-
353
-       if (!this->following && this->clock) {
354
-           this->clock->nsec = SPA_TIMESPEC_TO_NSEC(&this->now);
355
-           this->clock->duration = sample_count * this->clock->rate.denom / port->current_format.info.raw.rate;
356
-           this->clock->position = this->sample_count * this->clock->rate.denom / port->current_format.info.raw.rate;
357
-           this->clock->delay = 0;
358
-           this->clock->rate_diff = 1.0f;
359
-           this->clock->next_nsec = this->clock->nsec + (uint64_t)sample_count * SPA_NSEC_PER_SEC / port->current_format.info.raw.rate;
360
-       }
361
-   }
362
-
363
-   /* done if there are no buffers ready */
364
-   if (spa_list_is_empty(&port->ready))
365
-       return;
366
-
367
-   if (this->following)
368
-       return;
369
-
370
-   /* process the buffer if IO does not have any */
371
-   if (io != NULL && io->status != SPA_STATUS_HAVE_DATA) {
372
-       struct buffer *b;
373
-
374
-       if (io->buffer_id < port->n_buffers)
375
-           recycle_buffer(this, port, io->buffer_id);
376
+   spa_bt_decode_buffer_write_packet(&port->buffer, decoded);
377
 
378
-       b = spa_list_first(&port->ready, struct buffer, link);
379
-       spa_list_remove(&b->link);
380
-       b->outstanding = true;
381
+   dt = SPA_TIMESPEC_TO_NSEC(&this->now);
382
+   this->now = now;
383
+   dt = SPA_TIMESPEC_TO_NSEC(&this->now) - dt;
384
 
385
-       io->buffer_id = b->id;
386
-       io->status = SPA_STATUS_HAVE_DATA;
387
-   }
388
+   spa_log_trace(this->log, "decoded socket data size:%d frames:%d dt:%d dms",
389
+           (int)decoded, (int)decoded/port->frame_size,
390
+           (int)(dt / 100000));
391
 
392
-   /* notify ready */
393
-   spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_DATA);
394
    return;
395
 
396
 stop:
397
@@ -641,6 +545,75 @@
398
    a2dp_on_ready_read(source);
399
 }
400
 
401
+static int setup_matching(struct impl *this)
402
+{
403
+   struct port *port = &this->port;
404
+
405
+   if (this->position && port->rate_match) {
406
+       port->rate_match->rate = 1 / port->buffer.corr;
407
+
408
+       this->matching = this->following;
409
+       this->resampling = this->matching ||
410
+           (port->current_format.info.raw.rate != this->position->clock.rate.denom);
411
+   } else {
412
+       this->matching = false;
413
+       this->resampling = false;
414
+   }
415
+
416
+   if (port->rate_match)
417
+       SPA_FLAG_UPDATE(port->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, this->matching);
418
+
419
+   return 0;
420
+}
421
+
422
+static void a2dp_on_timeout(struct spa_source *source)
423
+{
424
+   struct impl *this = source->data;
425
+   struct port *port = &this->port;
426
+   uint64_t exp, duration;
427
+   uint32_t rate;
428
+   struct spa_io_buffers *io = port->io;
429
+   uint64_t prev_time, now_time;
430
+
431
+   if (this->transport == NULL)
432
+       return;
433
+
434
+   if (this->started && spa_system_timerfd_read(this->data_system, this->timerfd, &exp) < 0)
435
+       spa_log_warn(this->log, "error reading timerfd: %s", strerror(errno));
436
+
437
+   prev_time = this->current_time;
438
+   now_time = this->current_time = this->next_time;
439
+
440
+   spa_log_trace(this->log, "%p: timer %"PRIu64" %"PRIu64"", this,
441
+           now_time, now_time - prev_time);
442
+
443
+   if (SPA_LIKELY(this->position)) {
444
+       duration = this->position->clock.duration;
445
+       rate = this->position->clock.rate.denom;
446
+   } else {
447
+       duration = 1024;
448
+       rate = 48000;
449
+   }
450
+
451
+   setup_matching(this);
452
+
453
+   this->next_time = now_time + duration * SPA_NSEC_PER_SEC / port->buffer.corr / rate;
454
+
455
+   if (SPA_LIKELY(this->clock)) {
456
+       this->clock->nsec = now_time;
457
+       this->clock->position += duration;
458
+       this->clock->duration = duration;
459
+       this->clock->rate_diff = port->buffer.corr;
460
+       this->clock->next_nsec = this->next_time;
461
+   }
462
+
463
+   spa_log_trace(this->log, "%p: %d", this, io->status);
464
+   io->status = SPA_STATUS_HAVE_DATA;
465
+   spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_DATA);
466
+
467
+   set_timeout(this, this->next_time);
468
+}
469
+
470
 static int transport_start(struct impl *this)
471
 {
472
    int res, val;
473
@@ -683,7 +656,13 @@
474
    if (setsockopt(this->transport->fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)) < 0)
475
        spa_log_warn(this->log, "SO_PRIORITY failed: %m");
476
 
477
-   reset_buffers(&this->port);
478
+   reset_buffers(port);
479
+
480
+   spa_bt_decode_buffer_clear(&port->buffer);
481
+   if ((res = spa_bt_decode_buffer_init(&port->buffer, this->log,
482
+           port->frame_size, port->current_format.info.raw.rate,
483
+           this->quantum_limit, this->quantum_limit)) < 0)
484
+       return res;
485
 
486
    this->fd = this->transport->fd;
487
 
488
@@ -716,8 +695,18 @@
489
        set_duplex_timeout(this, this->duplex_timeout);
490
    }
491
 
492
+   this->timer_source.data = this;
493
+   this->timer_source.fd = this->timerfd;
494
+   this->timer_source.func = a2dp_on_timeout;
495
+   this->timer_source.mask = SPA_IO_IN;
496
+   this->timer_source.rmask = 0;
497
+   spa_loop_add_source(this->data_loop, &this->timer_source);
498
+
499
    this->sample_count = 0;
500
-   this->skip_count = 0;
501
+
502
+   setup_matching(this);
503
+
504
+   set_timers(this);
505
 
506
    return 0;
507
 }
508
@@ -753,6 +742,7 @@
509
                void *user_data)
510
 {
511
    struct impl *this = user_data;
512
+   struct itimerspec ts;
513
 
514
    spa_log_debug(this->log, "%p: remove source", this);
515
 
516
@@ -761,11 +751,20 @@
517
    if (this->source.loop)
518
        spa_loop_remove_source(this->data_loop, &this->source);
519
 
520
+   if (this->timer_source.loop)
521
+       spa_loop_remove_source(this->data_loop, &this->timer_source);
522
+   ts.it_value.tv_sec = 0;
523
+   ts.it_value.tv_nsec = 0;
524
+   ts.it_interval.tv_sec = 0;
525
+   ts.it_interval.tv_nsec = 0;
526
+   spa_system_timerfd_settime(this->data_system, this->timerfd, 0, &ts, NULL);
527
+
528
    return 0;
529
 }
530
 
531
 static int transport_stop(struct impl *this)
532
 {
533
+   struct port *port = &this->port;
534
    int res;
535
 
536
    spa_log_debug(this->log, "%p: transport stop", this);
537
@@ -783,6 +782,8 @@
538
        this->codec->deinit(this->codec_data);
539
    this->codec_data = NULL;
540
 
541
+   spa_bt_decode_buffer_clear(&port->buffer);
542
+
543
    return res;
544
 }
545
 
546
@@ -836,24 +837,20 @@
547
 
548
 static void emit_node_info(struct impl *this, bool full)
549
 {
550
-   char latency64 = SPA_STRINGIFY(MIN_LATENCY)"/48000";
551
    uint64_t old = full ? this->info.change_mask : 0;
552
 
553
    struct spa_dict_item node_info_items = {
554
        { SPA_KEY_DEVICE_API, "bluez5" },
555
        { SPA_KEY_MEDIA_CLASS, this->is_input ? "Audio/Source" : "Stream/Output/Audio" },
556
-       { SPA_KEY_NODE_LATENCY, latency },
557
+       { SPA_KEY_NODE_LATENCY, this->is_input ? "" : "512/48000" },
558
        { "media.name", ((this->transport && this->transport->device->name) ?
559
-                        this->transport->device->name : "A2DP") },
560
-                { SPA_KEY_NODE_DRIVER, this->is_input ? "true" : "false" },
561
+                   this->transport->device->name : "A2DP") },
562
+       { SPA_KEY_NODE_DRIVER, this->is_input ? "true" : "false" },
563
    };
564
 
565
    if (full)
566
        this->info.change_mask = this->info_all;
567
    if (this->info.change_mask) {
568
-       if (this->transport && this->port.have_format)
569
-           snprintf(latency, sizeof(latency), "%d/%d", (int)this->props.min_latency,
570
-                   (int)this->port.current_format.info.raw.rate);
571
        this->info.props = &SPA_DICT_INIT_ARRAY(node_info_items);
572
        spa_node_emit_info(&this->hooks, &this->info);
573
        this->info.change_mask = old;
574
@@ -991,11 +988,11 @@
575
 
576
        param = spa_pod_builder_add_object(&b,
577
            SPA_TYPE_OBJECT_ParamBuffers, id,
578
-           SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 8, MAX_BUFFERS),
579
+           SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS),
580
            SPA_PARAM_BUFFERS_blocks,  SPA_POD_Int(1),
581
            SPA_PARAM_BUFFERS_size,    SPA_POD_CHOICE_RANGE_Int(
582
-                           this->props.max_latency * port->frame_size,
583
-                           this->props.min_latency * port->frame_size,
584
+                           this->quantum_limit * port->frame_size,
585
+                           16 * port->frame_size,
586
                            INT32_MAX),
587
            SPA_PARAM_BUFFERS_stride,  SPA_POD_Int(port->frame_size));
588
        break;
589
@@ -1021,6 +1018,12 @@
590
                SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_Buffers),
591
                SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers)));
592
            break;
593
+       case 1:
594
+           param = spa_pod_builder_add_object(&b,
595
+                   SPA_TYPE_OBJECT_ParamIO, id,
596
+                   SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_RateMatch),
597
+                   SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_rate_match)));
598
+           break;
599
        default:
600
            return 0;
601
        }
602
@@ -1059,7 +1062,6 @@
603
        spa_list_init(&port->ready);
604
        port->n_buffers = 0;
605
    }
606
-   port->current_buffer = NULL;
607
    return 0;
608
 }
609
 
610
@@ -1217,6 +1219,9 @@
611
    case SPA_IO_Buffers:
612
        port->io = data;
613
        break;
614
+   case SPA_IO_RateMatch:
615
+       port->rate_match = data;
616
+       break;
617
    default:
618
        return -ENOENT;
619
    }
620
@@ -1244,6 +1249,88 @@
621
    return 0;
622
 }
623
 
624
+static uint32_t get_samples(struct impl *this, uint32_t *duration)
625
+{
626
+   struct port *port = &this->port;
627
+   uint32_t samples;
628
+
629
+   if (SPA_LIKELY(port->rate_match) && this->resampling) {
630
+       samples = port->rate_match->size;
631
+   } else {
632
+       if (SPA_LIKELY(this->position))
633
+           samples = this->position->clock.duration * port->current_format.info.raw.rate
634
+               / this->position->clock.rate.denom;
635
+       else
636
+           samples = 1024;
637
+   }
638
+
639
+   if (SPA_LIKELY(this->position))
640
+       *duration = this->position->clock.duration * port->current_format.info.raw.rate
641
+           / this->position->clock.rate.denom;
642
+   else if (SPA_LIKELY(this->clock))
643
+       *duration = this->clock->duration * port->current_format.info.raw.rate
644
+           / this->clock->rate.denom;
645
+   else
646
+       *duration = 1024 * port->current_format.info.raw.rate / 48000;
647
+
648
+   return samples;
649
+}
650
+
651
+static void process_buffering(struct impl *this)
652
+{
653
+   struct port *port = &this->port;
654
+   uint32_t duration;
655
+   const uint32_t samples = get_samples(this, &duration);
656
+   uint32_t avail;
657
+   void *buf;
658
+
659
+   spa_bt_decode_buffer_process(&port->buffer, samples, duration);
660
+
661
+   setup_matching(this);
662
+
663
+   buf = spa_bt_decode_buffer_get_read(&port->buffer, &avail);
664
+
665
+   /* copy data to buffers */
666
+   if (!spa_list_is_empty(&port->free) && avail > 0) {
667
+       struct buffer *buffer;
668
+       struct spa_data *datas;
669
+       uint32_t data_size;
670
+
671
+       data_size = samples * port->frame_size;
672
+
673
+       avail = SPA_MIN(avail, data_size);
674
+
675
+       spa_bt_decode_buffer_read(&port->buffer, avail);
676
+
677
+       buffer = spa_list_first(&port->free, struct buffer, link);
678
+       spa_list_remove(&buffer->link);
679
+
680
+       spa_log_trace(this->log, "dequeue %d", buffer->id);
681
+
682
+       if (buffer->h) {
683
+           buffer->h->seq = this->sample_count;
684
+           buffer->h->pts = SPA_TIMESPEC_TO_NSEC(&this->now);
685
+           buffer->h->dts_offset = 0;
686
+       }
687
+
688
+       datas = buffer->buf->datas;
689
+
690
+       spa_assert(datas0.maxsize >= data_size);
691
+
692
+       datas0.chunk->offset = 0;
693
+       datas0.chunk->size = avail;
694
+       datas0.chunk->stride = port->frame_size;
695
+
696
+       memcpy(datas0.data, buf, avail);
697
+
698
+       this->sample_count += avail / port->frame_size;
699
+
700
+       /* ready buffer if full */
701
+       spa_log_trace(this->log, "queue %d frames:%d", buffer->id, (int)avail / port->frame_size);
702
+       spa_list_append(&port->ready, &buffer->link);
703
+   }
704
+}
705
+
706
 static int impl_node_process(void *object)
707
 {
708
    struct impl *this = object;
709
@@ -1269,6 +1356,9 @@
710
        io->buffer_id = SPA_ID_INVALID;
711
    }
712
 
713
+   /* Handle buffering delay */
714
+   process_buffering(this);
715
+
716
    /* Return if there are no buffers ready to be processed */
717
    if (spa_list_is_empty(&port->ready))
718
        return SPA_STATUS_OK;
719
@@ -1350,16 +1440,19 @@
720
 static int impl_clear(struct spa_handle *handle)
721
 {
722
    struct impl *this = (struct impl *) handle;
723
+   struct port *port = &this->port;
724
    if (this->codec_data)
725
        this->codec->deinit(this->codec_data);
726
    if (this->codec_props && this->codec->clear_props)
727
        this->codec->clear_props(this->codec_props);
728
    if (this->transport)
729
        spa_hook_remove(&this->transport_listener);
730
+   spa_system_close(this->data_system, this->timerfd);
731
    if (this->duplex_timerfd >= 0) {
732
        spa_system_close(this->data_system, this->duplex_timerfd);
733
        this->duplex_timerfd = -1;
734
    }
735
+   spa_bt_decode_buffer_clear(&port->buffer);
736
    return 0;
737
 }
738
 
739
@@ -1451,7 +1544,11 @@
740
    spa_list_init(&port->ready);
741
    spa_list_init(&port->free);
742
 
743
+   this->quantum_limit = 8192;
744
+
745
    if (info != NULL) {
746
+       if (info && (str = spa_dict_lookup(info, "clock.quantum-limit")))
747
+           spa_atou32(str, &this->quantum_limit, 0);
748
        if ((str = spa_dict_lookup(info, SPA_KEY_API_BLUEZ5_TRANSPORT)) != NULL)
749
            sscanf(str, "pointer:%p", &this->transport);
750
        if ((str = spa_dict_lookup(info, "bluez5.a2dp-source-role")) != NULL)
751
@@ -1486,6 +1583,9 @@
752
    spa_bt_transport_add_listener(this->transport,
753
            &this->transport_listener, &transport_events, this);
754
 
755
+   this->timerfd = spa_system_timerfd_create(this->data_system,
756
+           CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
757
+
758
    if (this->is_duplex) {
759
        this->duplex_timerfd = spa_system_timerfd_create(this->data_system,
760
                CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
761
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/bluez5-dbus.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/bluez5-dbus.c Changed
39
 
1
@@ -3293,18 +3293,20 @@
2
 
3
    ret = a2dp_codec_to_endpoint(codec, endpoint, &object_path);
4
    if (ret < 0)
5
-       return ret;
6
+       goto error;
7
 
8
-   caps_size = codec->fill_caps(codec, 0, caps);
9
-   if (caps_size < 0)
10
-       return caps_size;
11
+   ret = caps_size = codec->fill_caps(codec, 0, caps);
12
+   if (ret < 0)
13
+       goto error;
14
 
15
    m = dbus_message_new_method_call(BLUEZ_SERVICE,
16
                                     path,
17
                                     BLUEZ_MEDIA_INTERFACE,
18
                                     "RegisterEndpoint");
19
-   if (m == NULL)
20
-       return -EIO;
21
+   if (m == NULL) {
22
+       ret = -EIO;
23
+       goto error;
24
+   }
25
 
26
    dbus_message_iter_init_append(m, &object_it);
27
    dbus_message_iter_append_basic(&object_it, DBUS_TYPE_OBJECT_PATH, &object_path);
28
@@ -3327,6 +3329,10 @@
29
    free(object_path);
30
 
31
    return 0;
32
+
33
+error:
34
+   free(object_path);
35
+   return ret;
36
 }
37
 
38
 static int register_a2dp_endpoint(struct spa_bt_monitor *monitor,
39
pipewire-0.3.54.tar.gz/spa/plugins/bluez5/decode-buffer.h Added
383
 
1
@@ -0,0 +1,381 @@
2
+/* Spa Bluez5 decode buffer
3
+ *
4
+ * Copyright © 2022 Pauli Virtanen
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a
7
+ * copy of this software and associated documentation files (the "Software"),
8
+ * to deal in the Software without restriction, including without limitation
9
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
+ * and/or sell copies of the Software, and to permit persons to whom the
11
+ * Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice (including the next
14
+ * paragraph) shall be included in all copies or substantial portions of the
15
+ * Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ * DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+/**
27
+ * \file decode-buffer.h   Buffering for Bluetooth sources
28
+ *
29
+ * A linear buffer, which is compacted when it gets half full.
30
+ *
31
+ * Also contains buffering logic, which calculates a rate correction
32
+ * factor to maintain the buffer level at the target value.
33
+ *
34
+ * Consider typical packet intervals with nominal frame duration
35
+ * of 10ms:
36
+ *
37
+ *     ... 5ms | 5ms | 20ms | 5ms | 5ms | 20ms ...
38
+ *
39
+ *     ... 3ms | 3ms | 4ms | 30ms | 3ms | 3ms | 4ms | 30ms ...
40
+ *
41
+ * plus random jitter; 10ms nominal may occasionally have 20+ms interval.
42
+ * The regular timer cycle cannot be aligned with this, so process()
43
+ * may occur at any time.
44
+ *
45
+ * The buffer level is the difference between the number of samples in
46
+ * buffer immediately after receiving a packet, and the samples consumed
47
+ * before receiving the next packet.
48
+ *
49
+ * The buffer level indicates how much any packet can be delayed without
50
+ * underrun. If it is positive, there are no underruns.
51
+ *
52
+ * The rate correction aims to maintain the average level at a safety margin.
53
+ */
54
+
55
+#ifndef SPA_BLUEZ5_DECODE_BUFFER_H
56
+#define SPA_BLUEZ5_DECODE_BUFFER_H
57
+
58
+#include <stdlib.h>
59
+#include <spa/utils/defs.h>
60
+#include <spa/utils/dll.h>
61
+#include <spa/support/log.h>
62
+
63
+#define BUFFERING_LONG_MSEC        60000
64
+#define BUFFERING_SHORT_MSEC       1000
65
+#define BUFFERING_DLL_BW       0.03
66
+#define BUFFERING_RATE_DIFF_MAX        0.005
67
+
68
+/**
69
+ * Safety margin.
70
+ *
71
+ * The spike is the long-window maximum difference
72
+ * between minimum and average buffer level.
73
+ */
74
+#define BUFFERING_TARGET(spike,packet_size)                \
75
+   SPA_CLAMP((spike)*3/2, (packet_size), 6*(packet_size))
76
+
77
+/** Windowed min/max */
78
+struct spa_bt_ptp
79
+{
80
+   union {
81
+       int32_t min;
82
+       int32_t mins4;
83
+   };
84
+   union {
85
+       int32_t max;
86
+       int32_t maxs4;
87
+   };
88
+   uint32_t pos;
89
+   uint32_t period;
90
+};
91
+
92
+struct spa_bt_decode_buffer
93
+{
94
+   struct spa_log *log;
95
+
96
+   uint32_t frame_size;
97
+   uint32_t rate;
98
+
99
+   uint8_t *buffer_decoded;
100
+   uint32_t buffer_size;
101
+   uint32_t buffer_reserve;
102
+   uint32_t write_index;
103
+   uint32_t read_index;
104
+
105
+   struct spa_bt_ptp spike;    /**< spikes (long window) */
106
+   struct spa_bt_ptp packet_size;  /**< packet size (short window) */
107
+
108
+   int32_t target;
109
+   int32_t level;
110
+   double level_avg;
111
+
112
+   struct spa_dll dll;
113
+   double corr;
114
+
115
+   uint32_t prev_consumed;
116
+   uint32_t prev_avail;
117
+   uint32_t prev_duration;
118
+   uint32_t underrun;
119
+   uint32_t pos;
120
+
121
+   uint8_t received:1;
122
+   uint8_t buffering:1;
123
+};
124
+
125
+static void spa_bt_ptp_init(struct spa_bt_ptp *p, int32_t period)
126
+{
127
+   size_t i;
128
+
129
+   spa_zero(*p);
130
+   for (i = 0; i < SPA_N_ELEMENTS(p->mins); ++i) {
131
+       p->minsi = INT32_MAX;
132
+       p->maxsi = INT32_MIN;
133
+   }
134
+   p->period = period;
135
+}
136
+
137
+static void spa_bt_ptp_update(struct spa_bt_ptp *p, int32_t value, uint32_t duration)
138
+{
139
+   const size_t n = SPA_N_ELEMENTS(p->mins);
140
+   size_t i;
141
+
142
+   for (i = 0; i < n; ++i) {
143
+       p->minsi = SPA_MIN(p->minsi, value);
144
+       p->maxsi = SPA_MAX(p->maxsi, value);
145
+   }
146
+
147
+   p->pos += duration;
148
+   if (p->pos >= p->period / (n - 1)) {
149
+       p->pos = 0;
150
+       for (i = 1; i < SPA_N_ELEMENTS(p->mins); ++i) {
151
+           p->minsi-1 = p->minsi;
152
+           p->maxsi-1 = p->maxsi;
153
+       }
154
+       p->minsn-1 = INT32_MAX;
155
+       p->maxsn-1 = INT32_MIN;
156
+   }
157
+}
158
+
159
+static int spa_bt_decode_buffer_init(struct spa_bt_decode_buffer *this, struct spa_log *log,
160
+       uint32_t frame_size, uint32_t rate, uint32_t quantum_limit, uint32_t reserve)
161
+{
162
+   spa_zero(*this);
163
+   this->frame_size = frame_size;
164
+   this->rate = rate;
165
+   this->log = log;
166
+   this->buffer_reserve = this->frame_size * reserve;
167
+   this->buffer_size = this->frame_size * quantum_limit * 2;
168
+   this->buffer_size += this->buffer_reserve;
169
+   this->corr = 1.0;
170
+   this->buffering = true;
171
+
172
+   spa_dll_init(&this->dll);
173
+
174
+   spa_bt_ptp_init(&this->spike, (uint64_t)this->rate * BUFFERING_LONG_MSEC / 1000);
175
+   spa_bt_ptp_init(&this->packet_size, (uint64_t)this->rate * BUFFERING_SHORT_MSEC / 1000);
176
+
177
+   if ((this->buffer_decoded = malloc(this->buffer_size)) == NULL) {
178
+       this->buffer_size = 0;
179
+       return -ENOMEM;
180
+   }
181
+   return 0;
182
+}
183
+
184
+static void spa_bt_decode_buffer_clear(struct spa_bt_decode_buffer *this)
185
+{
186
+   free(this->buffer_decoded);
187
+   spa_zero(*this);
188
+}
189
+
190
+static void spa_bt_decode_buffer_compact(struct spa_bt_decode_buffer *this)
191
+{
192
+   uint32_t avail;
193
+
194
+   spa_assert(this->read_index <= this->write_index);
195
+
196
+   if (this->read_index == this->write_index) {
197
+       this->read_index = 0;
198
+       this->write_index = 0;
199
+       goto done;
200
+   }
201
+
202
+   if (this->write_index > this->read_index + this->buffer_size - this->buffer_reserve) {
203
+       /* Drop data to keep buffer reserve free */
204
+       spa_log_info(this->log, "%p buffer overrun: dropping data", this);
205
+       this->read_index = this->write_index + this->buffer_reserve - this->buffer_size;
206
+   }
207
+
208
+   if (this->write_index < (this->buffer_size - this->buffer_reserve) / 2
209
+           || this->read_index == 0)
210
+       goto done;
211
+
212
+   avail = this->write_index - this->read_index;
213
+   spa_memmove(this->buffer_decoded,
214
+           SPA_PTROFF(this->buffer_decoded, this->read_index, void),
215
+           avail);
216
+   this->read_index = 0;
217
+   this->write_index = avail;
218
+
219
+done:
220
+   spa_assert(this->buffer_size - this->write_index >= this->buffer_reserve);
221
+}
222
+
223
+static void *spa_bt_decode_buffer_get_write(struct spa_bt_decode_buffer *this, uint32_t *avail)
224
+{
225
+   spa_bt_decode_buffer_compact(this);
226
+   spa_assert(this->buffer_size >= this->write_index);
227
+   *avail = this->buffer_size - this->write_index;
228
+   return SPA_PTROFF(this->buffer_decoded, this->write_index, void);
229
+}
230
+
231
+static void spa_bt_decode_buffer_write_packet(struct spa_bt_decode_buffer *this, uint32_t size)
232
+{
233
+   spa_assert(size % this->frame_size == 0);
234
+   this->write_index += size;
235
+   this->received = true;
236
+   spa_bt_ptp_update(&this->packet_size, size / this->frame_size, size / this->frame_size);
237
+}
238
+
239
+static void *spa_bt_decode_buffer_get_read(struct spa_bt_decode_buffer *this, uint32_t *avail)
240
+{
241
+   spa_assert(this->write_index >= this->read_index);
242
+   if (!this->buffering)
243
+       *avail = this->write_index - this->read_index;
244
+   else
245
+       *avail = 0;
246
+   return SPA_PTROFF(this->buffer_decoded, this->read_index, void);
247
+}
248
+
249
+static void spa_bt_decode_buffer_read(struct spa_bt_decode_buffer *this, uint32_t size)
250
+{
251
+   spa_assert(size % this->frame_size == 0);
252
+   this->read_index += size;
253
+}
254
+
255
+static void spa_bt_decode_buffer_recover(struct spa_bt_decode_buffer *this)
256
+{
257
+   int32_t size = (this->write_index - this->read_index) / this->frame_size;
258
+
259
+   this->prev_avail = size * this->frame_size;
260
+   this->prev_consumed = this->prev_duration;
261
+   this->level = (int32_t)this->prev_avail/this->frame_size
262
+       - (int32_t)this->prev_duration;
263
+   this->level_avg = this->level;
264
+   this->target = this->level;
265
+   this->corr = 1.0;
266
+
267
+   spa_dll_init(&this->dll);
268
+}
269
+
270
+static void spa_bt_decode_buffer_process(struct spa_bt_decode_buffer *this, uint32_t samples, uint32_t duration)
271
+{
272
+   const uint32_t data_size = samples * this->frame_size;
273
+   const int32_t max_level = SPA_MAX(8 * this->packet_size.max, (int32_t)duration);
274
+   uint32_t avail;
275
+
276
+   if (SPA_UNLIKELY(duration != this->prev_duration)) {
277
+       this->prev_duration = duration;
278
+       spa_bt_decode_buffer_recover(this);
279
+   }
280
+
281
+   if (SPA_UNLIKELY(this->buffering)) {
282
+       int32_t size = (this->write_index - this->read_index) / this->frame_size;
283
+
284
+       this->corr = 1.0;
285
+
286
+       spa_log_trace(this->log, "%p buffering size:%d", this, (int)size);
287
+
288
+       if (this->received &&
289
+               this->packet_size.max > 0 &&
290
+               size >= SPA_MAX(3*this->packet_size.max, (int32_t)duration))
291
+           this->buffering = false;
292
+       else
293
+           return;
294
+
295
+       spa_bt_decode_buffer_recover(this);
296
+   }
297
+
298
+   if (SPA_UNLIKELY(this->dll.bw == 0.0)) {
299
+       spa_log_trace(this->log, "%p dll reset duration:%d rate:%d", this,
300
+               (int)duration, (int)this->rate);
301
+       spa_dll_set_bw(&this->dll, BUFFERING_DLL_BW, duration, (uint64_t)this->rate);
302
+   }
303
+
304
+   spa_bt_decode_buffer_get_read(this, &avail);
305
+
306
+   if (this->received) {
307
+       const uint32_t avg_period = (uint64_t)this->rate * BUFFERING_SHORT_MSEC / 1000;
308
+       int32_t level, target;
309
+
310
+       /* Track buffer level */
311
+       level = (int32_t)(this->prev_avail/this->frame_size) - (int32_t)this->prev_consumed;
312
+       level = SPA_MAX(level, -max_level);
313
+       this->prev_consumed = SPA_MIN(this->prev_consumed, avg_period);
314
+
315
+       this->level_avg = ((double)this->prev_consumed*level
316
+               + ((double)avg_period - this->prev_consumed)*this->level_avg) / avg_period;
317
+       spa_bt_ptp_update(&this->spike, this->level_avg - level, this->prev_consumed);
318
+
319
+       /* Update target level */
320
+       target = BUFFERING_TARGET(this->spike.max, this->packet_size.max);
321
+
322
+       if (level > SPA_MAX(4 * target, 2*(int32_t)duration) &&
323
+               avail > data_size) {
324
+           /* Lagging too much: drop data */
325
+           uint32_t size = SPA_MIN(avail - data_size,
326
+                   (level - target*5/2) * this->frame_size);
327
+
328
+           spa_bt_decode_buffer_read(this, size);
329
+           spa_log_trace(this->log, "%p overrun samples:%d level:%d target:%d",
330
+                   this, (int)size/this->frame_size,
331
+                   (int)level, (int)target);
332
+
333
+           spa_bt_decode_buffer_recover(this);
334
+       }
335
+
336
+       this->pos += this->prev_consumed;
337
+       if (this->pos > this->rate) {
338
+           spa_log_debug(this->log,
339
+                   "%p avg:%d target:%d level:%d buffer:%d spike:%d corr:%f",
340
+                   this,
341
+                   (int)this->level_avg,
342
+                   (int)target,
343
+                   (int)level,
344
+                   (int)(avail / this->frame_size),
345
+                   (int)this->spike.max,
346
+                   (double)this->corr);
347
+           this->pos = 0;
348
+       }
349
+
350
+       spa_bt_decode_buffer_get_read(this, &avail);
351
+
352
+       this->prev_consumed = 0;
353
+       this->prev_avail = avail;
354
+       this->underrun = 0;
355
+       this->received = false;
356
+       this->level = level;
357
+       this->target = target;
358
+   }
359
+
360
+   this->corr = spa_dll_update(&this->dll, this->target - this->level);
361
+
362
+   if (SPA_ABS(this->corr - 1.0) > BUFFERING_RATE_DIFF_MAX) {
363
+       spa_log_trace(this->log, "%p too big rate difference: clamp + reset", this);
364
+       spa_dll_init(&this->dll);
365
+       this->corr = SPA_CLAMP(this->corr, 1.0 - BUFFERING_RATE_DIFF_MAX,
366
+               1.0 + BUFFERING_RATE_DIFF_MAX);
367
+   }
368
+
369
+   if (avail < data_size) {
370
+       spa_log_trace(this->log, "%p underrun samples:%d", this,
371
+               (data_size - avail) / this->frame_size);
372
+       this->underrun += samples;
373
+       if (this->underrun >= SPA_MIN((uint32_t)max_level, this->buffer_size / this->frame_size)) {
374
+           this->buffering = true;
375
+           spa_log_debug(this->log, "%p underrun too much: start buffering", this);
376
+       }
377
+   }
378
+
379
+   this->prev_consumed += samples;
380
+}
381
+
382
+#endif
383
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/sco-io.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/sco-io.c Changed
45
 
1
@@ -55,16 +55,12 @@
2
  * since kernel might not report it as the socket MTU, see
3
  * https://lore.kernel.org/linux-bluetooth/20201210003528.3pmaxvubiwegxmhl@pali/T/
4
  *
5
- * Since 24 is the packet size for the smallest setting (ALT1), we'll stop
6
- * reading when rx packet of at least this size is seen, and use its size as the
7
- * heuristic maximum write MTU. Of course, if we have a source connected, we'll
8
- * continue reading without stopping.
9
+ * We continue reading also when there's no source connected, to keep socket
10
+ * flushed.
11
  *
12
  * XXX: when the kernel/backends start giving the right values, the heuristic
13
  * XXX: can be removed
14
  */
15
-#define HEURISTIC_MIN_MTU 24
16
-
17
 #define MAX_MTU 1024
18
 
19
 
20
@@ -94,12 +90,6 @@
21
    int enabled;
22
    int changed = 0;
23
 
24
-   enabled = io->source_cb != NULL || io->read_size < HEURISTIC_MIN_MTU;
25
-   if (SPA_FLAG_IS_SET(io->source.mask, SPA_IO_IN) != enabled) {
26
-       SPA_FLAG_UPDATE(io->source.mask, SPA_IO_IN, enabled);
27
-       changed = 1;
28
-   }
29
-
30
    enabled = io->sink_cb != NULL;
31
    if (SPA_FLAG_IS_SET(io->source.mask, SPA_IO_OUT) != enabled) {
32
        SPA_FLAG_UPDATE(io->source.mask, SPA_IO_OUT, enabled);
33
@@ -118,11 +108,6 @@
34
    if (SPA_FLAG_IS_SET(source->rmask, SPA_IO_IN)) {
35
        int res;
36
 
37
-       /*
38
-        * Note that we will read from the socket for a few times even
39
-        * when there is no source callback, to autodetect packet size.
40
-        */
41
-
42
    read_again:
43
        res = read(io->fd, io->read_buffer, SPA_MIN(io->read_mtu, MAX_MTU));
44
        if (res <= 0) {
45
pipewire-0.3.53.tar.gz/spa/plugins/bluez5/sco-source.c -> pipewire-0.3.54.tar.gz/spa/plugins/bluez5/sco-source.c Changed
736
 
1
@@ -58,11 +58,11 @@
2
 #undef SPA_LOG_TOPIC_DEFAULT
3
 #define SPA_LOG_TOPIC_DEFAULT &log_topic
4
 
5
+#include "decode-buffer.h"
6
+
7
 #define DEFAULT_CLOCK_NAME "clock.system.monotonic"
8
 
9
 struct props {
10
-   uint32_t min_latency;
11
-   uint32_t max_latency;
12
    char clock_name64;
13
 };
14
 
15
@@ -101,8 +101,7 @@
16
    struct spa_list free;
17
    struct spa_list ready;
18
 
19
-   struct buffer *current_buffer;
20
-   uint32_t ready_offset;
21
+   struct spa_bt_decode_buffer buffer;
22
 };
23
 
24
 struct impl {
25
@@ -116,6 +115,8 @@
26
    struct spa_hook_list hooks;
27
    struct spa_callbacks callbacks;
28
 
29
+   uint32_t quantum_limit;
30
+
31
    uint64_t info_all;
32
    struct spa_node_info info;
33
 #define IDX_PropInfo   0
34
@@ -132,10 +133,18 @@
35
 
36
    unsigned int started:1;
37
    unsigned int following:1;
38
+   unsigned int matching:1;
39
+   unsigned int resampling:1;
40
+
41
+   struct spa_source timer_source;
42
+   int timerfd;
43
 
44
    struct spa_io_clock *clock;
45
    struct spa_io_position *position;
46
 
47
+   uint64_t current_time;
48
+   uint64_t next_time;
49
+
50
    /* mSBC */
51
    sbc_t msbc;
52
    bool msbc_seq_initialized;
53
@@ -150,13 +159,8 @@
54
 
55
 #define CHECK_PORT(this,d,p)   ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
56
 
57
-static const uint32_t default_min_latency = 128;
58
-static const uint32_t default_max_latency = 512;
59
-
60
 static void reset_props(struct props *props)
61
 {
62
-   props->min_latency = default_min_latency;
63
-   props->max_latency = default_max_latency;
64
    strncpy(props->clock_name, DEFAULT_CLOCK_NAME, sizeof(props->clock_name));
65
 }
66
 
67
@@ -184,23 +188,7 @@
68
    switch (id) {
69
    case SPA_PARAM_PropInfo:
70
    {
71
-       struct props *p = &this->props;
72
-
73
        switch (result.index) {
74
-       case 0:
75
-           param = spa_pod_builder_add_object(&b,
76
-               SPA_TYPE_OBJECT_PropInfo, id,
77
-               SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_minLatency),
78
-               SPA_PROP_INFO_description, SPA_POD_String("The minimum latency"),
79
-               SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX));
80
-           break;
81
-       case 1:
82
-           param = spa_pod_builder_add_object(&b,
83
-               SPA_TYPE_OBJECT_PropInfo, id,
84
-               SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_maxLatency),
85
-               SPA_PROP_INFO_description, SPA_POD_String("The maximum latency"),
86
-               SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX));
87
-           break;
88
        default:
89
            return 0;
90
        }
91
@@ -208,15 +196,7 @@
92
    }
93
    case SPA_PARAM_Props:
94
    {
95
-       struct props *p = &this->props;
96
-
97
        switch (result.index) {
98
-       case 0:
99
-           param = spa_pod_builder_add_object(&b,
100
-               SPA_TYPE_OBJECT_Props, id,
101
-               SPA_PROP_minLatency, SPA_POD_Int(p->min_latency),
102
-               SPA_PROP_maxLatency, SPA_POD_Int(p->max_latency));
103
-           break;
104
        default:
105
            return 0;
106
        }
107
@@ -237,6 +217,41 @@
108
    return 0;
109
 }
110
 
111
+static int set_timeout(struct impl *this, uint64_t time)
112
+{
113
+       struct itimerspec ts;
114
+       ts.it_value.tv_sec = time / SPA_NSEC_PER_SEC;
115
+       ts.it_value.tv_nsec = time % SPA_NSEC_PER_SEC;
116
+       ts.it_interval.tv_sec = 0;
117
+       ts.it_interval.tv_nsec = 0;
118
+       return spa_system_timerfd_settime(this->data_system,
119
+              this->timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
120
+}
121
+
122
+static int set_timers(struct impl *this)
123
+{
124
+       struct timespec now;
125
+
126
+       spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &now);
127
+       this->next_time = SPA_TIMESPEC_TO_NSEC(&now);
128
+
129
+       return set_timeout(this, this->following ? 0 : this->next_time);
130
+}
131
+
132
+static int do_reassign_follower(struct spa_loop *loop,
133
+           bool async,
134
+           uint32_t seq,
135
+           const void *data,
136
+           size_t size,
137
+           void *user_data)
138
+{
139
+   struct impl *this = user_data;
140
+   struct port *port = &this->port;
141
+
142
+   spa_bt_decode_buffer_recover(&port->buffer);
143
+   return 0;
144
+}
145
+
146
 static inline bool is_following(struct impl *this)
147
 {
148
    return this->position && this->clock && this->position->clock.id != this->clock->id;
149
@@ -269,6 +284,7 @@
150
    if (this->started && following != this->following) {
151
        spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
152
        this->following = following;
153
+       spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
154
    }
155
 
156
    return 0;
157
@@ -284,10 +300,7 @@
158
    if (param == NULL) {
159
        reset_props(&new_props);
160
    } else {
161
-       spa_pod_parse_object(param,
162
-               SPA_TYPE_OBJECT_Props, NULL,
163
-               SPA_PROP_minLatency, SPA_POD_OPT_Int(&new_props.min_latency),
164
-               SPA_PROP_maxLatency, SPA_POD_OPT_Int(&new_props.max_latency));
165
+       /* noop */
166
    }
167
 
168
    changed = (memcmp(&new_props, &this->props, sizeof(struct props)) != 0);
169
@@ -326,8 +339,6 @@
170
    spa_list_init(&port->free);
171
    spa_list_init(&port->ready);
172
 
173
-   port->current_buffer = NULL;
174
-
175
    for (i = 0; i < port->n_buffers; i++) {
176
        struct buffer *b = &port->buffersi;
177
        spa_list_append(&port->free, &b->link);
178
@@ -422,116 +433,107 @@
179
    return true;
180
 }
181
 
182
-static void preprocess_and_decode_msbc_data(void *userdata, uint8_t *read_data, int size_read)
183
+static uint32_t preprocess_and_decode_msbc_data(void *userdata, uint8_t *read_data, int size_read)
184
 {
185
    struct impl *this = userdata;
186
    struct port *port = &this->port;
187
-   struct spa_data *datas = port->current_buffer->buf->datas;
188
+   uint32_t decoded = 0;
189
+   int i;
190
 
191
    spa_log_trace(this->log, "handling mSBC data");
192
 
193
-   /* check if the packet contains only zeros - if so ignore the packet.
194
-      This is necessary, because some kernels insert bogus "all-zero" packets
195
-      into the datastream.
196
-      See https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/549 */
197
-   if (is_zero_packet(read_data, size_read)) {
198
-       return;
199
-   }
200
+   /*
201
+    * Check if the packet contains only zeros - if so ignore the packet.
202
+    * This is necessary, because some kernels insert bogus "all-zero" packets
203
+    * into the datastream.
204
+    * See https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/549
205
+    */
206
+   if (is_zero_packet(read_data, size_read))
207
+       return 0;
208
 
209
-   int i;
210
    for (i = 0; i < size_read; ++i) {
211
+       void *buf;
212
+       uint32_t avail;
213
+       int seq, processed;
214
+       size_t written;
215
+
216
        msbc_buffer_append_byte(this, read_datai);
217
 
218
-       /* Handle found mSBC packets.
219
-        *
220
-        * XXX: if there's no space for the decoded audio in
221
-        * XXX: the current buffer, we'll drop data.
222
+       if (this->msbc_buffer_pos != MSBC_ENCODED_SIZE)
223
+           continue;
224
+
225
+       /*
226
+        * Handle found mSBC packet
227
         */
228
-       if (this->msbc_buffer_pos == MSBC_ENCODED_SIZE) {
229
-           spa_log_trace(this->log, "Received full mSBC packet, start processing it");
230
-
231
-           if (port->ready_offset + MSBC_DECODED_SIZE <= datas0.maxsize) {
232
-               int seq, processed;
233
-               size_t written;
234
-               spa_log_trace(this->log,
235
-                   "Output buffer has space, processing mSBC packet");
236
-
237
-               /* Check sequence number */
238
-               seq = ((this->msbc_buffer1 >> 4) & 1) |
239
-                     ((this->msbc_buffer1 >> 6) & 2);
240
-
241
-               spa_log_trace(this->log, "mSBC packet seq=%u", seq);
242
-               if (!this->msbc_seq_initialized) {
243
-                   this->msbc_seq_initialized = true;
244
-                   this->msbc_seq = seq;
245
-               } else if (seq != this->msbc_seq) {
246
-                   spa_log_info(this->log,
247
-                       "missing mSBC packet: %u != %u", seq, this->msbc_seq);
248
-                   this->msbc_seq = seq;
249
-                   /* TODO: Implement PLC. */
250
-               }
251
-               this->msbc_seq = (this->msbc_seq + 1) % 4;
252
-
253
-               /* decode frame */
254
-               processed = sbc_decode(
255
-                   &this->msbc, this->msbc_buffer + 2, MSBC_ENCODED_SIZE - 3,
256
-                   (uint8_t *)datas0.data + port->ready_offset, MSBC_DECODED_SIZE,
257
-                   &written);
258
-
259
-               if (processed < 0) {
260
-                   spa_log_warn(this->log, "sbc_decode failed: %d", processed);
261
-                   /* TODO: manage errors */
262
-                   continue;
263
-               }
264
-
265
-               port->ready_offset += written;
266
-
267
-           } else {
268
-               spa_log_warn(this->log, "Output buffer full, dropping mSBC packet");
269
-           }
270
+
271
+       buf = spa_bt_decode_buffer_get_write(&port->buffer, &avail);
272
+
273
+       /* Check sequence number */
274
+       seq = ((this->msbc_buffer1 >> 4) & 1) |
275
+           ((this->msbc_buffer1 >> 6) & 2);
276
+
277
+       spa_log_trace(this->log, "mSBC packet seq=%u", seq);
278
+       if (!this->msbc_seq_initialized) {
279
+           this->msbc_seq_initialized = true;
280
+           this->msbc_seq = seq;
281
+       } else if (seq != this->msbc_seq) {
282
+           /* TODO: PLC (too late to insert data now) */
283
+           spa_log_info(this->log,
284
+                   "missing mSBC packet: %u != %u", seq, this->msbc_seq);
285
+           this->msbc_seq = seq;
286
        }
287
+
288
+       this->msbc_seq = (this->msbc_seq + 1) % 4;
289
+
290
+       if (avail < MSBC_DECODED_SIZE)
291
+           spa_log_warn(this->log, "Output buffer full, dropping msbc data");
292
+
293
+       /* decode frame */
294
+       processed = sbc_decode(
295
+           &this->msbc, this->msbc_buffer + 2, MSBC_ENCODED_SIZE - 3,
296
+                   buf, avail, &written);
297
+
298
+       if (processed < 0) {
299
+           spa_log_warn(this->log, "sbc_decode failed: %d", processed);
300
+           /* TODO: manage errors */
301
+           continue;
302
+       }
303
+
304
+       spa_bt_decode_buffer_write_packet(&port->buffer, written);
305
+       decoded += written;
306
    }
307
+
308
+   return decoded;
309
 }
310
 
311
 static int sco_source_cb(void *userdata, uint8_t *read_data, int size_read)
312
 {
313
    struct impl *this = userdata;
314
    struct port *port = &this->port;
315
-   struct spa_io_buffers *io = port->io;
316
-   struct spa_data *datas;
317
-   uint32_t min_data;
318
+   uint32_t decoded;
319
+   uint64_t dt;
320
 
321
    if (this->transport == NULL) {
322
        spa_log_debug(this->log, "no transport, stop reading");
323
        goto stop;
324
    }
325
 
326
-   /* get buffer */
327
-   if (!port->current_buffer) {
328
-       if (spa_list_is_empty(&port->free)) {
329
-           spa_log_warn(this->log, "buffer not available");
330
-           return 0;
331
-       }
332
-       port->current_buffer = spa_list_first(&port->free, struct buffer, link);
333
-       spa_list_remove(&port->current_buffer->link);
334
-       port->ready_offset = 0;
335
-   }
336
-   datas = port->current_buffer->buf->datas;
337
-
338
    /* update the current pts */
339
+   dt = SPA_TIMESPEC_TO_NSEC(&this->now);
340
    spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &this->now);
341
+   dt = SPA_TIMESPEC_TO_NSEC(&this->now) - dt;
342
 
343
    /* handle data read from socket */
344
-   spa_log_trace(this->log, "read socket data %d", size_read);
345
 #if 0
346
    hexdump_to_log(this, read_data, size_read);
347
 #endif
348
 
349
    if (this->transport->codec == HFP_AUDIO_CODEC_MSBC) {
350
-       preprocess_and_decode_msbc_data(userdata, read_data, size_read);
351
-
352
+       decoded = preprocess_and_decode_msbc_data(userdata, read_data, size_read);
353
    } else {
354
+       uint32_t avail;
355
        uint8_t *packet;
356
+
357
        if (size_read != 48 && is_zero_packet(read_data, size_read)) {
358
            /* Adapter is returning non-standard CVSD stream. For example
359
             * Intel 8087:0029 at Firmware revision 0.0 build 191 week 21 2021
360
@@ -539,62 +541,92 @@
361
             */
362
            return 0;
363
        }
364
-       packet = (uint8_t *)datas0.data + port->ready_offset;
365
-       spa_memmove(packet, read_data, size_read);
366
-       port->ready_offset += size_read;
367
+
368
+       packet = spa_bt_decode_buffer_get_write(&port->buffer, &avail);
369
+       avail = SPA_MIN(avail, (uint32_t)size_read);
370
+       spa_memmove(packet, read_data, avail);
371
+       spa_bt_decode_buffer_write_packet(&port->buffer, avail);
372
+
373
+       decoded = avail;
374
    }
375
 
376
-   /* send buffer if full */
377
-   min_data = SPA_MIN(this->props.min_latency * port->frame_size, datas0.maxsize / 2);
378
-   if (port->ready_offset >= min_data) {
379
-       uint64_t sample_count;
380
+   spa_log_trace(this->log, "read socket data size:%d decoded frames:%d dt:%d dms",
381
+           size_read, decoded / port->frame_size,
382
+           (int)(dt / 100000));
383
 
384
-       datas0.chunk->offset = 0;
385
-       datas0.chunk->size = port->ready_offset;
386
-       datas0.chunk->stride = port->frame_size;
387
+   return 0;
388
 
389
-       sample_count = datas0.chunk->size / port->frame_size;
390
-       spa_list_append(&port->ready, &port->current_buffer->link);
391
-       port->current_buffer = NULL;
392
-
393
-       if (!this->following && this->clock) {
394
-           this->clock->nsec = SPA_TIMESPEC_TO_NSEC(&this->now);
395
-           this->clock->duration = sample_count * this->clock->rate.denom / port->current_format.info.raw.rate;
396
-           this->clock->position += this->clock->duration;
397
-           this->clock->delay = 0;
398
-           this->clock->rate_diff = 1.0f;
399
-           this->clock->next_nsec = this->clock->nsec;
400
-       }
401
+stop:
402
+   return 1;
403
+}
404
+
405
+static int setup_matching(struct impl *this)
406
+{
407
+   struct port *port = &this->port;
408
+
409
+   if (this->position && port->rate_match) {
410
+       port->rate_match->rate = 1 / port->buffer.corr;
411
+
412
+       this->matching = this->following;
413
+       this->resampling = this->matching ||
414
+           (port->current_format.info.raw.rate != this->position->clock.rate.denom);
415
+   } else {
416
+       this->matching = false;
417
+       this->resampling = false;
418
    }
419
 
420
-   /* done if there are no buffers ready */
421
-   if (spa_list_is_empty(&port->ready))
422
-       return 0;
423
+   if (port->rate_match)
424
+       SPA_FLAG_UPDATE(port->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, this->matching);
425
 
426
-   if (this->following)
427
-       return 0;
428
+   return 0;
429
+}
430
 
431
-   /* process the buffer if IO does not have any */
432
-   if (io->status != SPA_STATUS_HAVE_DATA) {
433
-       struct buffer *b;
434
+static void sco_on_timeout(struct spa_source *source)
435
+{
436
+   struct impl *this = source->data;
437
+   struct port *port = &this->port;
438
+   uint64_t exp, duration;
439
+   uint32_t rate;
440
+   struct spa_io_buffers *io = port->io;
441
+   uint64_t prev_time, now_time;
442
+
443
+   if (this->transport == NULL)
444
+       return;
445
 
446
-       if (io->buffer_id < port->n_buffers)
447
-           recycle_buffer(this, port, io->buffer_id);
448
+   if (this->started && spa_system_timerfd_read(this->data_system, this->timerfd, &exp) < 0)
449
+       spa_log_warn(this->log, "error reading timerfd: %s", strerror(errno));
450
 
451
-       b = spa_list_first(&port->ready, struct buffer, link);
452
-       spa_list_remove(&b->link);
453
-       b->outstanding = true;
454
+   prev_time = this->current_time;
455
+   now_time = this->current_time = this->next_time;
456
 
457
-       io->buffer_id = b->id;
458
-       io->status = SPA_STATUS_HAVE_DATA;
459
+   spa_log_trace(this->log, "%p: timer %"PRIu64" %"PRIu64"", this,
460
+           now_time, now_time - prev_time);
461
+
462
+   if (SPA_LIKELY(this->position)) {
463
+       duration = this->position->clock.duration;
464
+       rate = this->position->clock.rate.denom;
465
+   } else {
466
+       duration = 1024;
467
+       rate = 48000;
468
    }
469
 
470
-   /* notify ready */
471
+   setup_matching(this);
472
+
473
+   this->next_time = now_time + duration * SPA_NSEC_PER_SEC / port->buffer.corr / rate;
474
+
475
+   if (SPA_LIKELY(this->clock)) {
476
+       this->clock->nsec = now_time;
477
+       this->clock->position += duration;
478
+       this->clock->duration = duration;
479
+       this->clock->rate_diff = port->buffer.corr;
480
+       this->clock->next_nsec = this->next_time;
481
+   }
482
+
483
+   spa_log_trace(this->log, "%p: %d", this, io->status);
484
+   io->status = SPA_STATUS_HAVE_DATA;
485
    spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_DATA);
486
-   return 0;
487
 
488
-stop:
489
-   return 1;
490
+   set_timeout(this, this->next_time);
491
 }
492
 
493
 static int do_add_source(struct spa_loop *loop,
494
@@ -613,6 +645,7 @@
495
 
496
 static int do_start(struct impl *this)
497
 {
498
+   struct port *port = &this->port;
499
    bool do_accept;
500
    int res;
501
 
502
@@ -636,7 +669,13 @@
503
        return res;
504
 
505
    /* Reset the buffers and sample count */
506
-   reset_buffers(&this->port);
507
+   reset_buffers(port);
508
+
509
+   spa_bt_decode_buffer_clear(&port->buffer);
510
+   if ((res = spa_bt_decode_buffer_init(&port->buffer, this->log,
511
+           port->frame_size, port->current_format.info.raw.rate,
512
+           this->quantum_limit, this->quantum_limit)) < 0)
513
+       return res;
514
 
515
    /* Init mSBC if needed */
516
    if (this->transport->codec == HFP_AUDIO_CODEC_MSBC) {
517
@@ -653,6 +692,17 @@
518
        goto fail;
519
    spa_loop_invoke(this->data_loop, do_add_source, 0, NULL, 0, true, this);
520
 
521
+   /* Start timer */
522
+   this->timer_source.data = this;
523
+   this->timer_source.fd = this->timerfd;
524
+   this->timer_source.func = sco_on_timeout;
525
+   this->timer_source.mask = SPA_IO_IN;
526
+   this->timer_source.rmask = 0;
527
+   spa_loop_add_source(this->data_loop, &this->timer_source);
528
+
529
+   setup_matching(this);
530
+   set_timers(this);
531
+
532
    /* Set the started flag */
533
    this->started = true;
534
 
535
@@ -671,15 +721,25 @@
536
                void *user_data)
537
 {
538
    struct impl *this = user_data;
539
+   struct itimerspec ts;
540
 
541
    if (this->transport && this->transport->sco_io)
542
        spa_bt_sco_io_set_source_cb(this->transport->sco_io, NULL, NULL);
543
 
544
+   if (this->timer_source.loop)
545
+       spa_loop_remove_source(this->data_loop, &this->timer_source);
546
+   ts.it_value.tv_sec = 0;
547
+   ts.it_value.tv_nsec = 0;
548
+   ts.it_interval.tv_sec = 0;
549
+   ts.it_interval.tv_nsec = 0;
550
+   spa_system_timerfd_settime(this->data_system, this->timerfd, 0, &ts, NULL);
551
+
552
    return 0;
553
 }
554
 
555
 static int do_stop(struct impl *this)
556
 {
557
+   struct port *port = &this->port;
558
    int res = 0;
559
 
560
    if (!this->started)
561
@@ -696,6 +756,8 @@
562
        res = spa_bt_transport_release(this->transport);
563
    }
564
 
565
+   spa_bt_decode_buffer_clear(&port->buffer);
566
+
567
    return res;
568
 }
569
 
570
@@ -738,12 +800,9 @@
571
        { SPA_KEY_MEDIA_CLASS, "Audio/Source" },
572
        { SPA_KEY_NODE_DRIVER, "true" },
573
    };
574
-
575
-   char latency64 = "128/8000";
576
    const struct spa_dict_item ag_node_info_items = {
577
        { SPA_KEY_DEVICE_API, "bluez5" },
578
        { SPA_KEY_MEDIA_CLASS, "Stream/Output/Audio" },
579
-       { SPA_KEY_NODE_LATENCY, latency },
580
        { "media.name", ((this->transport && this->transport->device->name) ?
581
                    this->transport->device->name : "HSP/HFP") },
582
    };
583
@@ -753,9 +812,6 @@
584
    if (full)
585
        this->info.change_mask = this->info_all;
586
    if (this->info.change_mask) {
587
-       if (this->transport && this->port.have_format)
588
-           snprintf(latency, sizeof(latency), "%d/%d", (int)this->props.min_latency,
589
-                   (int)this->port.current_format.info.raw.rate);
590
        this->info.props = is_ag ?
591
            &SPA_DICT_INIT_ARRAY(ag_node_info_items) :
592
            &SPA_DICT_INIT_ARRAY(hu_node_info_items);
593
@@ -902,11 +958,11 @@
594
 
595
        param = spa_pod_builder_add_object(&b,
596
            SPA_TYPE_OBJECT_ParamBuffers, id,
597
-           SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 8, MAX_BUFFERS),
598
+           SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS),
599
            SPA_PARAM_BUFFERS_blocks,  SPA_POD_Int(1),
600
            SPA_PARAM_BUFFERS_size,    SPA_POD_CHOICE_RANGE_Int(
601
-                           this->props.max_latency * port->frame_size,
602
-                           this->props.min_latency * port->frame_size,
603
+                           this->quantum_limit * port->frame_size,
604
+                           16 * port->frame_size,
605
                            INT32_MAX),
606
            SPA_PARAM_BUFFERS_stride,  SPA_POD_Int(port->frame_size));
607
        break;
608
@@ -976,7 +1032,6 @@
609
        spa_list_init(&port->ready);
610
        port->n_buffers = 0;
611
    }
612
-   port->current_buffer = NULL;
613
    return 0;
614
 }
615
 
616
@@ -1147,6 +1202,79 @@
617
    return 0;
618
 }
619
 
620
+static uint32_t get_samples(struct impl *this, uint32_t *duration)
621
+{
622
+   struct port *port = &this->port;
623
+   uint32_t samples;
624
+
625
+   if (SPA_LIKELY(port->rate_match) && this->resampling) {
626
+       samples = port->rate_match->size;
627
+   } else {
628
+       if (SPA_LIKELY(this->position))
629
+           samples = this->position->clock.duration * port->current_format.info.raw.rate
630
+               / this->position->clock.rate.denom;
631
+       else
632
+           samples = 1024;
633
+   }
634
+
635
+   if (SPA_LIKELY(this->position))
636
+       *duration = this->position->clock.duration * port->current_format.info.raw.rate
637
+           / this->position->clock.rate.denom;
638
+   else if (SPA_LIKELY(this->clock))
639
+       *duration = this->clock->duration * port->current_format.info.raw.rate
640
+           / this->clock->rate.denom;
641
+   else
642
+       *duration = 1024 * port->current_format.info.raw.rate / 48000;
643
+
644
+   return samples;
645
+}
646
+
647
+static void process_buffering(struct impl *this)
648
+{
649
+   struct port *port = &this->port;
650
+   uint32_t duration;
651
+   const uint32_t samples = get_samples(this, &duration);
652
+   void *buf;
653
+   uint32_t avail;
654
+
655
+   spa_bt_decode_buffer_process(&port->buffer, samples, duration);
656
+
657
+   setup_matching(this);
658
+
659
+   buf = spa_bt_decode_buffer_get_read(&port->buffer, &avail);
660
+
661
+   /* copy data to buffers */
662
+   if (!spa_list_is_empty(&port->free) && avail > 0) {
663
+       struct buffer *buffer;
664
+       struct spa_data *datas;
665
+       uint32_t data_size;
666
+
667
+       data_size = samples * port->frame_size;
668
+
669
+       avail = SPA_MIN(avail, data_size);
670
+
671
+       spa_bt_decode_buffer_read(&port->buffer, avail);
672
+
673
+       buffer = spa_list_first(&port->free, struct buffer, link);
674
+       spa_list_remove(&buffer->link);
675
+
676
+       spa_log_trace(this->log, "dequeue %d", buffer->id);
677
+
678
+       datas = buffer->buf->datas;
679
+
680
+       spa_assert(datas0.maxsize >= data_size);
681
+
682
+       datas0.chunk->offset = 0;
683
+       datas0.chunk->size = avail;
684
+       datas0.chunk->stride = port->frame_size;
685
+       memcpy(datas0.data, buf, avail);
686
+
687
+       /* ready buffer if full */
688
+       spa_log_trace(this->log, "queue %d frames:%d", buffer->id, (int)avail / port->frame_size);
689
+       spa_list_append(&port->ready, &buffer->link);
690
+   }
691
+}
692
+
693
 static int impl_node_process(void *object)
694
 {
695
    struct impl *this = object;
696
@@ -1170,6 +1298,9 @@
697
        io->buffer_id = SPA_ID_INVALID;
698
    }
699
 
700
+   /* Produce data */
701
+   process_buffering(this);
702
+
703
    /* Return if there are no buffers ready to be processed */
704
    if (spa_list_is_empty(&port->ready))
705
        return SPA_STATUS_OK;
706
@@ -1252,6 +1383,8 @@
707
    struct impl *this = (struct impl *) handle;
708
    if (this->transport)
709
        spa_hook_remove(&this->transport_listener);
710
+   spa_system_close(this->data_system, this->timerfd);
711
+   spa_bt_decode_buffer_clear(&this->port.buffer);
712
    return 0;
713
 }
714
 
715
@@ -1341,6 +1474,10 @@
716
    spa_list_init(&port->ready);
717
    spa_list_init(&port->free);
718
 
719
+   this->quantum_limit = 8192;
720
+   if (info && (str = spa_dict_lookup(info, "clock.quantum-limit")))
721
+       spa_atou32(str, &this->quantum_limit, 0);
722
+
723
    if (info && (str = spa_dict_lookup(info, SPA_KEY_API_BLUEZ5_TRANSPORT)))
724
        sscanf(str, "pointer:%p", &this->transport);
725
 
726
@@ -1351,6 +1488,9 @@
727
    spa_bt_transport_add_listener(this->transport,
728
            &this->transport_listener, &transport_events, this);
729
 
730
+   this->timerfd = spa_system_timerfd_create(this->data_system,
731
+           CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
732
+
733
    return 0;
734
 }
735
 
736
pipewire-0.3.53.tar.gz/spa/plugins/support/null-audio-sink.c -> pipewire-0.3.54.tar.gz/spa/plugins/support/null-audio-sink.c Changed
46
 
1
@@ -42,6 +42,7 @@
2
 #include <spa/node/keys.h>
3
 #include <spa/param/audio/format-utils.h>
4
 #include <spa/debug/types.h>
5
+#include <spa/debug/mem.h>
6
 #include <spa/param/audio/type-info.h>
7
 #include <spa/param/param.h>
8
 #include <spa/pod/filter.h>
9
@@ -57,6 +58,7 @@
10
    uint32_t n_pos;
11
    uint32_t posSPA_AUDIO_MAX_CHANNELS;
12
    char clock_name64;
13
+   unsigned int debug:1;
14
 };
15
 
16
 static void reset_props(struct props *props)
17
@@ -65,6 +67,7 @@
18
    props->rate = 0;
19
    props->n_pos = 0;
20
    strncpy(props->clock_name, DEFAULT_CLOCK_NAME, sizeof(props->clock_name));
21
+   props->debug = false;
22
 }
23
 
24
 #define DEFAULT_CHANNELS   2
25
@@ -744,6 +747,20 @@
26
        io->status = -EINVAL;
27
        return io->status;
28
    }
29
+   if (this->props.debug) {
30
+       struct buffer *b;
31
+       uint32_t i;
32
+
33
+       b = &port->buffersio->buffer_id;
34
+       for (i = 0; i < b->outbuf->n_datas; i++) {
35
+           uint32_t offs, size;
36
+           struct spa_data *d = b->outbuf->datas;
37
+
38
+           offs = SPA_MIN(d->chunk->offset, d->maxsize);
39
+           size = SPA_MIN(d->maxsize - offs, d->chunk->size);
40
+           spa_debug_mem(i, SPA_PTROFF(di.data, offs, void), SPA_MIN(16u, size));;
41
+       }
42
+   }
43
    io->status = SPA_STATUS_OK;
44
    return SPA_STATUS_HAVE_DATA;
45
 }
46
pipewire-0.3.53.tar.gz/src/modules/module-protocol-pulse/client.c -> pipewire-0.3.54.tar.gz/src/modules/module-protocol-pulse/client.c Changed
11
 
1
@@ -177,6 +177,9 @@
2
    free(client->default_sink);
3
    free(client->default_source);
4
 
5
+   free(client->temporary_default_sink);
6
+   free(client->temporary_default_source);
7
+
8
    pw_properties_free(client->props);
9
    pw_properties_free(client->routes);
10
 
11
pipewire-0.3.53.tar.gz/src/modules/module-protocol-pulse/client.h -> pipewire-0.3.54.tar.gz/src/modules/module-protocol-pulse/client.h Changed
10
 
1
@@ -75,6 +75,8 @@
2
    struct pw_manager_object *metadata_default;
3
    char *default_sink;
4
    char *default_source;
5
+   char *temporary_default_sink;       /**< pending value, for MOVE_* commands */
6
+   char *temporary_default_source;     /**< pending value, for MOVE_* commands */
7
    struct pw_manager_object *metadata_routes;
8
    struct pw_properties *routes;
9
 
10
pipewire-0.3.53.tar.gz/src/modules/module-protocol-pulse/pulse-server.c -> pipewire-0.3.54.tar.gz/src/modules/module-protocol-pulse/pulse-server.c Changed
180
 
1
@@ -678,8 +678,8 @@
2
        latency = attr->fragsize;
3
    }
4
    /* make sure can queue at least to fragsize without overruns */
5
-   if (attr->maxlength < attr->fragsize * 2)
6
-       attr->maxlength = attr->fragsize * 2;
7
+   if (attr->maxlength < attr->fragsize * 4)
8
+       attr->maxlength = attr->fragsize * 4;
9
 
10
    pw_log_info("%s maxlength:%u fragsize:%u minfrag:%u latency:%u",
11
            s->client->name, attr->maxlength, attr->fragsize, minfrag,
12
@@ -961,6 +961,8 @@
13
                free(client->default_sink);
14
                client->default_sink = value ? strdup(value) : NULL;
15
            }
16
+           free(client->temporary_default_sink);
17
+           client->temporary_default_sink = NULL;
18
        }
19
        if (key == NULL || spa_streq(key, "default.audio.source")) {
20
            if (value != NULL) {
21
@@ -974,6 +976,8 @@
22
                free(client->default_source);
23
                client->default_source = value ? strdup(value) : NULL;
24
            }
25
+           free(client->temporary_default_source);
26
+           client->temporary_default_source = NULL;
27
        }
28
        if (changed)
29
            send_default_change_subscribe_event(client, true, true);
30
@@ -1801,7 +1805,7 @@
31
    struct channel_map map;
32
    uint32_t source_index;
33
    const char *source_name;
34
-   struct buffer_attr attr;
35
+   struct buffer_attr attr = { 0 };
36
    bool corked = false,
37
        no_remap = false,
38
        no_remix = false,
39
@@ -3685,6 +3689,27 @@
40
    return 0;
41
 }
42
 
43
+static int fill_sink_info_proplist(struct message *m, const struct spa_dict *sink_props,
44
+       const struct pw_manager_object *card)
45
+{
46
+   struct pw_device_info *card_info = card ? card->info : NULL;
47
+   struct pw_properties *props = NULL;
48
+
49
+   if (card_info && card_info->props) {
50
+       props = pw_properties_new_dict(sink_props);
51
+       if (props == NULL)
52
+           return -ENOMEM;
53
+
54
+       pw_properties_add(props, card_info->props);
55
+       sink_props = &props->dict;
56
+   }
57
+   message_put(m, TAG_PROPLIST, sink_props, TAG_INVALID);
58
+
59
+   pw_properties_free(props);
60
+
61
+   return 0;
62
+}
63
+
64
 static int fill_sink_info(struct client *client, struct message *m,
65
        struct pw_manager_object *o)
66
 {
67
@@ -3777,8 +3802,10 @@
68
        TAG_INVALID);
69
 
70
    if (client->version >= 13) {
71
+       int res;
72
+       if ((res = fill_sink_info_proplist(m, info->props, card)) < 0)
73
+           return res;
74
        message_put(m,
75
-           TAG_PROPLIST, info->props,
76
            TAG_USEC, 0LL,          /* requested latency */
77
            TAG_INVALID);
78
    }
79
@@ -3867,22 +3894,27 @@
80
    return 0;
81
 }
82
 
83
-static int fill_source_info_proplist(struct message *m, struct pw_manager_object *o,
84
-       struct pw_node_info *info)
85
+static int fill_source_info_proplist(struct message *m, const struct spa_dict *source_props,
86
+       const struct pw_manager_object *card, const bool is_monitor)
87
 {
88
+   struct pw_device_info *card_info = card ? card->info : NULL;
89
    struct pw_properties *props = NULL;
90
-   struct spa_dict *props_dict = info->props;
91
 
92
-   if (pw_manager_object_is_monitor(o)) {
93
-       props = pw_properties_new_dict(info->props);
94
+   if ((card_info && card_info->props) || is_monitor) {
95
+       props = pw_properties_new_dict(source_props);
96
        if (props == NULL)
97
            return -ENOMEM;
98
 
99
-       pw_properties_set(props, PW_KEY_DEVICE_CLASS, "monitor");
100
-       props_dict = &props->dict;
101
+       if (card_info && card_info->props)
102
+           pw_properties_add(props, card_info->props);
103
+
104
+       if (is_monitor)
105
+           pw_properties_set(props, PW_KEY_DEVICE_CLASS, "monitor");
106
+
107
+       source_props = &props->dict;
108
    }
109
+   message_put(m, TAG_PROPLIST, source_props, TAG_INVALID);
110
 
111
-   message_put(m, TAG_PROPLIST, props_dict, TAG_INVALID);
112
    pw_properties_free(props);
113
 
114
    return 0;
115
@@ -3984,7 +4016,7 @@
116
 
117
    if (client->version >= 13) {
118
        int res;
119
-       if ((res = fill_source_info_proplist(m, o, info)) < 0)
120
+       if ((res = fill_source_info_proplist(m, info->props, card, is_monitor)) < 0)
121
            return res;
122
        message_put(m,
123
            TAG_USEC, 0LL,          /* requested latency */
124
@@ -4723,6 +4755,20 @@
125
    if (res < 0)
126
        return res;
127
 
128
+   /*
129
+    * The metadata is not necessarily updated within one server sync.
130
+    * Correct functioning of MOVE_* commands requires knowing the current
131
+    * default target, so we need to stash temporary values here in case
132
+    * the client emits them before metadata gets updated.
133
+    */
134
+   if (sink) {
135
+       free(client->temporary_default_sink);
136
+       client->temporary_default_sink = name ? strdup(name) : NULL;
137
+   } else {
138
+       free(client->temporary_default_source);
139
+       client->temporary_default_source = name ? strdup(name) : NULL;
140
+   }
141
+
142
    return operation_new(client, tag);
143
 }
144
 
145
@@ -4764,6 +4810,7 @@
146
    int target_id;
147
    int64_t target_serial;
148
    const char *name_device;
149
+   const char *name;
150
    struct pw_node_info *info;
151
    struct selector sel;
152
    int res;
153
@@ -4800,7 +4847,13 @@
154
    if ((dev = find_device(client, index_device, name_device, sink, NULL)) == NULL)
155
        return -ENOENT;
156
 
157
-   dev_default = find_device(client, SPA_ID_INVALID, NULL, sink, NULL);
158
+   /*
159
+    * The client metadata is not necessarily yet updated after SET_DEFAULT command,
160
+    * so use the temporary values if they are still set.
161
+    */
162
+   name = sink ? client->temporary_default_sink : client->temporary_default_source;
163
+   dev_default = find_device(client, SPA_ID_INVALID, name, sink, NULL);
164
+
165
    if (dev == dev_default) {
166
        /*
167
         * When moving streams to a node that is equal to the default,
168
@@ -4826,6 +4879,11 @@
169
            SPA_TYPE_INFO_BASE"Id", "%"PRIi64, target_serial)) < 0)
170
        return res;
171
 
172
+   name = spa_dict_lookup(info->props, PW_KEY_NODE_NAME);
173
+   pw_log_debug("%s %s done tag:%u index:%u name:%s target:%d target-serial:%"PRIi64, client->name,
174
+           commandscommand.name, tag, index, name ? name : "<null>",
175
+           target_id, target_serial);
176
+
177
    /* We will temporarily claim the stream was already moved */
178
    set_temporary_move_target(client, o, dev->index);
179
    send_object_event(client, o, SUBSCRIPTION_EVENT_CHANGE);
180
pipewire-0.3.53.tar.gz/src/tools/dsffile.c -> pipewire-0.3.54.tar.gz/src/tools/dsffile.c Changed
18
 
1
@@ -216,13 +216,15 @@
2
    uint8_t *d = data;
3
    int step = SPA_ABS(layout->interleave);
4
    bool rev = layout->lsb != f->info.lsb;
5
-   size_t total, block, offset, pos;
6
+   size_t total, block, offset, pos, scale;
7
 
8
    block = f->offset / f->info.blocksize;
9
    offset = block * f->info.blocksize * f->info.channels;
10
    pos = f->offset % f->info.blocksize;
11
+   scale = SPA_CLAMP(f->info.rate / (44100u * 64u), 1u, 4u);
12
 
13
    samples *= step;
14
+   samples *= scale;
15
 
16
    for (total = 0; total < samples && offset + pos < f->info.length; total++) {
17
        const uint8_t *s = f->p + offset + pos;
18
Refresh

No build results available

Refresh

No rpmlint results available

Request History
Bjørn Lie's avatar

zaitor created request almost 3 years ago

New upstream release


Bjørn Lie's avatar

zaitor accepted request almost 3 years ago

Xin