summaryrefslogtreecommitdiffhomepage
path: root/contrib/vorbis/doc/vorbisfile/vorbisfile_example_c.html
blob: f3ba1d6cc7590c6db576f6479aa7d15d5d5d103f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>

<head>
<title>vorbisfile - vorbisfile_example.c</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>

<body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
<table border=0 width=100%>
<tr>
<td><p class=tiny>Vorbisfile documentation</p></td>
<td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
</tr>
</table>

<h1>vorbisfile_example.c</h1>

<p>
The example program source:

<br><br>
<table border=0 width=100% color=black cellspacing=0 cellpadding=7>
<tr bgcolor=#cccccc>
	<td>
<pre><b>
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;math.h&gt;
#include "vorbis/codec.h"
#include "vorbis/vorbisfile.h"

#ifdef _WIN32
#include &lt;io.h&gt;
#include &lt;fcntl.h&gt;
#endif

char pcmout[4096];

int main(int argc, char **argv){
  OggVorbis_File vf;
  int eof=0;
  int current_section;

#ifdef _WIN32
  _setmode( _fileno( stdin ), _O_BINARY );
  _setmode( _fileno( stdout ), _O_BINARY );
#endif

  if(ov_open_callbacks(stdin, &amp;vf, NULL, 0, OV_CALLBACKS_NOCLOSE) &lt; 0) {
      fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
      exit(1);
  }

  {
    char **ptr=ov_comment(&amp;vf,-1)-&gt;user_comments;
    vorbis_info *vi=ov_info(&amp;vf,-1);
    while(*ptr){
      fprintf(stderr,"%s\n",*ptr);
      ++ptr;
    }
    fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi-&gt;channels,vi-&gt;rate);
    fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&amp;vf,-1)-&gt;vendor);
  }
  
  while(!eof){
    long ret=ov_read(&amp;vf,pcmout,sizeof(pcmout),0,2,1,&amp;current_section);
    if (ret == 0) {
      /* EOF */
      eof=1;
    } else if (ret &lt; 0) {
      /* error in the stream.  Not a problem, just reporting it in
	 case we (the app) cares.  In this case, we don't. */
    } else {
      /* we don't bother dealing with sample rate changes, etc, but
	 you'll have to */
      fwrite(pcmout,1,ret,stdout);
    }
  }

  ov_clear(&amp;vf);
    
  fprintf(stderr,"Done.\n");
  return(0);
}

</b></pre>
	</td>
</tr>
</table>


<br><br>
<hr noshade>
<table border=0 width=100%>
<tr valign=top>
<td><p class=tiny>copyright &copy; 2000-2010 Xiph.Org</p></td>
<td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/index.html">Ogg Vorbis</a></p></td>
</tr><tr>
<td><p class=tiny>Vorbisfile documentation</p></td>
<td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
</tr>
</table>

</body>

</html>