summaryrefslogtreecommitdiff
path: root/ztmonitor.c
diff options
context:
space:
mode:
authormatteo <matteo@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2003-02-24 06:00:31 +0000
committermatteo <matteo@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2003-02-24 06:00:31 +0000
commitb574418782d181cbd69a271704d8d3f3a3d38fb6 (patch)
treead59f16dc60d92c9e6c8371347a9ab96c09ebc42 /ztmonitor.c
parent29117b53a69aac3bd45cec6138603e36cd265fd0 (diff)
Mon Feb 24 07:00:01 CET 2003
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@150 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'ztmonitor.c')
-rwxr-xr-xztmonitor.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/ztmonitor.c b/ztmonitor.c
index da186ee..c226c33 100755
--- a/ztmonitor.c
+++ b/ztmonitor.c
@@ -51,6 +51,12 @@
#define FRAG_SIZE 8
+/* Put the ofh (output file handle) outside
+ * the main loop in case we ever add a signal
+ * hanlder.
+ */
+static FILE* ofh = 0;
+
static int stereo = 0;
int audio_open(void)
{
@@ -191,18 +197,33 @@ int main(int argc, char *argv[])
int afd = -1, pfd, pfd2 = -1;
short buf[8192];
short buf2[16384];
+ char output_file[255];
int res, res2;
int visual = 0;
- int x;
+ int x,i;
struct zt_confinfo zc;
if ((argc < 2) || (atoi(argv[1]) < 1)) {
- fprintf(stderr, "Usage: ztmonitor <channel num> [-v]\n");
+ fprintf(stderr, "Usage: ztmonitor <channel num> [-v] [-f FILE]\n");
exit(1);
}
- if (argc > 2) {
- if (!strcmp(argv[2], "-v"))
- visual = 1;
+ for (i = 2; i < argc; ++i) {
+ if (!strcmp(argv[i], "-v"))
+ visual = 1;
+ else if (!strcmp(argv[i], "-f") && (i+1) < argc) {
+ ++i; /*we care about hte file name */
+ if (strlen(argv[i]) < 255 ) {
+ strcpy(output_file, argv[i]);
+ fprintf(stderr, "Output to %s\n", output_file);
+ if ((ofh = fopen(output_file, "w"))<0) {
+ fprintf(stderr, "Could not open %s for writing: %s\n", output_file, strerror(errno));
+ exit(0);
+ }
+ fprintf(stderr, "Run e.g., 'sox -r 8000 -s -w -c 1 file.raw file.wav' to convert.\n");
+ } else {
+ fprintf(stderr, "File Name %s too long\n",argv[i+1]);
+ }
+ }
}
if (!visual) {
/* Open audio */
@@ -253,7 +274,11 @@ int main(int argc, char *argv[])
visualize((short *)buf, (short *)buf2, res/2);
else
printf("Huh? res = %d, res2 = %d?\n", res, res2);
+
} else {
+ if (ofh)
+ fwrite(buf, 1, res, ofh);
+
if (stereo) {
for (x=0;x<res;x++)
buf2[x<<1] = buf2[(x<<1) + 1] = buf[x];
@@ -262,5 +287,6 @@ int main(int argc, char *argv[])
write(afd, buf, res);
}
}
+ if (ofh) fclose(ofh); /*Never Reached */
exit(0);
}