Panda3D
vorbisAudio.cxx
1 // Filename: vorbisAudio.cxx
2 // Created by: rdb (23Aug13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "vorbisAudio.h"
16 #include "vorbisAudioCursor.h"
17 #include "virtualFileSystem.h"
18 #include "dcast.h"
19 
20 #ifdef HAVE_VORBIS
21 
22 TypeHandle VorbisAudio::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: VorbisAudio::Constructor
26 // Access: Protected
27 // Description: xxx
28 ////////////////////////////////////////////////////////////////////
29 VorbisAudio::
30 VorbisAudio(const Filename &name) :
31  MovieAudio(name)
32 {
33  _filename = name;
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: VorbisAudio::Destructor
38 // Access: Protected, Virtual
39 // Description: xxx
40 ////////////////////////////////////////////////////////////////////
41 VorbisAudio::
42 ~VorbisAudio() {
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: VorbisAudio::open
47 // Access: Published, Virtual
48 // Description: Open this audio, returning a MovieAudioCursor
49 ////////////////////////////////////////////////////////////////////
50 PT(MovieAudioCursor) VorbisAudio::
51 open() {
53  istream *stream = vfs->open_read_file(_filename, true);
54 
55  if (stream == NULL) {
56  return NULL;
57  } else {
58  PT(VorbisAudioCursor) cursor = new VorbisAudioCursor(this, stream);
59  if (cursor == NULL || !cursor->_is_valid) {
60  return NULL;
61  } else {
62  return DCAST(MovieAudioCursor, cursor);
63  }
64  }
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: VorbisAudio::make
69 // Access: Published, Static
70 // Description: Obtains a MovieAudio that references a file.
71 ////////////////////////////////////////////////////////////////////
72 PT(MovieAudio) VorbisAudio::
73 make(const Filename &name) {
74  return DCAST(MovieAudio, new VorbisAudio(name));
75 }
76 
77 #endif // HAVE_VORBIS
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A MovieAudio is actually any source that provides a sequence of audio samples.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A MovieAudio is actually any source that provides a sequence of audio samples.
Definition: movieAudio.h:48