|
Line 0
Link Here
|
|
|
1 |
--- mozilla/media/libcubeb/src/cubeb_sndio.c.orig 2018-05-16 23:58:58.000000000 +0200 |
| 2 |
+++ mozilla/media/libcubeb/src/cubeb_sndio.c |
| 3 |
@@ -43,17 +43,33 @@ struct cubeb_stream { |
| 4 |
cubeb_data_callback data_cb; /* cb to preapare data */ |
| 5 |
cubeb_state_callback state_cb; /* cb to notify about state changes */ |
| 6 |
void *arg; /* user arg to {data,state}_cb */ |
| 7 |
+ float volume; /* current volume */ |
| 8 |
}; |
| 9 |
|
| 10 |
static void |
| 11 |
-float_to_s16(void *ptr, long nsamp) |
| 12 |
+s16_setvol(void *ptr, long nsamp, float volume) |
| 13 |
{ |
| 14 |
int16_t *dst = ptr; |
| 15 |
+ int32_t mult = volume * 32768; |
| 16 |
+ int32_t s; |
| 17 |
+ |
| 18 |
+ while (nsamp-- > 0) { |
| 19 |
+ s = *dst; |
| 20 |
+ s = (s * mult) >> 15; |
| 21 |
+ *(dst++) = s; |
| 22 |
+ } |
| 23 |
+} |
| 24 |
+ |
| 25 |
+static void |
| 26 |
+float_to_s16(void *ptr, long nsamp, float volume) |
| 27 |
+{ |
| 28 |
+ int16_t *dst = ptr; |
| 29 |
float *src = ptr; |
| 30 |
+ float mult = volume * 32768; |
| 31 |
int s; |
| 32 |
|
| 33 |
while (nsamp-- > 0) { |
| 34 |
- s = lrintf(*(src++) * 32768); |
| 35 |
+ s = lrintf(*(src++) * mult); |
| 36 |
if (s < -32768) |
| 37 |
s = -32768; |
| 38 |
else if (s > 32767) |
| 39 |
@@ -111,7 +127,9 @@ sndio_mainloop(void *arg) |
| 40 |
break; |
| 41 |
} |
| 42 |
if (s->conv) |
| 43 |
- float_to_s16(s->buf, nfr * s->pchan); |
| 44 |
+ float_to_s16(s->buf, nfr * s->pchan, s->volume); |
| 45 |
+ else |
| 46 |
+ s16_setvol(s->buf, nfr * s->pchan, s->volume); |
| 47 |
start = 0; |
| 48 |
end = nfr * s->bpf; |
| 49 |
} |
| 50 |
@@ -260,6 +278,7 @@ sndio_stream_init(cubeb * context, |
| 51 |
free(s); |
| 52 |
return CUBEB_ERROR; |
| 53 |
} |
| 54 |
+ s->volume = 1.; |
| 55 |
*stream = s; |
| 56 |
DPR("sndio_stream_init() end, ok\n"); |
| 57 |
(void)context; |
| 58 |
@@ -346,7 +365,11 @@ sndio_stream_set_volume(cubeb_stream *s, float volume) |
| 59 |
{ |
| 60 |
DPR("sndio_stream_set_volume(%f)\n", volume); |
| 61 |
pthread_mutex_lock(&s->mtx); |
| 62 |
- sio_setvol(s->hdl, SIO_MAXVOL * volume); |
| 63 |
+ if (volume < 0.) |
| 64 |
+ volume = 0.; |
| 65 |
+ else if (volume > 1.0) |
| 66 |
+ volume = 1.; |
| 67 |
+ s->volume = volume; |
| 68 |
pthread_mutex_unlock(&s->mtx); |
| 69 |
return CUBEB_OK; |
| 70 |
} |