mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	volume work
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@42 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									e31bac0257
								
							
						
					
					
						commit
						d571be6f51
					
				
					 12 changed files with 203 additions and 35 deletions
				
			
		
							
								
								
									
										97
									
								
								src/cli.c
									
										
									
									
									
								
							
							
						
						
									
										97
									
								
								src/cli.c
									
										
									
									
									
								
							| 
						 | 
					@ -13,6 +13,7 @@
 | 
				
			||||||
#include "sourceoutput.h"
 | 
					#include "sourceoutput.h"
 | 
				
			||||||
#include "tokenizer.h"
 | 
					#include "tokenizer.h"
 | 
				
			||||||
#include "strbuf.h"
 | 
					#include "strbuf.h"
 | 
				
			||||||
 | 
					#include "namereg.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cli {
 | 
					struct cli {
 | 
				
			||||||
    struct core *core;
 | 
					    struct core *core;
 | 
				
			||||||
| 
						 | 
					@ -45,20 +46,24 @@ static void cli_command_stat(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
static void cli_command_info(struct cli *c, struct tokenizer *t);
 | 
					static void cli_command_info(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
static void cli_command_load(struct cli *c, struct tokenizer *t);
 | 
					static void cli_command_load(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
static void cli_command_unload(struct cli *c, struct tokenizer *t);
 | 
					static void cli_command_unload(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
 | 
					static void cli_command_sink_volume(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
 | 
					static void cli_command_sink_input_volume(struct cli *c, struct tokenizer *t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct command commands[] = {
 | 
					static const struct command commands[] = {
 | 
				
			||||||
    { "exit",                    cli_command_exit,           "Terminate the daemon",         1 },
 | 
					    { "exit",                    cli_command_exit,              "Terminate the daemon",         1 },
 | 
				
			||||||
    { "help",                    cli_command_help,           "Show this help",               1 },
 | 
					    { "help",                    cli_command_help,              "Show this help",               1 },
 | 
				
			||||||
    { "modules",                 cli_command_modules,        "List loaded modules",          1 },
 | 
					    { "modules",                 cli_command_modules,           "List loaded modules",          1 },
 | 
				
			||||||
    { "sinks",                   cli_command_sinks,          "List loaded sinks",            1 },
 | 
					    { "sinks",                   cli_command_sinks,             "List loaded sinks",            1 },
 | 
				
			||||||
    { "sources",                 cli_command_sources,        "List loaded sources",          1 },
 | 
					    { "sources",                 cli_command_sources,           "List loaded sources",          1 },
 | 
				
			||||||
    { "clients",                 cli_command_clients,        "List loaded clients",          1 },
 | 
					    { "clients",                 cli_command_clients,           "List loaded clients",          1 },
 | 
				
			||||||
    { "sink_inputs",             cli_command_sink_inputs,    "List sink inputs",             1 },
 | 
					    { "sink_inputs",             cli_command_sink_inputs,       "List sink inputs",             1 },
 | 
				
			||||||
    { "source_outputs",          cli_command_source_outputs, "List source outputs",          1 },
 | 
					    { "source_outputs",          cli_command_source_outputs,    "List source outputs",          1 },
 | 
				
			||||||
    { "stat",                    cli_command_stat,           "Show memory block statistics", 1 },
 | 
					    { "stat",                    cli_command_stat,              "Show memory block statistics", 1 },
 | 
				
			||||||
    { "info",                    cli_command_info,           "Show comprehensive status",    1 },
 | 
					    { "info",                    cli_command_info,              "Show comprehensive status",    1 },
 | 
				
			||||||
    { "load",                    cli_command_load,           "Load a module (given by name and arguments)", 3 },
 | 
					    { "load",                    cli_command_load,              "Load a module (args: name, arguments)",                     3},
 | 
				
			||||||
    { "unload",                  cli_command_unload,         "Unload a module (specified by index)",        2 },
 | 
					    { "unload",                  cli_command_unload,            "Unload a module (args: index)",                             2},
 | 
				
			||||||
 | 
					    { "sink_volume",             cli_command_sink_volume,       "Set the volume of a sink (args: sink, volume)",             3},
 | 
				
			||||||
 | 
					    { "sink_input_volume",       cli_command_sink_input_volume, "Set the volume of a sink input (args: sink input, volume)", 3},
 | 
				
			||||||
    { NULL, NULL, NULL, 0 }
 | 
					    { NULL, NULL, NULL, 0 }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -277,3 +282,71 @@ static void cli_command_unload(struct cli *c, struct tokenizer *t) {
 | 
				
			||||||
    module_unload_request(c->core, m);
 | 
					    module_unload_request(c->core, m);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void cli_command_sink_volume(struct cli *c, struct tokenizer *t) {
 | 
				
			||||||
 | 
					    const char *n, *v;
 | 
				
			||||||
 | 
					    char *x = NULL;
 | 
				
			||||||
 | 
					    struct sink *sink;
 | 
				
			||||||
 | 
					    long volume;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(n = tokenizer_get(t, 1))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "You need to specify a sink either by its name or its index.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(v = tokenizer_get(t, 2))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    volume = strtol(v, &x, 0);
 | 
				
			||||||
 | 
					    if (!x || *x != 0 || volume < 0) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "Failed to parse volume.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(sink = namereg_get(c->core, n, NAMEREG_SINK))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "No sink found by this name or index.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sink->volume = (uint32_t) volume;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void cli_command_sink_input_volume(struct cli *c, struct tokenizer *t) {
 | 
				
			||||||
 | 
					    const char *n, *v;
 | 
				
			||||||
 | 
					    char *x = NULL;
 | 
				
			||||||
 | 
					    struct sink_input *si;
 | 
				
			||||||
 | 
					    long index, volume;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(n = tokenizer_get(t, 1))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "You need to specify a sink input by its index.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    index = strtol(n, &x, 0);
 | 
				
			||||||
 | 
					    if (!x || *x != 0 || index < 0) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "Failed to parse index.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(v = tokenizer_get(t, 2))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    x = NULL;
 | 
				
			||||||
 | 
					    volume = strtol(v, &x, 0);
 | 
				
			||||||
 | 
					    if (!x || *x != 0 || volume < 0) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "Failed to parse volume.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(si = idxset_get_by_index(c->core->sink_inputs, (uint32_t) index))) {
 | 
				
			||||||
 | 
					        ioline_puts(c->line, "No sink input found with this index.\n");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    si->volume = (uint32_t) volume;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
    c = core_new(pa_mainloop_get_api(mainloop));
 | 
					    c = core_new(pa_mainloop_get_api(mainloop));
 | 
				
			||||||
    assert(c);
 | 
					    assert(c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    module_load(c, "module-oss-mmap", "/dev/dsp1");
 | 
					    module_load(c, "module-oss", "/dev/dsp1");
 | 
				
			||||||
/*    module_load(c, "module-pipe-sink", NULL);
 | 
					/*    module_load(c, "module-pipe-sink", NULL);
 | 
				
			||||||
    module_load(c, "module-simple-protocol-tcp", NULL);
 | 
					    module_load(c, "module-simple-protocol-tcp", NULL);
 | 
				
			||||||
    module_load(c, "module-simple-protocol-unix", NULL);
 | 
					    module_load(c, "module-simple-protocol-unix", NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,3 +78,17 @@ void memblock_unref_fixed(struct memblock *b) {
 | 
				
			||||||
    b->type = MEMBLOCK_DYNAMIC;
 | 
					    b->type = MEMBLOCK_DYNAMIC;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void memchunk_make_writable(struct memchunk *c) {
 | 
				
			||||||
 | 
					    struct memblock *n;
 | 
				
			||||||
 | 
					    assert(c && c->memblock && c->memblock->ref >= 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (c->memblock->ref == 1)
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    n = memblock_new(c->length);
 | 
				
			||||||
 | 
					    assert(n);
 | 
				
			||||||
 | 
					    memcpy(n->data, c->memblock->data+c->index, c->length);
 | 
				
			||||||
 | 
					    memblock_unref(c->memblock);
 | 
				
			||||||
 | 
					    c->memblock = n;
 | 
				
			||||||
 | 
					    c->index = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,8 @@ void memblock_unref_fixed(struct memblock*b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define memblock_assert_exclusive(b) assert((b)->ref == 1)
 | 
					#define memblock_assert_exclusive(b) assert((b)->ref == 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void memchunk_make_writable(struct memchunk *c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern unsigned memblock_count, memblock_total;
 | 
					extern unsigned memblock_count, memblock_total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
| 
						 | 
					@ -87,11 +88,24 @@ void namereg_unregister(struct core *c, const char *name) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void* namereg_get(struct core *c, const char *name, enum namereg_type type) {
 | 
					void* namereg_get(struct core *c, const char *name, enum namereg_type type) {
 | 
				
			||||||
    struct namereg_entry *e;
 | 
					    struct namereg_entry *e;
 | 
				
			||||||
 | 
					    uint32_t index;
 | 
				
			||||||
 | 
					    char *x = NULL;
 | 
				
			||||||
 | 
					    void *d = NULL;
 | 
				
			||||||
    assert(c && name);
 | 
					    assert(c && name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(e = hashset_get(c->namereg, name)))
 | 
					    if ((e = hashset_get(c->namereg, name)))
 | 
				
			||||||
        if (e->type == e->type)
 | 
					        if (e->type == e->type)
 | 
				
			||||||
            return e->data;
 | 
					            return e->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return NULL;
 | 
					    index = (uint32_t) strtol(name, &x, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!x || *x != 0)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (type == NAMEREG_SINK)
 | 
				
			||||||
 | 
					        d = idxset_get_by_index(c->sinks, index);
 | 
				
			||||||
 | 
					    else if (type == NAMEREG_SOURCE)
 | 
				
			||||||
 | 
					        d = idxset_get_by_index(c->sources, index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return d;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +47,7 @@ void silence_memory(void *p, size_t length, struct pa_sample_spec *spec) {
 | 
				
			||||||
    memset(p, c, length);
 | 
					    memset(p, c, length);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint8_t volume) {
 | 
					size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint32_t volume) {
 | 
				
			||||||
    unsigned c, d;
 | 
					    unsigned c, d;
 | 
				
			||||||
    assert(channels && data && length && spec);
 | 
					    assert(channels && data && length && spec);
 | 
				
			||||||
    assert(spec->format == PA_SAMPLE_S16NE);
 | 
					    assert(spec->format == PA_SAMPLE_S16NE);
 | 
				
			||||||
| 
						 | 
					@ -59,27 +60,27 @@ size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, si
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        for (c = 0; c < nchannels; c++) {
 | 
					        for (c = 0; c < nchannels; c++) {
 | 
				
			||||||
            int32_t v;
 | 
					            int32_t v;
 | 
				
			||||||
            uint8_t volume = channels[c].volume;
 | 
					            uint32_t volume = channels[c].volume;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            if (d >= channels[c].chunk.length)
 | 
					            if (d >= channels[c].chunk.length)
 | 
				
			||||||
                return d;
 | 
					                return d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (volume == 0)
 | 
					            if (volume == VOLUME_MUTE)
 | 
				
			||||||
                v = 0;
 | 
					                v = 0;
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
                v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d));
 | 
					                v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (volume != 0xFF)
 | 
					                if (volume != VOLUME_NORM)
 | 
				
			||||||
                    v = v*volume/0xFF;
 | 
					                    v = (int32_t) ((float)v*volume/VOLUME_NORM);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sum += v;
 | 
					            sum += v;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (volume == 0)
 | 
					        if (volume == VOLUME_MUTE)
 | 
				
			||||||
            sum = 0;
 | 
					            sum = 0;
 | 
				
			||||||
        else if (volume != 0xFF)
 | 
					        else if (volume != VOLUME_NORM)
 | 
				
			||||||
            sum = sum*volume/0xFF;
 | 
					            sum = (int32_t) ((float) sum*volume/VOLUME_NORM);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (sum < -0x8000) sum = -0x8000;
 | 
					        if (sum < -0x8000) sum = -0x8000;
 | 
				
			||||||
        if (sum > 0x7FFF) sum = 0x7FFF;
 | 
					        if (sum > 0x7FFF) sum = 0x7FFF;
 | 
				
			||||||
| 
						 | 
					@ -88,3 +89,40 @@ size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, si
 | 
				
			||||||
        data += sizeof(int16_t);
 | 
					        data += sizeof(int16_t);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t volume) {
 | 
				
			||||||
 | 
					    int16_t *d;
 | 
				
			||||||
 | 
					    size_t n;
 | 
				
			||||||
 | 
					    assert(c && spec && (c->length % pa_sample_size(spec) == 0));
 | 
				
			||||||
 | 
					    assert(spec->format == PA_SAMPLE_S16NE);
 | 
				
			||||||
 | 
					    memblock_assert_exclusive(c->memblock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (volume == VOLUME_NORM)
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (volume == VOLUME_MUTE) {
 | 
				
			||||||
 | 
					        silence_memchunk(c, spec);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (d = (c->memblock->data+c->index), n = c->length/sizeof(int16_t); n > 0; d++, n--) {
 | 
				
			||||||
 | 
					        int32_t t = (int32_t)(*d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        t *= volume;
 | 
				
			||||||
 | 
					        t /= VOLUME_NORM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (t < -0x8000) t = -0x8000;
 | 
				
			||||||
 | 
					        if (t > 0x7FFF) t = 0x7FFF;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        *d = (int16_t) t;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t volume_multiply(uint32_t a, uint32_t b) {
 | 
				
			||||||
 | 
					    uint64_t p = a;
 | 
				
			||||||
 | 
					    p *= b;
 | 
				
			||||||
 | 
					    p /= VOLUME_NORM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (uint32_t) p;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,16 +8,23 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct pa_sample_spec default_sample_spec;
 | 
					extern struct pa_sample_spec default_sample_spec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define VOLUME_NORM (0x100)
 | 
				
			||||||
 | 
					#define VOLUME_MUTE (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct memblock *silence_memblock(struct memblock* b, struct pa_sample_spec *spec);
 | 
					struct memblock *silence_memblock(struct memblock* b, struct pa_sample_spec *spec);
 | 
				
			||||||
void silence_memchunk(struct memchunk *c, struct pa_sample_spec *spec);
 | 
					void silence_memchunk(struct memchunk *c, struct pa_sample_spec *spec);
 | 
				
			||||||
void silence_memory(void *p, size_t length, struct pa_sample_spec *spec);
 | 
					void silence_memory(void *p, size_t length, struct pa_sample_spec *spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mix_info {
 | 
					struct mix_info {
 | 
				
			||||||
    struct memchunk chunk;
 | 
					    struct memchunk chunk;
 | 
				
			||||||
    uint8_t volume;
 | 
					    uint32_t volume;
 | 
				
			||||||
    void *userdata;
 | 
					    void *userdata;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint8_t volume);
 | 
					size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint32_t volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t volume_multiply(uint32_t a, uint32_t b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								src/sink.c
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								src/sink.c
									
										
									
									
									
								
							| 
						 | 
					@ -39,7 +39,7 @@ struct sink* sink_new(struct core *core, const char *name, int fail, const struc
 | 
				
			||||||
    assert(s->monitor_source);
 | 
					    assert(s->monitor_source);
 | 
				
			||||||
    free(n);
 | 
					    free(n);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    s->volume = 0xFF;
 | 
					    s->volume = VOLUME_NORM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->notify = NULL;
 | 
					    s->notify = NULL;
 | 
				
			||||||
    s->get_latency = NULL;
 | 
					    s->get_latency = NULL;
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,7 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (n == 1) {
 | 
					    if (n == 1) {
 | 
				
			||||||
 | 
					        uint32_t volume = VOLUME_NORM;
 | 
				
			||||||
        struct sink_info *i = info[0].userdata;
 | 
					        struct sink_info *i = info[0].userdata;
 | 
				
			||||||
        assert(i);
 | 
					        assert(i);
 | 
				
			||||||
        *result = info[0].chunk;
 | 
					        *result = info[0].chunk;
 | 
				
			||||||
| 
						 | 
					@ -141,6 +142,14 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
 | 
				
			||||||
            result->length = length;
 | 
					            result->length = length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        l = result->length;
 | 
					        l = result->length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM)
 | 
				
			||||||
 | 
					            volume = volume_multiply(s->volume, info[0].volume);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if (volume != VOLUME_NORM) {
 | 
				
			||||||
 | 
					            memchunk_make_writable(result);
 | 
				
			||||||
 | 
					            volume_memchunk(result, &s->sample_spec, volume);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        result->memblock = memblock_new(length);
 | 
					        result->memblock = memblock_new(length);
 | 
				
			||||||
        assert(result->memblock);
 | 
					        assert(result->memblock);
 | 
				
			||||||
| 
						 | 
					@ -164,6 +173,7 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
 | 
				
			||||||
    unsigned n;
 | 
					    unsigned n;
 | 
				
			||||||
    size_t l;
 | 
					    size_t l;
 | 
				
			||||||
    assert(s && target && target->length && target->memblock && target->memblock->data);
 | 
					    assert(s && target && target->length && target->memblock && target->memblock->data);
 | 
				
			||||||
 | 
					    memblock_assert_exclusive(target->memblock);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    n = fill_mix_info(s, info, MAX_MIX_CHANNELS);
 | 
					    n = fill_mix_info(s, info, MAX_MIX_CHANNELS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -171,6 +181,7 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (n == 1) {
 | 
					    if (n == 1) {
 | 
				
			||||||
 | 
					        uint32_t volume = VOLUME_NORM;
 | 
				
			||||||
        struct sink_info *i = info[0].userdata;
 | 
					        struct sink_info *i = info[0].userdata;
 | 
				
			||||||
        assert(i);
 | 
					        assert(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,6 +191,12 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        memcpy(target->memblock->data+target->index, info[0].chunk.memblock->data + info[0].chunk.index, l);
 | 
					        memcpy(target->memblock->data+target->index, info[0].chunk.memblock->data + info[0].chunk.index, l);
 | 
				
			||||||
        target->length = l;
 | 
					        target->length = l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM)
 | 
				
			||||||
 | 
					            volume = volume_multiply(s->volume, info[0].volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (volume != VOLUME_NORM)
 | 
				
			||||||
 | 
					            volume_memchunk(target, &s->sample_spec, volume);
 | 
				
			||||||
    } else
 | 
					    } else
 | 
				
			||||||
        target->length = l = mix_chunks(info, n, target->memblock->data+target->index, target->length, &s->sample_spec, s->volume);
 | 
					        target->length = l = mix_chunks(info, n, target->memblock->data+target->index, target->length, &s->sample_spec, s->volume);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					@ -257,8 +274,9 @@ char *sink_list_to_string(struct core *c) {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    for (sink = idxset_first(c->sinks, &index); sink; sink = idxset_next(c->sinks, &index)) {
 | 
					    for (sink = idxset_first(c->sinks, &index); sink; sink = idxset_next(c->sinks, &index)) {
 | 
				
			||||||
        assert(sink->monitor_source);
 | 
					        assert(sink->monitor_source);
 | 
				
			||||||
        strbuf_printf(s, "  %c index: %u, name: <%s>, volume: <0x%02x>, latency: <%u usec>, monitor_source: <%u>\n", sink == default_sink ? '*' : ' ', sink->index, sink->name, (unsigned) sink->volume, sink_get_latency(sink), sink->monitor_source->index);
 | 
					        strbuf_printf(s, "  %c index: %u, name: <%s>, volume: <0x%04x>, latency: <%u usec>, monitor_source: <%u>\n", sink == default_sink ? '*' : ' ', sink->index, sink->name, (unsigned) sink->volume, sink_get_latency(sink), sink->monitor_source->index);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return strbuf_tostring_free(s);
 | 
					    return strbuf_tostring_free(s);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ struct sink {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct source *monitor_source;
 | 
					    struct source *monitor_source;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t volume;
 | 
					    uint32_t volume;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void (*notify)(struct sink*sink);
 | 
					    void (*notify)(struct sink*sink);
 | 
				
			||||||
    uint32_t (*get_latency)(struct sink *s);
 | 
					    uint32_t (*get_latency)(struct sink *s);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "sinkinput.h"
 | 
					#include "sinkinput.h"
 | 
				
			||||||
#include "strbuf.h"
 | 
					#include "strbuf.h"
 | 
				
			||||||
 | 
					#include "sample-util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sink_input* sink_input_new(struct sink *s, struct pa_sample_spec *spec, const char *name) {
 | 
					struct sink_input* sink_input_new(struct sink *s, struct pa_sample_spec *spec, const char *name) {
 | 
				
			||||||
    struct sink_input *i;
 | 
					    struct sink_input *i;
 | 
				
			||||||
| 
						 | 
					@ -22,7 +23,7 @@ struct sink_input* sink_input_new(struct sink *s, struct pa_sample_spec *spec, c
 | 
				
			||||||
    i->get_latency = NULL;
 | 
					    i->get_latency = NULL;
 | 
				
			||||||
    i->userdata = NULL;
 | 
					    i->userdata = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    i->volume = 0xFF;
 | 
					    i->volume = VOLUME_NORM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert(s->core);
 | 
					    assert(s->core);
 | 
				
			||||||
    r = idxset_put(s->core->sink_inputs, i, &i->index);
 | 
					    r = idxset_put(s->core->sink_inputs, i, &i->index);
 | 
				
			||||||
| 
						 | 
					@ -64,7 +65,7 @@ char *sink_input_list_to_string(struct core *c) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = idxset_first(c->sink_inputs, &index); i; i = idxset_next(c->sink_inputs, &index)) {
 | 
					    for (i = idxset_first(c->sink_inputs, &index); i; i = idxset_next(c->sink_inputs, &index)) {
 | 
				
			||||||
        assert(i->sink);
 | 
					        assert(i->sink);
 | 
				
			||||||
        strbuf_printf(s, "    index: %u, name: <%s>, sink: <%u>; volume: <0x%02x>, latency: <%u usec>\n",
 | 
					        strbuf_printf(s, "    index: %u, name: <%s>, sink: <%u>; volume: <0x%04x>, latency: <%u usec>\n",
 | 
				
			||||||
                      i->index,
 | 
					                      i->index,
 | 
				
			||||||
                      i->name,
 | 
					                      i->name,
 | 
				
			||||||
                      i->sink->index,
 | 
					                      i->sink->index,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ struct sink_input {
 | 
				
			||||||
    char *name;
 | 
					    char *name;
 | 
				
			||||||
    struct sink *sink;
 | 
					    struct sink *sink;
 | 
				
			||||||
    struct pa_sample_spec sample_spec;
 | 
					    struct pa_sample_spec sample_spec;
 | 
				
			||||||
    uint8_t volume;
 | 
					    uint32_t volume;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    int (*peek) (struct sink_input *i, struct memchunk *chunk);
 | 
					    int (*peek) (struct sink_input *i, struct memchunk *chunk);
 | 
				
			||||||
    void (*drop) (struct sink_input *i, size_t length);
 | 
					    void (*drop) (struct sink_input *i, size_t length);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										9
									
								
								src/todo
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								src/todo
									
										
									
									
									
								
							| 
						 | 
					@ -2,16 +2,17 @@
 | 
				
			||||||
       recording
 | 
					       recording
 | 
				
			||||||
       sync() function
 | 
					       sync() function
 | 
				
			||||||
       more functions
 | 
					       more functions
 | 
				
			||||||
 | 
					- esound protocol:
 | 
				
			||||||
 | 
					       recording
 | 
				
			||||||
 | 
					- split oss-dma?
 | 
				
			||||||
- simple library
 | 
					- simple library
 | 
				
			||||||
- simple control protocol: 
 | 
					- simple control protocol: 
 | 
				
			||||||
       kill client/input/output
 | 
					       kill client/input/output
 | 
				
			||||||
       set_volume
 | 
					 | 
				
			||||||
- resampling
 | 
					- resampling
 | 
				
			||||||
- volume adjust on single sink input
 | 
					 | 
				
			||||||
- fp volume scaling (both < and > 1)
 | 
					 | 
				
			||||||
- esound protocol
 | 
					 | 
				
			||||||
- config parser/cmdline
 | 
					- config parser/cmdline
 | 
				
			||||||
- record testing
 | 
					- record testing
 | 
				
			||||||
 | 
					- mixing/volume
 | 
				
			||||||
 | 
					- kill() routines in all modules
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- 0.1
 | 
					-- 0.1
 | 
				
			||||||
- future cancellation
 | 
					- future cancellation
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue