chainingexample.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <html>
  2. <head>
  3. <title>vorbisfile - Example Code</title>
  4. <link rel=stylesheet href="style.css" type="text/css">
  5. </head>
  6. <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
  7. <table border=0 width=100%>
  8. <tr>
  9. <td><p class=tiny>vorbisfile documentation</p></td>
  10. <td align=right><p class=tiny>vorbisfile version 1.25 - 20000615</p></td>
  11. </tr>
  12. </table>
  13. <h1>Chaining Example Code</h1>
  14. <p>
  15. The following is a run-through of the chaining example program supplied
  16. with vorbisfile - <a href="chaining_example_c.html">chaining_example.c</a>.
  17. This program demonstrates how to work with a chained bitstream.
  18. <p>
  19. First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
  20. <br><br>
  21. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  22. <tr bgcolor=#cccccc>
  23. <td>
  24. <pre><b>
  25. #include "vorbis/codec.h"
  26. #include "vorbis/vorbisfile.h"
  27. #include "../lib/misc.h"
  28. </b></pre>
  29. </td>
  30. </tr>
  31. </table>
  32. <p>Inside main(), we declare our primary OggVorbis_File structure. We also declare a other helpful variables to track our progress within the file.
  33. <br><br>
  34. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  35. <tr bgcolor=#cccccc>
  36. <td>
  37. <pre><b>
  38. int main(){
  39. OggVorbis_File ov;
  40. int i;
  41. </b></pre>
  42. </td>
  43. </tr>
  44. </table>
  45. <p><a href="ov_open.html">ov_open()</a> must be
  46. called to initialize the <a href="OggVorbis_File.html">OggVorbis_File</a> structure with default values.
  47. <a href="ov_open.html">ov_open()</a> also checks to ensure that we're reading Vorbis format and not something else.
  48. <br><br>
  49. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  50. <tr bgcolor=#cccccc>
  51. <td>
  52. <pre><b>
  53. if(ov_open(stdin,&ov,NULL,-1)<0){
  54. printf("Could not open input as an OggVorbis file.\n\n");
  55. exit(1);
  56. }
  57. </b></pre>
  58. </td>
  59. </tr>
  60. </table>
  61. <p>
  62. First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
  63. <p>Then we're going to find the number of logical bitstreams in the physical bitstream using <a href="ov_streams.html">ov_streams</a>.
  64. <p>We use <a href="ov_time_total.html">ov_time_total</a> to determine the total length of the physical bitstream. We specify that we want the entire bitstream by using the argument <tt>-1</tt>.
  65. <br><br>
  66. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  67. <tr bgcolor=#cccccc>
  68. <td>
  69. <pre><b>
  70. if(ov_seekable(&ov)){
  71. printf("Input bitstream contained %ld logical bitstream section(s).\n",
  72. ov_streams(&ov));
  73. printf("Total bitstream playing time: %ld seconds\n\n",
  74. (long)ov_time_total(&ov,-1));
  75. }else{
  76. printf("Standard input was not seekable.\n"
  77. "First logical bitstream information:\n\n");
  78. }
  79. </b></pre>
  80. </td>
  81. </tr>
  82. </table>
  83. <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
  84. <p>We use <a href="ov_info.html">ov_info</a> to pull out the <a href="vorbis_info.html">vorbis_info</a> struct for each logical bitstream. This struct contains bitstream-specific info.
  85. <p><a href="ov_serialnumber.html">ov_serialnumber</a> retrieves the unique serial number for the logical bistream. <a href="ov_raw_total.html">ov_raw_total</a> gives the total compressed bytes for the logical bitstream, and <a href="ov_time_total.html">ov_time_total</a> gives the total time in the logical bitstream.
  86. <br><br>
  87. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  88. <tr bgcolor=#cccccc>
  89. <td>
  90. <pre><b>
  91. for(i=0;i<ov_streams(&ov);i++){
  92. vorbis_info *vi=ov_info(&ov,i);
  93. printf("\tlogical bitstream section %d information:\n",i+1);
  94. printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
  95. vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
  96. ov_serialnumber(&ov,i));
  97. printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
  98. printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
  99. }
  100. </b></pre>
  101. </td>
  102. </tr>
  103. </table>
  104. <p>
  105. When we're done with the entire physical bitstream, we need to call <a href="ov_clear.html">ov_clear()</a> to release the bitstream.
  106. <br><br>
  107. <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
  108. <tr bgcolor=#cccccc>
  109. <td>
  110. <pre><b>
  111. ov_clear(&ov);
  112. return 0;
  113. }
  114. </b></pre>
  115. </td>
  116. </tr>
  117. </table>
  118. <p>
  119. The full source for chaining_example.c can be found with the vorbis
  120. distribution in <a href="chaining_example_c.html">chaining_example.c</a>.
  121. <br><br>
  122. <hr noshade>
  123. <table border=0 width=100%>
  124. <tr valign=top>
  125. <td><p class=tiny>copyright &copy; 2000 vorbis team</p></td>
  126. <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a><br><a href="mailto:team@vorbis.org">team@vorbis.org</a></p></td>
  127. </tr><tr>
  128. <td><p class=tiny>vorbisfile documentation</p></td>
  129. <td align=right><p class=tiny>vorbisfile version 1.25 - 20000615</p></td>
  130. </tr>
  131. </table>
  132. </body>
  133. </html>