From 0dd0e3e026ea41b75d5f9d43cd3ca599a1aa38ec Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 12 May 2000 08:38:20 +0000 Subject: [PATCH] Addition of win32 support to the examples (changing stdin/stdout to binary mode). svn path=/trunk/vorbis/; revision=389 --- examples/decoder_example.c | 28 +++++++++++++++++++++------- examples/encoder_example.c | 20 +++++++++++++++++--- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/examples/decoder_example.c b/examples/decoder_example.c index 23542af..8e6abf2 100644 --- a/examples/decoder_example.c +++ b/examples/decoder_example.c @@ -12,7 +12,7 @@ ******************************************************************** function: simple example decoder - last mod: $Id: decoder_example.c,v 1.6 2000/05/12 05:50:11 msmith Exp $ + last mod: $Id: decoder_example.c,v 1.7 2000/05/12 08:38:20 msmith Exp $ ********************************************************************/ @@ -23,13 +23,19 @@ /* Note that this is POSIX, not ANSI code */ #include +#include #include #include "vorbis/codec.h" +#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ +#include +#include +#endif + int16_t convbuffer[4096]; /* take 8k out of the data segment, not the stack */ int convsize=4096; -int main(){ +int main(int argc, char **argv){ ogg_sync_state oy; /* sync and verify incoming physical bitstream */ ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */ @@ -45,6 +51,14 @@ int main(){ char *buffer; int bytes; +#ifdef _WIN32 /* We need to set stdin/stdout 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 + + /********** Decode setup ************/ ogg_sync_init(&oy); /* Now we can read pages */ @@ -144,7 +158,7 @@ int main(){ /* no harm in not checking before adding more */ buffer=ogg_sync_buffer(&oy,4096); bytes=fread(buffer,1,4096,stdin); - if(bytes==0 && i < 2){ + if(bytes==0 && i<2){ fprintf(stderr,"End of file before finding all Vorbis headers!\n"); exit(1); } @@ -207,14 +221,14 @@ int main(){ while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){ int j; int clipflag=0; - int out=(samples32767){ @@ -234,9 +248,9 @@ int main(){ fprintf(stderr,"Clipping in frame %ld\n",vd.sequence); - fwrite(convbuffer,2*vi.channels,out,stdout); + fwrite(convbuffer,2*vi.channels,bout,stdout); - vorbis_synthesis_read(&vd,out); /* tell libvorbis how + vorbis_synthesis_read(&vd,bout); /* tell libvorbis how many samples we actually consumed */ } diff --git a/examples/encoder_example.c b/examples/encoder_example.c index 530e27f..a2851bf 100644 --- a/examples/encoder_example.c +++ b/examples/encoder_example.c @@ -12,7 +12,7 @@ ******************************************************************** function: simple example encoder - last mod: $Id: encoder_example.c,v 1.6 2000/01/28 15:25:07 xiphmont Exp $ + last mod: $Id: encoder_example.c,v 1.7 2000/05/12 08:38:20 msmith Exp $ ********************************************************************/ @@ -27,6 +27,12 @@ #include #include "vorbis/modes.h" +#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ +#include +#include +#endif + + #define READ 1024 signed char readbuffer[READ*4+44]; /* out of the data segment, not the stack */ @@ -49,6 +55,14 @@ int main(){ verify that it matches 16bit/stereo/44.1kHz. This is just an example, after all. */ +#ifdef _WIN32 /* We need to set stdin/stdout 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 + + fread(readbuffer,1,44,stdin); /********** Encode setup ************/ @@ -68,8 +82,8 @@ int main(){ /* set up our packet->stream encoder */ /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ - srandom(time(NULL)); - ogg_stream_init(&os,random()); + srand(time(NULL)); + ogg_stream_init(&os,rand()); /* Vorbis streams begin with three headers; the initial header (with most of the codec setup parameters) which is mandated by the Ogg -- 2.7.4