]> mj.ucw.cz Git - vcut.git/blob - vorbistest.c
OK
[vcut.git] / vorbistest.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <unistd.h>
5 #include <vorbis/vorbisfile.h>
6
7 static void die(char *msg, ...)
8 {
9   va_list args;
10   va_start(args, msg);
11   vfprintf(stderr, msg, args);
12   fputc('\n', stderr);
13   exit(1);
14 }
15
16 int main(void)
17 {
18   OggVorbis_File vf;
19   int err;
20
21   err = ov_open(stdin, &vf, NULL, 0);
22   if (err)
23     die("ov_open: error %d", err);
24   if (!ov_seekable(&vf))
25     die("Input is not seekable");
26
27   int nstr = ov_streams(&vf);
28   printf("Found %d logical streams\n", nstr);
29   for (int i=0; i<nstr; i++)
30     {
31       vorbis_info *vi;
32       vi = ov_info(&vf, i);
33       if (!vi)
34         die("ov_info failed");
35       printf("Stream %d: v=%d chan=%d rate=%ld nbr=%ld rawsize=%Ld samples=%Ld\n", i,
36              vi->version, vi->channels, vi->rate, vi->bitrate_nominal,
37              ov_raw_total(&vf, i), ov_pcm_total(&vf, i));
38
39       vorbis_comment *vc;
40       vc = ov_comment(&vf, i);
41       if (!vc)
42         die("ov_comment failed");
43       for (int j=0; j<vc->comments; j++)
44         printf("\t%.*s\n", vc->comment_lengths[j], vc->user_comments[j]);
45     }
46
47   printf("Decoding...\n");
48   char buf[4096];
49   for(;;)
50     {
51       printf("@%Ld #%ld ", ov_pcm_tell(&vf), ov_serialnumber(&vf, -1));
52       int bp;
53       int e = ov_read(&vf, buf, sizeof(buf), 0, 2, 1, &bp);
54       printf("S%d >%d\n", bp, e);
55       if (!e)
56         break;
57       if (e == OV_HOLE)
58         printf("!!! HOLE DETECTED\n");
59       else if (e == OV_EBADLINK)
60         printf("!!! BAD LINK\n");
61     }
62
63   ov_clear(&vf);
64   return 0;
65 }