blob: ae1e042759ec062f7c2cce2ea5c49a3d88b80036 (
plain)
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
|
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include "grab-ng.h"
#include "sound.h"
void
oss_levels(struct ng_audio_buf *buf, int *left, int *right)
{
int lmax,rmax,i,level;
signed char *s = (signed char*) buf->data;
unsigned char *u = (unsigned char*) buf->data;
lmax = 0;
rmax = 0;
switch (buf->fmt.fmtid) {
case AUDIO_U8_MONO:
i = 0;
while (i < buf->size) {
level = abs((int)u[i++] - 128);
if (lmax < level)
lmax = level, rmax = level;
}
break;
case AUDIO_U8_STEREO:
i = 0;
while (i < buf->size) {
level = abs((int)u[i++] - 128);
if (lmax < level)
lmax = level;
level = abs((int)u[i++] - 128);
if (rmax < level)
rmax = level;
}
break;
case AUDIO_S16_BE_MONO:
case AUDIO_S16_LE_MONO:
i = (AUDIO_S16_BE_MONO == buf->fmt.fmtid) ? 0 : 1;
while (i < buf->size) {
level = abs((int)s[i]);
i += 2;
if (lmax < level)
lmax = level, rmax = level;
}
break;
case AUDIO_S16_LE_STEREO:
case AUDIO_S16_BE_STEREO:
i = (AUDIO_S16_BE_STEREO == buf->fmt.fmtid) ? 0 : 1;
while (i < buf->size) {
level = abs((int)s[i]);
i += 2;
if (lmax < level)
lmax = level;
level = abs((int)s[i]);
i += 2;
if (rmax < level)
rmax = level;
}
break;
}
*left = lmax;
*right = rmax;
}
|