Panda3D
vorbisAudioCursor.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file vorbisAudioCursor.h
10  * @author rdb
11  * @date 2013-08-23
12  */
13 
14 #ifndef VORBISAUDIOCURSOR_H
15 #define VORBISAUDIOCURSOR_H
16 
17 #include "pandabase.h"
18 #include "movieAudioCursor.h"
19 
20 #ifdef HAVE_VORBIS
21 
22 #include <vorbis/codec.h>
23 #include <vorbis/vorbisfile.h>
24 
25 class VorbisAudio;
26 
27 /**
28  * Interfaces with the libvorbisfile library to implement decoding of Ogg
29  * Vorbis audio files.
30  */
31 class EXPCL_PANDA_MOVIES VorbisAudioCursor : public MovieAudioCursor {
32 PUBLISHED:
33  explicit VorbisAudioCursor(VorbisAudio *src, std::istream *stream);
34  virtual ~VorbisAudioCursor();
35  virtual void seek(double offset);
36 
37 public:
38  virtual void read_samples(int n, int16_t *data);
39 
40  bool _is_valid;
41 
42 private:
43  // Callbacks passed to libvorbisfile that read via VFS.
44  static size_t cb_read_func(void *ptr, size_t size, size_t nmemb, void *datasource);
45  static int cb_seek_func(void *datasource, ogg_int64_t offset, int whence);
46  static int cb_close_func(void *datasource);
47  static long cb_tell_func(void *datasource);
48 
49 protected:
50 #ifndef CPPPARSER
51  OggVorbis_File _ov;
52 #endif
53 
54  int _bitstream;
55  double _byte_rate;
56  int _block_align;
57  int _bytes_per_sample;
58  bool _is_float;
59 
60  std::streampos _data_start;
61  std::streampos _data_pos;
62  size_t _data_size;
63 
64 public:
65  static TypeHandle get_class_type() {
66  return _type_handle;
67  }
68  static void init_type() {
69  MovieAudioCursor::init_type();
70  register_type(_type_handle, "VorbisAudioCursor",
71  MovieAudioCursor::get_class_type());
72  }
73  virtual TypeHandle get_type() const {
74  return get_class_type();
75  }
76  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
77 
78 private:
79  static TypeHandle _type_handle;
80 };
81 
82 #include "vorbisAudioCursor.I"
83 
84 #endif // HAVE_VORBIS
85 
86 #endif // VORBISAUDIOCURSOR_H
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A MovieAudio is actually any source that provides a sequence of audio samples.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual void seek(double offset)
Skips to the specified offset within the file.