summaryrefslogtreecommitdiffstats
path: root/src/sample.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-06-15 15:18:33 +0000
committerLennart Poettering <lennart@poettering.net>2004-06-15 15:18:33 +0000
commit78f386ad45dc046d673fca5441dff188a7297059 (patch)
tree9ffa89fb46457318184e0531bb0e68d3817ceb4d /src/sample.c
parent98f41f1e70e66dcfc4c457ae47bffb07ed83947f (diff)
more work
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@17 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/sample.c')
-rw-r--r--src/sample.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/sample.c b/src/sample.c
index 2e46eac7..6a000228 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -33,24 +33,6 @@ struct memblock *silence(struct memblock* b, struct sample_spec *spec) {
return b;
}
-void add_clip(struct memchunk *target, struct memchunk *chunk, struct sample_spec *spec) {
- int16_t *p, *d;
- size_t i;
- assert(target && target->memblock && chunk && chunk->memblock && spec);
- assert(spec->format == SAMPLE_S16NE);
- assert((target->length & 1) == 0);
-
- d = target->memblock->data + target->index;
- p = chunk->memblock->data + chunk->index;
-
- for (i = 0; i < target->length && i < chunk->length; i++) {
- int32_t r = (int32_t) *d + (int32_t) *p;
- if (r < -0x8000) r = 0x8000;
- if (r > 0x7FFF) r = 0x7FFF;
- *d = (int16_t) r;
- }
-}
-
size_t sample_size(struct sample_spec *spec) {
assert(spec);
size_t b = 1;
@@ -78,3 +60,38 @@ size_t bytes_per_second(struct sample_spec *spec) {
return spec->rate*sample_size(spec);
}
+size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct sample_spec *spec) {
+ unsigned c, d;
+ assert(chunks && target && spec);
+ assert(spec->format == SAMPLE_S16NE);
+
+ for (d = 0;; d += sizeof(int16_t)) {
+ int32_t sum = 0;
+
+ if (d >= length)
+ return d;
+
+ for (c = 0; c < nchannels; c++) {
+ int32_t v;
+ uint8_t volume = channels[c].volume;
+
+ if (d >= channels[c].chunk.length)
+ return d;
+
+ if (volume == 0)
+ v = 0;
+ else {
+ v = *((int16_t*) (channels[c].chunk->memblock->data + channels[c].chunk->index + d));
+
+ if (volume != 0xFF)
+ v = v*volume/0xFF;
+ }
+
+ sum += v;
+ }
+
+ if (sum < -0x8000) sum = -0x8000;
+ if (sum > 0x7FFF) sum = 0x7FFF;
+ *(data++) = sum;
+ }
+}