summaryrefslogtreecommitdiff
path: root/emulators/rpcs3/files/patch-cubeb-revert
blob: c941396a31eae446dcc60187d2bdcfb518f1bc0a (plain) (blame)
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
Revert https://github.com/mozilla/cubeb/commit/0846b39f1fdc
until https://github.com/mozilla/cubeb/issues/746

--- 3rdparty/cubeb/cubeb/src/cubeb_sndio.c.orig	2025-09-16 23:01:49 UTC
+++ 3rdparty/cubeb/cubeb/src/cubeb_sndio.c
@@ -68,7 +68,7 @@ struct cubeb_stream {
   struct sio_hdl * hdl;          /* link us to sndio */
   int mode;                      /* bitmap of SIO_{PLAY,REC} */
   int active;                    /* cubec_start() called */
-  int conv;                      /* need float->s24 conversion */
+  int conv;                      /* need float->s16 conversion */
   unsigned char * rbuf;          /* rec data consumed from here */
   unsigned char * pbuf;          /* play data is prepared here */
   unsigned int nfr;              /* number of frames in ibuf and obuf */
@@ -99,33 +99,33 @@ static void
 }
 
 static void
-float_to_s24(void * ptr, long nsamp, float volume)
+float_to_s16(void * ptr, long nsamp, float volume)
 {
-  int32_t * dst = ptr;
+  int16_t * dst = ptr;
   float * src = ptr;
-  float mult = volume * 8388608;
+  float mult = volume * 32768;
   int s;
 
   while (nsamp-- > 0) {
     s = lrintf(*(src++) * mult);
-    if (s < -8388608)
-      s = -8388608;
-    else if (s > 8388607)
-      s = 8388607;
+    if (s < -32768)
+      s = -32768;
+    else if (s > 32767)
+      s = 32767;
     *(dst++) = s;
   }
 }
 
 static void
-s24_to_float(void * ptr, long nsamp)
+s16_to_float(void * ptr, long nsamp)
 {
-  int32_t * src = ptr;
+  int16_t * src = ptr;
   float * dst = ptr;
 
   src += nsamp;
   dst += nsamp;
   while (nsamp-- > 0)
-    *(--dst) = (1. / 8388608) * *(--src);
+    *(--dst) = (1. / 32768) * *(--src);
 }
 
 static const char *
@@ -213,7 +213,7 @@ sndio_mainloop(void * arg)
       }
 
       if ((s->mode & SIO_REC) && s->conv)
-        s24_to_float(s->rbuf, s->nfr * s->rchan);
+        s16_to_float(s->rbuf, s->nfr * s->rchan);
 
       /* invoke call-back, it returns less that s->nfr if done */
       pthread_mutex_unlock(&s->mtx);
@@ -244,7 +244,7 @@ sndio_mainloop(void * arg)
 
       if (s->mode & SIO_PLAY) {
         if (s->conv)
-          float_to_s24(s->pbuf, nfr * s->pchan, s->volume);
+          float_to_s16(s->pbuf, nfr * s->pchan, s->volume);
         else
           s16_setvol(s->pbuf, nfr * s->pchan, s->volume);
       }
@@ -429,25 +429,21 @@ sndio_stream_init(cubeb * context, cubeb_stream ** str
   }
   WRAP(sio_initpar)(&wpar);
   wpar.sig = 1;
+  wpar.bits = 16;
   switch (format) {
   case CUBEB_SAMPLE_S16LE:
     wpar.le = 1;
-    wpar.bits = 16;
     break;
   case CUBEB_SAMPLE_S16BE:
     wpar.le = 0;
-    wpar.bits = 16;
     break;
   case CUBEB_SAMPLE_FLOAT32NE:
     wpar.le = SIO_LE_NATIVE;
-    wpar.bits = 24;
-    wpar.msb = 0;
     break;
   default:
     DPR("sndio_stream_init() unsupported format\n");
     goto err;
   }
-  wpar.bps = SIO_BPS(wpar.bits);
   wpar.rate = rate;
   if (s->mode & SIO_REC)
     wpar.rchan = input_stream_params->channels;
@@ -459,8 +455,6 @@ sndio_stream_init(cubeb * context, cubeb_stream ** str
     goto err;
   }
   if (rpar.bits != wpar.bits || rpar.le != wpar.le || rpar.sig != wpar.sig ||
-      rpar.bps != wpar.bps ||
-      (wpar.bits < 8 * wpar.bps && rpar.msb != wpar.msb) ||
       rpar.rate != wpar.rate ||
       ((s->mode & SIO_REC) && rpar.rchan != wpar.rchan) ||
       ((s->mode & SIO_PLAY) && rpar.pchan != wpar.pchan)) {