File: up_portaudio_patches

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (252 lines) | stat: -rw-r--r-- 8,995 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
--- /dev/null
+++ b/PsychSourceGL/Cohorts/PortAudio/patches/common_timeinfo_currenttime
@@ -0,0 +1,15 @@
+From: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
+Subject: disable resetting of timeInfo->currentTime
+Origin: PTB-3
+
+--- a/portaudio/src/common/pa_process.c
++++ b/portaudio/src/common/pa_process.c
+@@ -683,7 +683,7 @@ void PaUtil_BeginBufferProcessing( PaUti
+         
+     bp->timeInfo->inputBufferAdcTime -= bp->framesInTempInputBuffer * bp->samplePeriod;
+     
+-    bp->timeInfo->currentTime = 0; /** FIXME: @todo time info currentTime not implemented */
++    // MARIO MK CHANGED PTB: bp->timeInfo->currentTime = 0; /** FIXME: @todo time info currentTime not implemented */
+ 
+     /* the first streamCallback will be called to generate samples which will be
+         outputted after the frames currently in the output buffer have been
--- /dev/null
+++ b/PsychSourceGL/Cohorts/PortAudio/patches/common_unique_DebugPrint
@@ -0,0 +1,36 @@
+From: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
+Subject: avoid PaUtil_DebugPrint defined in multiple locations -- reuse pa_debugprint.o
+Origin: PTB-3
+
+
+--- a/portaudio/Makefile.in
++++ b/portaudio/Makefile.in
+@@ -49,6 +49,7 @@ COMMON_OBJS = \
+ 	src/common/pa_cpuload.o \
+ 	src/common/pa_dither.o \
+ 	src/common/pa_front.o \
++	src/common/pa_debugprint.o \
+ 	src/common/pa_process.o \
+ 	src/common/pa_skeleton.o \
+ 	src/common/pa_stream.o \
+--- a/portaudio/src/common/pa_front.c
++++ b/portaudio/src/common/pa_front.c
+@@ -158,7 +158,8 @@ void PaUtil_SetLastHostErrorInfo( PaHost
+     strncpy( lastHostErrorText_, errorText, PA_LAST_HOST_ERROR_TEXT_LENGTH_ );
+ }
+ 
+-
++/*
++MK CHANGED PTB - Already defined in pa_debugprint
+ void PaUtil_DebugPrint( const char *format, ... )
+ {
+     va_list ap;
+@@ -169,7 +170,7 @@ void PaUtil_DebugPrint( const char *form
+ 
+     fflush( stderr );
+ }
+-
++*/
+ 
+ static PaUtilHostApiRepresentation **hostApis_ = 0;
+ static int hostApisCount_ = 0;
--- /dev/null
+++ b/PsychSourceGL/Cohorts/PortAudio/patches/linux_sched_rt
@@ -0,0 +1,58 @@
+From: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
+Subject: enforce (when possible) SCHED_RR on Linux systems
+Origin: PTB-3
+
+
+
+--- a/portaudio/src/os/unix/pa_unix_util.c
++++ b/portaudio/src/os/unix/pa_unix_util.c
+@@ -224,9 +224,18 @@ PaError PaUnixThread_Initialize( PaUnixT
+ }
+ #endif
+ 
++// MK: Enable Psychtoolbox specific Realtime scheduling setup code for RT scheduling the audio callback thread.
++#define MK_PSYCH_RTSCHED 1
++
+ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void* threadArg, PaTime waitForChild )
+ {
+-    PaError result = paNoError;
++#ifdef MK_PSYCH_RTSCHED
++	// MK: New code, not in original. Unconditionally try to boost callback threads priority
++	// to RT_FIFO realtime scheduling with given realtime priority. See below for rest.
++    struct sched_param spm = { 0 };
++	int policy;
++#endif 
++	PaError result = paNoError;
+     pthread_attr_t attr;
+     int started = 0;
+ 
+@@ -260,6 +269,29 @@ PaError PaUnixThread_New( PaUnixThread*
+     PA_UNLESS( !pthread_create( &self->thread, &attr, threadFunc, threadArg ), paInternalError );
+     started = 1;
+ 
++#ifdef MK_PSYCH_RTSCHED
++	// MK: New code, not in original. Unconditionally try to boost callback threads priority
++	// to RT_FIFO realtime scheduling with given realtime priority.
++	
++	// Query parent threads policy and priority:
++	pthread_getschedparam(pthread_self(), &policy, &spm);
++	
++	// If not RT policy, assign a base priority of minimum SCHED_FIFO. Otherwise use RT priority of parent as baseline:
++	if ((policy != SCHED_FIFO ) && (policy != SCHED_RR)) spm.sched_priority = sched_get_priority_min( SCHED_FIFO );
++	
++	// Set audio callback threads RT priority to parents baseline + 4, so it gets quite a boost wrt. its parent.
++	// Clamp to allowable maximum though:
++    spm.sched_priority = PA_MIN( spm.sched_priority + 4 , sched_get_priority_max( SCHED_FIFO ) );
++	
++	// Try to switch callback thread to SCHED_FIFO Realtime scheduling with proper realtime priority,
++	// but don't be pissed if it doesn't work. No all too big deal:
++    if( pthread_setschedparam(self->thread, SCHED_FIFO, &spm) != 0 )
++    {
++        PA_DEBUG(( "WARNING: Failed bumping audio callback thread to realtime priority!\n" ));
++    }
++
++#endif
++
+ #if 0
+     if( th->rtSched )
+     {
--- /dev/null
+++ b/PsychSourceGL/Cohorts/PortAudio/patches/series
@@ -0,0 +1,4 @@
+common_unique_DebugPrint
+common_timeinfo_currenttime
+linux_sched_rt
+dither_amd64_fixes
--- /dev/null
+++ b/PsychSourceGL/Cohorts/PortAudio/patches/dither_amd64_fixes
@@ -0,0 +1,124 @@
+--- a/portaudio/src/common/pa_dither.c
++++ b/portaudio/src/common/pa_dither.c
+@@ -1,5 +1,5 @@
+ /*
+- * $Id: pa_dither.c 1097 2006-08-26 08:27:53Z rossb $
++ * $Id$
+  * Portable Audio I/O Library triangular dither generator
+  *
+  * Based on the Open Source API proposed by Ross Bencina
+@@ -42,9 +42,14 @@
+  @brief Functions for generating dither noise
+ */
+ 
+-
+-#include "pa_dither.h"
+ #include "pa_types.h"
++#include "pa_dither.h"
++
++
++/* Note that the linear congruential algorithm requires 32 bit integers
++ * because it uses arithmetic overflow. So use PaUint32 instead of
++ * unsigned long so it will work on 64 bit systems.
++ */
+ 
+ #define PA_DITHER_BITS_   (15)
+ 
+@@ -57,9 +62,9 @@ void PaUtil_InitializeTriangularDitherSt
+ }
+ 
+ 
+-signed long PaUtil_Generate16BitTriangularDither( PaUtilTriangularDitherGenerator *state )
++PaInt32 PaUtil_Generate16BitTriangularDither( PaUtilTriangularDitherGenerator *state )
+ {
+-    signed long current, highPass;
++    PaInt32 current, highPass;
+ 
+     /* Generate two random numbers. */
+     state->randSeed1 = (state->randSeed1 * 196314165) + 907633515;
+@@ -69,9 +74,10 @@ signed long PaUtil_Generate16BitTriangul
+      * Shift before adding to prevent overflow which would skew the distribution.
+      * Also shift an extra bit for the high pass filter. 
+      */
+-#define DITHER_SHIFT_  ((SIZEOF_LONG*8 - PA_DITHER_BITS_) + 1)
+-    current = (((signed long)state->randSeed1)>>DITHER_SHIFT_) +
+-              (((signed long)state->randSeed2)>>DITHER_SHIFT_);
++#define DITHER_SHIFT_  ((sizeof(PaInt32)*8 - PA_DITHER_BITS_) + 1)
++	
++    current = (((PaInt32)state->randSeed1)>>DITHER_SHIFT_) +
++              (((PaInt32)state->randSeed2)>>DITHER_SHIFT_);
+ 
+     /* High pass filter to reduce audibility. */
+     highPass = current - state->previous;
+@@ -86,7 +92,7 @@ static const float const_float_dither_sc
+ 
+ float PaUtil_GenerateFloatTriangularDither( PaUtilTriangularDitherGenerator *state )
+ {
+-    signed long current, highPass;
++    PaInt32 current, highPass;
+ 
+     /* Generate two random numbers. */
+     state->randSeed1 = (state->randSeed1 * 196314165) + 907633515;
+@@ -96,9 +102,8 @@ float PaUtil_GenerateFloatTriangularDith
+      * Shift before adding to prevent overflow which would skew the distribution.
+      * Also shift an extra bit for the high pass filter. 
+      */
+-#define DITHER_SHIFT_  ((SIZEOF_LONG*8 - PA_DITHER_BITS_) + 1)
+-    current = (((signed long)state->randSeed1)>>DITHER_SHIFT_) +
+-              (((signed long)state->randSeed2)>>DITHER_SHIFT_);
++    current = (((PaInt32)state->randSeed1)>>DITHER_SHIFT_) +
++              (((PaInt32)state->randSeed2)>>DITHER_SHIFT_);
+ 
+     /* High pass filter to reduce audibility. */
+     highPass = current - state->previous;
+--- a/portaudio/src/common/pa_dither.h
++++ b/portaudio/src/common/pa_dither.h
+@@ -1,7 +1,7 @@
+ #ifndef PA_DITHER_H
+ #define PA_DITHER_H
+ /*
+- * $Id: pa_dither.h 1097 2006-08-26 08:27:53Z rossb $
++ * $Id$
+  * Portable Audio I/O Library triangular dither generator
+  *
+  * Based on the Open Source API proposed by Ross Bencina
+@@ -44,18 +44,24 @@
+  @brief Functions for generating dither noise
+ */
+ 
++#include "pa_types.h"
++
+ 
+ #ifdef __cplusplus
+ extern "C"
+ {
+ #endif /* __cplusplus */
+ 
++/* Note that the linear congruential algorithm requires 32 bit integers
++ * because it uses arithmetic overflow. So use PaUint32 instead of
++ * unsigned long so it will work on 64 bit systems.
++ */
+ 
+ /** @brief State needed to generate a dither signal */
+ typedef struct PaUtilTriangularDitherGenerator{
+-    unsigned long previous;
+-    unsigned long randSeed1;
+-    unsigned long randSeed2;
++    PaUint32 previous;
++    PaUint32 randSeed1;
++    PaUint32 randSeed2;
+ } PaUtilTriangularDitherGenerator;
+ 
+ 
+@@ -73,9 +79,9 @@ void PaUtil_InitializeTriangularDitherSt
+     signed short out = (signed short)(((in>>1) + dither) >> 15);
+ </pre>
+  @return
+- A signed long with a range of +32767 to -32768
++ A signed 32-bit integer with a range of +32767 to -32768
+ */
+-signed long PaUtil_Generate16BitTriangularDither( PaUtilTriangularDitherGenerator *ditherState );
++PaInt32 PaUtil_Generate16BitTriangularDither( PaUtilTriangularDitherGenerator *ditherState );
+ 
+ 
+ /**