H3D API  2.4.1
AudioFileReader.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 #ifndef __AUDIOFILEREADER_H__
30 #define __AUDIOFILEREADER_H__
31 
32 #include <H3D/H3DSoundFileNode.h>
33 
34 #ifdef HAVE_LIBAUDIOFILE
35 #include <audiofile.h>
36 
37 namespace H3D {
38 
48  class H3DAPI_API AudioFileReader : public H3DSoundFileNode {
49  public:
50 
53  file = NULL;
54  type_name = "AudioFileReader";
55  }
56 
59  if( file )
60  afCloseFile( file );
61  }
62 
65  unsigned int load( const string &_url );
66 
68  virtual void reset() {
69  afSeekFrame( file, AF_DEFAULT_TRACK, 0 );
70  }
71 
73  virtual unsigned int totalDataSize() {
74  return (unsigned int ) afGetTrackBytes( file, AF_DEFAULT_TRACK );
75  }
76 
79  virtual unsigned int nrChannels() {
80  return afGetChannels( file, AF_DEFAULT_TRACK );
81  }
82 
85  virtual unsigned int samplesPerSecond() {
86  return (unsigned int) afGetRate( file, AF_DEFAULT_TRACK );
87  }
88 
90  virtual unsigned int bitsPerSample() {
91  int sample_format, sample_width;
92  afGetVirtualSampleFormat( file, AF_DEFAULT_TRACK,
93  &sample_format, &sample_width );
94  return sample_width;
95  }
96 
98  virtual H3DTime duration() {
99  return afGetFrameCount(file, AF_DEFAULT_TRACK) /
100  afGetRate(file, AF_DEFAULT_TRACK);
101  }
102 
107  virtual unsigned int read( char *buffer, unsigned int size );
108 
111  static bool supportsFileType( const string &url );
112 
115 
118 
119  protected:
120  AFfilehandle file;
121  string url;
122  };
123 }
124 
125 #endif
126 #endif
Header file for H3DSoundFileNode, X3D scene-graph node.
AudioFileReader uses the Audio File Library ( http://www.68k.org/~michael/audiofile/ ) to read sound ...
Definition: AudioFileReader.h:48
virtual H3DTime duration()
The duration in seconds for the the PCM data.
Definition: AudioFileReader.h:98
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: AudioFileReader.h:114
virtual void reset()
Reset the stream to the beginning of the sound stream.
Definition: AudioFileReader.h:68
virtual unsigned int totalDataSize()
Returns the total size of the PCM data of the current stream.
Definition: AudioFileReader.h:73
virtual unsigned int bitsPerSample()
Returns the number of bits for a sample.
Definition: AudioFileReader.h:90
~AudioFileReader()
Destructor.
Definition: AudioFileReader.h:58
AudioFileReader()
Constructor.
Definition: AudioFileReader.h:52
virtual unsigned int samplesPerSecond()
Returns the number of samples per second for the current PCM data stream.
Definition: AudioFileReader.h:85
static FileReaderRegistration reader_registration
Register this node to the H3DSoundFileNodes available.
Definition: AudioFileReader.h:117
virtual unsigned int nrChannels()
Returns the number of channels per second for the current PCM data stream.
Definition: AudioFileReader.h:79
This abstract node type is used to derive node types that can stream PCM sound data from a file.
Definition: H3DSoundFileNode.h:46
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