[126] | 1 | //roarfilt.c: |
---|
| 2 | |
---|
| 3 | #include <roaraudio.h> |
---|
| 4 | |
---|
| 5 | #define BUFSIZE 1024 |
---|
| 6 | |
---|
| 7 | void usage (void) { |
---|
| 8 | printf("roarcat [OPTIONS]...\n"); |
---|
| 9 | |
---|
| 10 | printf("\nOptions:\n\n"); |
---|
| 11 | |
---|
| 12 | printf(" --server SERVER - Set server hostname\n" |
---|
| 13 | " --rate RATE - Set sample rate\n" |
---|
| 14 | " --bits BITS - Set bits per sample\n" |
---|
| 15 | " --chans CHANNELS - Set number of channels\n" |
---|
| 16 | " --help - Show this help\n" |
---|
[128] | 17 | "\n" |
---|
| 18 | " --half - half the volume\n" |
---|
| 19 | " --double - double the volume\n" |
---|
[126] | 20 | ); |
---|
| 21 | |
---|
| 22 | } |
---|
| 23 | |
---|
[128] | 24 | void vol2 (void * data, int mul, int div, int len) { |
---|
| 25 | int16_t * samples = (int16_t *) data; |
---|
| 26 | int i; |
---|
| 27 | |
---|
| 28 | len /= 2; |
---|
| 29 | |
---|
| 30 | for (i = 0; i < len; i++) |
---|
| 31 | samples[i] = ((int) samples[i] * mul) / div; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void vol1 (void * data, int mul, int div, int len) { |
---|
| 35 | int8_t * samples = (int8_t *) data; |
---|
| 36 | int i; |
---|
| 37 | |
---|
| 38 | len /= 2; |
---|
| 39 | |
---|
| 40 | for (i = 0; i < len; i++) |
---|
| 41 | samples[i] = ((int) samples[i] * mul) / div; |
---|
| 42 | } |
---|
| 43 | |
---|
[126] | 44 | int main (int argc, char * argv[]) { |
---|
| 45 | int rate = 44100; |
---|
| 46 | int bits = 16; |
---|
| 47 | int channels = 2; |
---|
| 48 | int codec = ROAR_CODEC_DEFAULT; |
---|
| 49 | char * server = NULL; |
---|
| 50 | char * k; |
---|
| 51 | int fh; |
---|
| 52 | int i; |
---|
[128] | 53 | int mul = 1, div = 1; |
---|
[126] | 54 | char buf[BUFSIZE]; |
---|
| 55 | |
---|
| 56 | for (i = 1; i < argc; i++) { |
---|
| 57 | k = argv[i]; |
---|
| 58 | |
---|
| 59 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 60 | server = argv[++i]; |
---|
| 61 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 62 | rate = atoi(argv[++i]); |
---|
| 63 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 64 | bits = atoi(argv[++i]); |
---|
| 65 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 66 | channels = atoi(argv[++i]); |
---|
[128] | 67 | } else if ( strcmp(k, "--half") == 0 ) { |
---|
| 68 | div *= 2; |
---|
| 69 | } else if ( strcmp(k, "--double") == 0 ) { |
---|
| 70 | mul *= 2; |
---|
[126] | 71 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 72 | usage(); |
---|
| 73 | return 0; |
---|
| 74 | } else { |
---|
| 75 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 76 | usage(); |
---|
| 77 | return 1; |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if ( (fh = roar_simple_filter(rate, channels, bits, codec, server, "roarifilt")) == -1 ) { |
---|
| 82 | fprintf(stderr, "Error: can not start playback\n"); |
---|
| 83 | return 1; |
---|
| 84 | } |
---|
| 85 | |
---|
[128] | 86 | if ( mul == div ) { |
---|
| 87 | fprintf(stderr, "Error: filter is useless!\n"); |
---|
| 88 | return 0; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if ( bits == 16 ) { |
---|
| 92 | while((i = read(fh, buf, BUFSIZE))) { |
---|
| 93 | vol2((void*)buf, mul, div, i); |
---|
| 94 | if (write(fh, buf, i) != i) |
---|
| 95 | break; |
---|
| 96 | } |
---|
| 97 | } else if ( bits == 8 ) { |
---|
| 98 | while((i = read(fh, buf, BUFSIZE))) { |
---|
| 99 | vol1((void*)buf, mul, div, i); |
---|
| 100 | if (write(fh, buf, i) != i) |
---|
| 101 | break; |
---|
| 102 | } |
---|
| 103 | } else { |
---|
| 104 | fprintf(stderr, "Error: %i bits per sample is not supported!\n", bits); |
---|
| 105 | return 1; |
---|
| 106 | } |
---|
[126] | 107 | |
---|
| 108 | roar_simple_close(fh); |
---|
| 109 | |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | //ll |
---|