summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2001-11-22 06:19:52 +0000
committerMonty <xiphmont@xiph.org>2001-11-22 06:19:52 +0000
commit4f02af3cfc348422a9d1362486cc0246e44ea5e3 (patch)
treeaffc6ba250ce942100958796d991dbdc5c4a4d10
parente12c7a09341cab3512fc58e3a00fa0dd9307961b (diff)
downloadlibvorbis-git-4f02af3cfc348422a9d1362486cc0246e44ea5e3.tar.gz
Bitrate management mark II running and running mcorrectly in 'full
blown' mode. Testing to continue. svn path=/branches/branch_monty_20011009/vorbis/; revision=2395
-rw-r--r--examples/chaining_example.c72
-rw-r--r--examples/encoder_example.c39
2 files changed, 93 insertions, 18 deletions
diff --git a/examples/chaining_example.c b/examples/chaining_example.c
new file mode 100644
index 00000000..21b6b1c3
--- /dev/null
+++ b/examples/chaining_example.c
@@ -0,0 +1,72 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * 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-2001 *
+ * by the XIPHOPHORUS Company http://www.xiph.org/ *
+
+ ********************************************************************
+
+ function: illustrate simple use of chained bitstream and vorbisfile.a
+ last mod: $Id: chaining_example.c,v 1.13.2.1 2001/11/22 06:19:52 xiphmont Exp $
+
+ ********************************************************************/
+
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+
+#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
+#include <io.h>
+#include <fcntl.h>
+#endif
+
+int main(){
+ OggVorbis_File ov;
+ int i;
+
+#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
+
+ /* 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");
+ exit(1);
+ }
+
+ /* print details about each logical bitstream in the input */
+ if(ov_seekable(&ov)){
+ printf("Input bitstream contained %ld logical bitstream section(s).\n",
+ ov_streams(&ov));
+ printf("Total bitstream playing time: %ld seconds\n\n",
+ (long)ov_time_total(&ov,-1));
+
+ }else{
+ printf("Standard input was not seekable.\n"
+ "First logical bitstream information:\n\n");
+ }
+
+ for(i=0;i<ov_streams(&ov);i++){
+ vorbis_info *vi=ov_info(&ov,i);
+ printf("\tlogical bitstream section %d information:\n",i+1);
+ printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
+ vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
+ ov_serialnumber(&ov,i));
+ printf("\t\theader length: %ld bytes\n",(long)
+ (ov.dataoffsets[i]-ov.offsets[i]));
+ printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
+ printf("\t\tuncompressed length: %ld bytes\n",
+ (long)(ov_pcm_total(&ov,i))*vi->channels*2+44);
+ printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
+ }
+
+ ov_clear(&ov);
+ return 0;
+}
+
diff --git a/examples/encoder_example.c b/examples/encoder_example.c
index d52c8214..644883d2 100644
--- a/examples/encoder_example.c
+++ b/examples/encoder_example.c
@@ -11,7 +11,7 @@
********************************************************************
function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.27.2.2 2001/10/11 20:34:14 xiphmont Exp $
+ last mod: $Id: encoder_example.c,v 1.27.2.3 2001/11/22 06:19:52 xiphmont Exp $
********************************************************************/
@@ -176,24 +176,27 @@ int main(){
block for encoding now */
while(vorbis_analysis_blockout(&vd,&vb)==1){
- /* analysis */
- vorbis_analysis(&vb,&op);
-
- /* weld the packet into the bitstream */
- ogg_stream_packetin(&os,&op);
-
- /* write out pages (if any) */
- while(!eos){
- int result=ogg_stream_pageout(&os,&og);
- if(result==0)break;
- fwrite(og.header,1,og.header_len,stdout);
- fwrite(og.body,1,og.body_len,stdout);
-
- /* this could be set above, but for illustrative purposes, I do
- it here (to show that vorbis does know where the stream ends) */
-
- if(ogg_page_eos(&og))eos=1;
+ /* analysis, assume we want to use bitrate management */
+ vorbis_analysis(&vb,NULL);
+ vorbis_bitrate_addblock(&vb);
+ while(vorbis_bitrate_flushpacket(&vd,&op)){
+
+ /* weld the packet into the bitstream */
+ ogg_stream_packetin(&os,&op);
+
+ /* write out pages (if any) */
+ while(!eos){
+ int result=ogg_stream_pageout(&os,&og);
+ if(result==0)break;
+ fwrite(og.header,1,og.header_len,stdout);
+ fwrite(og.body,1,og.body_len,stdout);
+
+ /* this could be set above, but for illustrative purposes, I do
+ it here (to show that vorbis does know where the stream ends) */
+
+ if(ogg_page_eos(&og))eos=1;
+ }
}
}
}