source: roaraudio/roarclients/roarvumeter.c @ 1103:bb5ee2384821

Last change on this file since 1103:bb5ee2384821 was 1103:bb5ee2384821, checked in by phi, 15 years ago

disable options needing libm

File size: 3.4 KB
Line 
1//roarcat.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#ifdef ROAR_HAVE_LIBM
28
29#include <math.h>
30
31#define BUFSIZE 1024
32
33void usage (void) {
34 printf("roarvumeter [OPTIONS]...\n");
35
36 printf("\nOptions:\n\n");
37
38 printf("  --server  SERVER   - Set server hostname\n"
39        "  --rate    RATE     - Set sample rate\n"
40        "  --bits    BITS     - Set bits per sample\n"
41        "  --chans   CHANNELS - Set number of channels\n"
42        "  --samples SAMPLES  - Set number of samples\n"
43        "  --help             - Show this help\n"
44       );
45
46}
47
48int vumeter16bit2ch (int fh, int samples, int16_t * buf) {
49 int i;
50 int samples_half = samples/2;
51 double suml, sumr;
52
53 printf("\e[s");
54 fflush(stdout);
55
56 while (read(fh, buf, samples * 2)) {
57  suml = sumr = 0;
58
59  for (i = 0; i < samples; i += 2) {
60   suml += (double) buf[i  ] * (double) buf[i  ];
61   sumr += (double) buf[i+1] * (double) buf[i+1];
62  }
63
64  suml = sqrt(suml/samples_half)/327.68;
65  sumr = sqrt(sumr/samples_half)/327.68;
66
67  printf("L: %3i%% R: %3i%%          \e[u", (int)suml, (int)sumr);
68  fflush(stdout);
69 }
70 return 0;
71}
72
73int vumeter (int fh, int samples, int bits, int channels) {
74 void * buf = malloc(samples*bits*2);
75
76 if ( !buf )
77  return -1;
78
79 if ( bits == 16 ) {
80  if ( channels == 2 ) {
81   vumeter16bit2ch(fh, samples, (int16_t *) buf);
82   free(buf);
83   return 0;
84  } else {
85   return -1;
86  }
87 } else {
88  return -1;
89 }
90}
91
92int main (int argc, char * argv[]) {
93 int    rate     = 44100;
94 int    bits     = 16;
95 int    channels = 2;
96 int    codec    = ROAR_CODEC_DEFAULT;
97 int    samples  = 441;
98 char * server   = NULL;
99 char * k;
100 int    fh;
101 int    i;
102
103 for (i = 1; i < argc; i++) {
104  k = argv[i];
105
106  if ( strcmp(k, "--server") == 0 ) {
107   server = argv[++i];
108  } else if ( strcmp(k, "--rate") == 0 ) {
109   rate = atoi(argv[++i]);
110  } else if ( strcmp(k, "--bits") == 0 ) {
111   bits = atoi(argv[++i]);
112  } else if ( strcmp(k, "--channels") == 0 ) {
113   channels = atoi(argv[++i]);
114  } else if ( strcmp(k, "--samples") == 0 ) {
115   samples = atoi(argv[++i]);
116  } else if ( strcmp(k, "--help") == 0 ) {
117   usage();
118   return 0;
119  } else {
120   fprintf(stderr, "Error: unknown argument: %s\n", k);
121   usage();
122   return 1;
123  }
124 }
125
126 if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarvumeter")) == -1 ) {
127  fprintf(stderr, "Error: can not start playback\n");
128  return 1;
129 }
130
131 vumeter(fh, samples*channels, bits, channels);
132
133 printf("\n"); // if the reach this then roard has quited and we should print a newline
134
135 roar_simple_close(fh);
136
137 return 0;
138}
139
140#else
141int main (void) {
142 fprintf(stderr, "Error: No Math library support compiled in.\n");
143 return 1;
144}
145#endif
146
147//ll
Note: See TracBrowser for help on using the repository browser.