~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to misc/libtremor/ivorbisfile_example.c

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 *                                                                  *
 
3
 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
 
4
 *                                                                  *
 
5
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
 
6
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
 
7
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
 
8
 *                                                                  *
 
9
 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002    *
 
10
 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
 
11
 *                                                                  *
 
12
 ********************************************************************
 
13
 
 
14
 function: simple example decoder using vorbisidec
 
15
 
 
16
 ********************************************************************/
 
17
 
 
18
/* Takes a vorbis bitstream from stdin and writes raw stereo PCM to
 
19
   stdout using vorbisfile. Using vorbisfile is much simpler than
 
20
   dealing with libvorbis. */
 
21
 
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <vorbis/ivorbiscodec.h>
 
25
#include <vorbis/ivorbisfile.h>
 
26
 
 
27
#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
 
28
#include <io.h>
 
29
#include <fcntl.h>
 
30
#endif
 
31
 
 
32
char pcmout[4096]; /* take 4k out of the data segment, not the stack */
 
33
 
 
34
int main(){
 
35
  OggVorbis_File vf;
 
36
  int eof=0;
 
37
  int current_section;
 
38
 
 
39
#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
 
40
  /* Beware the evil ifdef. We avoid these where we can, but this one we 
 
41
     cannot. Don't add any more, you'll probably go to hell if you do. */
 
42
  _setmode( _fileno( stdin ), _O_BINARY );
 
43
  _setmode( _fileno( stdout ), _O_BINARY );
 
44
#endif
 
45
 
 
46
  if(ov_open(stdin, &vf, NULL, 0) < 0) {
 
47
      fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
 
48
      exit(1);
 
49
  }
 
50
 
 
51
  /* Throw the comments plus a few lines about the bitstream we're
 
52
     decoding */
 
53
  {
 
54
    char **ptr=ov_comment(&vf,-1)->user_comments;
 
55
    vorbis_info *vi=ov_info(&vf,-1);
 
56
    while(*ptr){
 
57
      fprintf(stderr,"%s\n",*ptr);
 
58
      ++ptr;
 
59
    }
 
60
    fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
 
61
    fprintf(stderr,"\nDecoded length: %ld samples\n",
 
62
            (long)ov_pcm_total(&vf,-1));
 
63
    fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
 
64
  }
 
65
  
 
66
  while(!eof){
 
67
    long ret=ov_read(&vf,pcmout,sizeof(pcmout),&current_section);
 
68
    if (ret == 0) {
 
69
      /* EOF */
 
70
      eof=1;
 
71
    } else if (ret < 0) {
 
72
      /* error in the stream.  Not a problem, just reporting it in
 
73
         case we (the app) cares.  In this case, we don't. */
 
74
    } else {
 
75
      /* we don't bother dealing with sample rate changes, etc, but
 
76
         you'll have to*/
 
77
      fwrite(pcmout,1,ret,stdout);
 
78
    }
 
79
  }
 
80
 
 
81
  /* cleanup */
 
82
  ov_clear(&vf);
 
83
    
 
84
  fprintf(stderr,"Done.\n");
 
85
  return(0);
 
86
}