summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/chaining_example.c11
-rw-r--r--examples/decoder_example.c6
-rw-r--r--examples/encoder_example.c4
-rw-r--r--examples/seeking_example.c121
-rw-r--r--examples/vorbisfile_example.c8
5 files changed, 94 insertions, 56 deletions
diff --git a/examples/chaining_example.c b/examples/chaining_example.c
index 3910d314..53f9ccfd 100644
--- a/examples/chaining_example.c
+++ b/examples/chaining_example.c
@@ -5,13 +5,13 @@
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.18 2002/10/11 11:14:41 xiphmont Exp $
+ last mod: $Id$
********************************************************************/
@@ -28,15 +28,14 @@ int main(){
OggVorbis_File ov;
int i;
-#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
+#ifdef _WIN32 /* We need to set stdin to binary mode. Damn windows. */
/* Beware the evil ifdef. We avoid these where we can, but this one we
cannot. Don't add any more, you'll probably go to hell if you do. */
_setmode( _fileno( stdin ), _O_BINARY );
- _setmode( _fileno( stdout ), _O_BINARY );
#endif
/* open the file/pipe on stdin */
- if(ov_open(stdin,&ov,NULL,-1)<0){
+ if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
printf("Could not open input as an OggVorbis file.\n\n");
exit(1);
}
diff --git a/examples/decoder_example.c b/examples/decoder_example.c
index 209e77fc..dfb142f5 100644
--- a/examples/decoder_example.c
+++ b/examples/decoder_example.c
@@ -5,13 +5,13 @@
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.27 2002/07/12 15:07:52 giles Exp $
+ last mod: $Id$
********************************************************************/
diff --git a/examples/encoder_example.c b/examples/encoder_example.c
index bdc32a5a..95cfe552 100644
--- a/examples/encoder_example.c
+++ b/examples/encoder_example.c
@@ -5,8 +5,8 @@
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
diff --git a/examples/seeking_example.c b/examples/seeking_example.c
index 32fc1e93..829efb57 100644
--- a/examples/seeking_example.c
+++ b/examples/seeking_example.c
@@ -5,13 +5,13 @@
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: illustrate seeking, and test it too
- last mod: $Id: seeking_example.c,v 1.15 2002/07/11 06:40:47 xiphmont Exp $
+ last mod: $Id$
********************************************************************/
@@ -25,35 +25,41 @@
# include <fcntl.h>
#endif
-void _verify(OggVorbis_File *ov,ogg_int64_t pos,
- ogg_int64_t val,ogg_int64_t pcmval,
+void _verify(OggVorbis_File *ov,
+ ogg_int64_t val,ogg_int64_t pcmval,double timeval,
ogg_int64_t pcmlength,
char *bigassbuffer){
int j;
long bread;
char buffer[4096];
int dummy;
+ ogg_int64_t pos;
/* verify the raw position, the pcm position and position decode */
if(val!=-1 && ov_raw_tell(ov)<val){
- printf("raw position out of tolerance: requested %ld, got %ld\n",
+ fprintf(stderr,"raw position out of tolerance: requested %ld, got %ld\n",
(long)val,(long)ov_raw_tell(ov));
exit(1);
}
if(pcmval!=-1 && ov_pcm_tell(ov)>pcmval){
- printf("pcm position out of tolerance: requested %ld, got %ld\n",
+ fprintf(stderr,"pcm position out of tolerance: requested %ld, got %ld\n",
(long)pcmval,(long)ov_pcm_tell(ov));
exit(1);
}
+ if(timeval!=-1 && ov_time_tell(ov)>timeval){
+ fprintf(stderr,"time position out of tolerance: requested %f, got %f\n",
+ timeval,ov_time_tell(ov));
+ exit(1);
+ }
pos=ov_pcm_tell(ov);
if(pos<0 || pos>pcmlength){
- printf("pcm position out of bounds: got %ld\n",(long)pos);
+ fprintf(stderr,"pcm position out of bounds: got %ld\n",(long)pos);
exit(1);
}
bread=ov_read(ov,buffer,4096,1,1,1,&dummy);
for(j=0;j<bread;j++){
if(buffer[j]!=bigassbuffer[j+pos*2]){
- printf("data position after seek doesn't match pcm position\n");
+ fprintf(stderr,"data position after seek doesn't match pcm position\n");
{
FILE *f=fopen("a.m","w");
@@ -73,18 +79,18 @@ int main(){
OggVorbis_File ov;
int i,ret;
ogg_int64_t pcmlength;
+ double timelength;
char *bigassbuffer;
int dummy;
#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
_setmode( _fileno( stdin ), _O_BINARY );
- _setmode( _fileno( stdout ), _O_BINARY );
#endif
/* open the file/pipe on stdin */
- if(ov_open(stdin,&ov,NULL,-1)<0){
- printf("Could not open input as an OggVorbis file.\n\n");
+ if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
+ fprintf(stderr,"Could not open input as an OggVorbis file.\n\n");
exit(1);
}
@@ -96,7 +102,7 @@ int main(){
for(i=0;i<ov.links;i++){
vorbis_info *vi=ov_info(&ov,i);
if(vi->channels!=2){
- printf("Sorry; right now seeking_test can only use Vorbis files\n"
+ fprintf(stderr,"Sorry; right now seeking_test can only use Vorbis files\n"
"that are entirely stereo.\n\n");
exit(1);
}
@@ -104,8 +110,8 @@ int main(){
/* because we want to do sample-level verification that the seek
does what it claimed, decode the entire file into memory */
- fflush(stdout);
pcmlength=ov_pcm_total(&ov,-1);
+ timelength=ov_time_total(&ov,-1);
bigassbuffer=malloc(pcmlength*2); /* w00t */
i=0;
while(i<pcmlength*2){
@@ -120,83 +126,116 @@ int main(){
(long)(pcmlength*2-i));
}
- /* Exercise all the real seeking cases; ov_raw_seek,
- ov_pcm_seek_page and ov_pcm_seek. time seek is just a wrapper
- on pcm_seek */
{
ogg_int64_t length=ov.end;
- printf("\rtesting raw seeking to random places in %ld bytes....\n",
+ fprintf(stderr,"\rtesting raw seeking to random places in %ld bytes....\n",
(long)length);
for(i=0;i<1000;i++){
ogg_int64_t val=(double)rand()/RAND_MAX*length;
- ogg_int64_t pos;
- printf("\r\t%d [raw position %ld]... ",i,(long)val);
- fflush(stdout);
+ fprintf(stderr,"\r\t%d [raw position %ld]... ",i,(long)val);
ret=ov_raw_seek(&ov,val);
if(ret<0){
- printf("seek failed: %d\n",ret);
+ fprintf(stderr,"seek failed: %d\n",ret);
exit(1);
}
- _verify(&ov,pos,val,-1,pcmlength,bigassbuffer);
+ _verify(&ov,val,-1,-1.,pcmlength,bigassbuffer);
}
}
- printf("\r");
+ fprintf(stderr,"\r");
{
- printf("testing pcm page seeking to random places in %ld samples....\n",
+ fprintf(stderr,"testing pcm page seeking to random places in %ld samples....\n",
(long)pcmlength);
for(i=0;i<1000;i++){
ogg_int64_t val=(double)rand()/RAND_MAX*pcmlength;
- ogg_int64_t pos;
- printf("\r\t%d [pcm position %ld]... ",i,(long)val);
- fflush(stdout);
+ fprintf(stderr,"\r\t%d [pcm position %ld]... ",i,(long)val);
ret=ov_pcm_seek_page(&ov,val);
if(ret<0){
- printf("seek failed: %d\n",ret);
+ fprintf(stderr,"seek failed: %d\n",ret);
exit(1);
}
- _verify(&ov,pos,-1,val,pcmlength,bigassbuffer);
+ _verify(&ov,-1,val,-1.,pcmlength,bigassbuffer);
}
}
- printf("\r");
+ fprintf(stderr,"\r");
{
- ogg_int64_t length=ov.end;
- printf("testing pcm exact seeking to random places in %ld samples....\n",
+ fprintf(stderr,"testing pcm exact seeking to random places in %ld samples....\n",
(long)pcmlength);
for(i=0;i<1000;i++){
ogg_int64_t val=(double)rand()/RAND_MAX*pcmlength;
- ogg_int64_t pos;
- printf("\r\t%d [pcm position %ld]... ",i,(long)val);
- fflush(stdout);
+ fprintf(stderr,"\r\t%d [pcm position %ld]... ",i,(long)val);
ret=ov_pcm_seek(&ov,val);
if(ret<0){
- printf("seek failed: %d\n",ret);
+ fprintf(stderr,"seek failed: %d\n",ret);
exit(1);
}
if(ov_pcm_tell(&ov)!=val){
- printf("Declared position didn't perfectly match request: %ld != %ld\n",
+ fprintf(stderr,"Declared position didn't perfectly match request: %ld != %ld\n",
(long)val,(long)ov_pcm_tell(&ov));
exit(1);
}
- _verify(&ov,pos,-1,val,pcmlength,bigassbuffer);
+ _verify(&ov,-1,val,-1.,pcmlength,bigassbuffer);
+
+ }
+ }
+
+ fprintf(stderr,"\r");
+ {
+ fprintf(stderr,"testing time page seeking to random places in %f seconds....\n",
+ timelength);
+
+ for(i=0;i<1000;i++){
+ double val=(double)rand()/RAND_MAX*timelength;
+ fprintf(stderr,"\r\t%d [time position %f]... ",i,val);
+ ret=ov_time_seek_page(&ov,val);
+ if(ret<0){
+ fprintf(stderr,"seek failed: %d\n",ret);
+ exit(1);
+ }
+
+ _verify(&ov,-1,-1,val,pcmlength,bigassbuffer);
+
+ }
+ }
+
+ fprintf(stderr,"\r");
+ {
+ fprintf(stderr,"testing time exact seeking to random places in %f seconds....\n",
+ timelength);
+
+ for(i=0;i<1000;i++){
+ double val=(double)rand()/RAND_MAX*timelength;
+ fprintf(stderr,"\r\t%d [time position %f]... ",i,val);
+ ret=ov_time_seek(&ov,val);
+ if(ret<0){
+ fprintf(stderr,"seek failed: %d\n",ret);
+ exit(1);
+ }
+ if(ov_time_tell(&ov)<val-1 || ov_time_tell(&ov)>val+1){
+ fprintf(stderr,"Declared position didn't perfectly match request: %f != %f\n",
+ val,ov_time_tell(&ov));
+ exit(1);
+ }
+
+ _verify(&ov,-1,-1,val,pcmlength,bigassbuffer);
}
}
- printf("\r \nOK.\n\n");
+ fprintf(stderr,"\r \nOK.\n\n");
}else{
- printf("Standard input was not seekable.\n");
+ fprintf(stderr,"Standard input was not seekable.\n");
}
ov_clear(&ov);
diff --git a/examples/vorbisfile_example.c b/examples/vorbisfile_example.c
index 36e679e0..61fb0d7b 100644
--- a/examples/vorbisfile_example.c
+++ b/examples/vorbisfile_example.c
@@ -5,13 +5,13 @@
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: simple example decoder using vorbisfile
- last mod: $Id: vorbisfile_example.c,v 1.10 2002/07/11 06:40:47 xiphmont Exp $
+ last mod: $Id$
********************************************************************/
@@ -44,7 +44,7 @@ int main(){
_setmode( _fileno( stdout ), _O_BINARY );
#endif
- if(ov_open(stdin, &vf, NULL, 0) < 0) {
+ if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
exit(1);
}