1 #include "ogglength.h"
2
3 #ifdef OGG_SUPPORT
4 //Inspired from ogginfo.c
5 // part of the vorbis-tools package of the OGG Vorbis project
OGG_length(const char * filename)6 int OGG_length(const char *filename)
7 {
8 FILE *fp;
9 OggVorbis_File vf;
10 int rc,i;
11 double playtime;
12
13 memset(&vf,0,sizeof(OggVorbis_File));
14
15 fp = fopen(filename,"r");
16 if (!fp) {
17 fprintf(stderr,"Unable to open \"%s\n", filename);
18 }
19
20 rc = ov_open(fp,&vf,NULL,0);
21
22 if (rc < 0) {
23 fprintf(stderr,"Unable to understand \"%s\", errorcode=%d\n", filename, rc);
24 return 0;
25 }
26
27 playtime = (double) ov_time_total(&vf,-1);
28
29 // printf("length (seconds) =%f\n",playtime);
30 // printf("length (samples) =%d\n",((int) (playtime * 75)));
31
32 ov_clear(&vf);
33
34 return (int) (playtime * 75.0);
35 }
36
37 #endif
38