diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2010-04-01 11:24:38 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2010-04-01 11:24:38 +0200 |
commit | a4a3e6b21da7d11e66364ab9ab67795a3f78020a (patch) | |
tree | 4ab98e8339361b8a4c89bedbe8888055292746b6 /common/sound.c | |
parent | f53a049ec82b6e1d0877a93387ed4d15797749a2 (diff) |
v3.74
Diffstat (limited to 'common/sound.c')
-rw-r--r-- | common/sound.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/common/sound.c b/common/sound.c new file mode 100644 index 0000000..490d3f2 --- /dev/null +++ b/common/sound.c @@ -0,0 +1,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 = buf->data; + unsigned char *u = 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; +} |