Line 0
Link Here
|
|
|
1 |
|
2 |
# HG changeset patch |
3 |
# User Alex Chronopoulos <achronop@gmail.com> |
4 |
# Date 1528999505 25200 |
5 |
# Node ID 0e40938905915ec04bbbccb4f093182a6785ac3a |
6 |
# Parent a75f33744de61543dc840cbb0324fedf997c3931 |
7 |
Bug 1467882 - Update cubeb from upstream to 0677b30. r=kinetik |
8 |
|
9 |
diff --git a/media/libcubeb/README_MOZILLA b/media/libcubeb/README_MOZILLA |
10 |
--- media/libcubeb/README_MOZILLA |
11 |
+++ media/libcubeb/README_MOZILLA |
12 |
@@ -1,8 +1,8 @@ |
13 |
The source from this directory was copied from the cubeb |
14 |
git repository using the update.sh script. The only changes |
15 |
made were those applied by update.sh and the addition of |
16 |
Makefile.in build files for the Mozilla build system. |
17 |
|
18 |
The cubeb git repository is: git://github.com/kinetiknz/cubeb.git |
19 |
|
20 |
-The git commit ID used was abf6ae235b0f15a2656f2d8692ac13708188165e (2018-06-01 13:02:45 +1200) |
21 |
+The git commit ID used was 0677b3027b78c629586b099b5155aa6ac7422674 (2018-06-12 08:48:55 -0700) |
22 |
diff --git a/media/libcubeb/src/cubeb_sndio.c b/media/libcubeb/src/cubeb_sndio.c |
23 |
--- media/libcubeb/src/cubeb_sndio.c |
24 |
+++ media/libcubeb/src/cubeb_sndio.c |
25 |
@@ -46,27 +46,43 @@ struct cubeb_stream { |
26 |
unsigned int pbpf; /* play bytes per frame */ |
27 |
unsigned int rchan; /* number of rec channels */ |
28 |
unsigned int pchan; /* number of play channels */ |
29 |
unsigned int nblks; /* number of blocks in the buffer */ |
30 |
uint64_t hwpos; /* frame number Joe hears right now */ |
31 |
uint64_t swpos; /* number of frames produced/consumed */ |
32 |
cubeb_data_callback data_cb; /* cb to preapare data */ |
33 |
cubeb_state_callback state_cb; /* cb to notify about state changes */ |
34 |
+ float volume; /* current volume */ |
35 |
}; |
36 |
|
37 |
static void |
38 |
-float_to_s16(void *ptr, long nsamp) |
39 |
+s16_setvol(void *ptr, long nsamp, float volume) |
40 |
+{ |
41 |
+ int16_t *dst = ptr; |
42 |
+ int32_t mult = volume * 32768; |
43 |
+ int32_t s; |
44 |
+ |
45 |
+ while (nsamp-- > 0) { |
46 |
+ s = *dst; |
47 |
+ s = (s * mult) >> 15; |
48 |
+ *(dst++) = s; |
49 |
+ } |
50 |
+} |
51 |
+ |
52 |
+static void |
53 |
+float_to_s16(void *ptr, long nsamp, float volume) |
54 |
{ |
55 |
int16_t *dst = ptr; |
56 |
float *src = ptr; |
57 |
+ float mult = volume * 32768; |
58 |
int s; |
59 |
|
60 |
while (nsamp-- > 0) { |
61 |
- s = lrintf(*(src++) * 32768); |
62 |
+ s = lrintf(*(src++) * mult); |
63 |
if (s < -32768) |
64 |
s = -32768; |
65 |
else if (s > 32767) |
66 |
s = 32767; |
67 |
*(dst++) = s; |
68 |
} |
69 |
} |
70 |
|
71 |
@@ -164,18 +180,22 @@ sndio_mainloop(void *arg) |
72 |
/* need to write (aka drain) the partial play block we got */ |
73 |
pend = nfr * s->pbpf; |
74 |
eof = 1; |
75 |
} |
76 |
|
77 |
if (prime > 0) |
78 |
prime--; |
79 |
|
80 |
- if ((s->mode & SIO_PLAY) && s->conv) |
81 |
- float_to_s16(s->pbuf, nfr * s->pchan); |
82 |
+ if (s->mode & SIO_PLAY) { |
83 |
+ if (s->conv) |
84 |
+ float_to_s16(s->pbuf, nfr * s->pchan, s->volume); |
85 |
+ else |
86 |
+ s16_setvol(s->pbuf, nfr * s->pchan, s->volume); |
87 |
+ } |
88 |
|
89 |
if (s->mode & SIO_REC) |
90 |
rstart = 0; |
91 |
if (s->mode & SIO_PLAY) |
92 |
pstart = 0; |
93 |
} |
94 |
|
95 |
events = 0; |
96 |
@@ -367,16 +387,17 @@ sndio_stream_init(cubeb * context, |
97 |
if (s->pbuf == NULL) |
98 |
goto err; |
99 |
} |
100 |
if (s->mode & SIO_REC) { |
101 |
s->rbuf = malloc(bps * rpar.rchan * rpar.round); |
102 |
if (s->rbuf == NULL) |
103 |
goto err; |
104 |
} |
105 |
+ s->volume = 1.; |
106 |
*stream = s; |
107 |
DPR("sndio_stream_init() end, ok\n"); |
108 |
(void)context; |
109 |
(void)stream_name; |
110 |
return CUBEB_OK; |
111 |
err: |
112 |
if (s->hdl) |
113 |
sio_close(s->hdl); |
114 |
@@ -471,17 +492,21 @@ sndio_stream_get_position(cubeb_stream * |
115 |
return CUBEB_OK; |
116 |
} |
117 |
|
118 |
static int |
119 |
sndio_stream_set_volume(cubeb_stream *s, float volume) |
120 |
{ |
121 |
DPR("sndio_stream_set_volume(%f)\n", volume); |
122 |
pthread_mutex_lock(&s->mtx); |
123 |
- sio_setvol(s->hdl, SIO_MAXVOL * volume); |
124 |
+ if (volume < 0.) |
125 |
+ volume = 0.; |
126 |
+ else if (volume > 1.0) |
127 |
+ volume = 1.; |
128 |
+ s->volume = volume; |
129 |
pthread_mutex_unlock(&s->mtx); |
130 |
return CUBEB_OK; |
131 |
} |
132 |
|
133 |
int |
134 |
sndio_stream_get_latency(cubeb_stream * stm, uint32_t * latency) |
135 |
{ |
136 |
// http://www.openbsd.org/cgi-bin/man.cgi?query=sio_open |
137 |
|