H3D API  2.4.1
OggFileReader.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 
30 #ifndef __OGGFILEREADER_H__
31 #define __OGGFILEREADER_H__
32 
33 #include <H3D/H3DSoundFileNode.h>
34 
35 #ifdef HAVE_LIBVORBIS
36 #include <vorbis/vorbisfile.h>
37 
38 namespace H3D {
39 
45  class H3DAPI_API OggFileReader : public H3DSoundFileNode {
46  public:
47 
49  OggFileReader() : ogg_file(), info( NULL ), comment( NULL ) {
50  should_clear = false;
51  type_name = "OggFileReader";
52  }
53 
56  if( should_clear )
57  ov_clear( &ogg_file );
58  }
59 
62  unsigned int load( const string &_url );
63 
65  virtual H3DTime duration() {
66  return ov_time_total( &ogg_file, -1 );
67  }
68 
70  virtual void reset() {
71  ov_raw_seek( &ogg_file, 0 );
72  }
73 
75  virtual unsigned int totalDataSize() {
76  return (unsigned int)( ov_pcm_total( &ogg_file, -1 ) * bitsPerSample() / 8 );
77  }
78 
81  virtual unsigned int nrChannels() {
82  return info->channels;
83  }
84 
86  virtual unsigned int bitsPerSample() {
87  return 16;
88  }
89 
94  virtual unsigned int read( char *buffer, unsigned int size );
95 
98  virtual unsigned int samplesPerSecond() {
99  return info->rate;
100  }
101 
104  static bool supportsFileType( const string &url );
105 
108 
111 
112  protected:
113  OggVorbis_File ogg_file;
114  // used to know if ov_clear should be called
115  // there was a problem when creating and destroying OggFileReader
116  // without using it.
117  bool should_clear;
118  vorbis_info* info;
119  vorbis_comment *comment;
120  string url;
121  };
122 }
123 
124 #endif
125 #endif
Header file for H3DSoundFileNode, X3D scene-graph node.
This abstract node type is used to derive node types that can stream PCM sound data from a file.
Definition: H3DSoundFileNode.h:46
OggFileReader uses the libVorbis (http://www.vorbis.com) decoder library to support Ogg Vorbis files.
Definition: OggFileReader.h:45
virtual unsigned int totalDataSize()
Returns the total size of the PCM data of the current stream.
Definition: OggFileReader.h:75
virtual unsigned int samplesPerSecond()
Returns the number of samples per second for the current PCM data stream.
Definition: OggFileReader.h:98
virtual void reset()
Reset the stream to the beginning of the sound stream.
Definition: OggFileReader.h:70
OggFileReader()
Constructor.
Definition: OggFileReader.h:49
virtual unsigned int bitsPerSample()
Returns the number of bits for a sample.
Definition: OggFileReader.h:86
virtual H3DTime duration()
The duration in seconds for the the PCM data.
Definition: OggFileReader.h:65
virtual unsigned int nrChannels()
Returns the number of channels per second for the current PCM data stream.
Definition: OggFileReader.h:81
~OggFileReader()
Destructor.
Definition: OggFileReader.h:55
static FileReaderRegistration reader_registration
Register this node to the H3DSoundFileNodes available.
Definition: OggFileReader.h:110
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: OggFileReader.h:107
double H3DTime
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
Class used to register a class to the registered file readers.
Definition: H3DSoundFileNode.h:58