Panda3D
vorbisAudioCursor.h
1 // Filename: vorbisAudioCursor.h
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 #ifndef VORBISAUDIOCURSOR_H
16 #define VORBISAUDIOCURSOR_H
17 
18 #include "pandabase.h"
19 #include "movieAudioCursor.h"
20 
21 #ifdef HAVE_VORBIS
22 
23 #include <vorbis/codec.h>
24 #include <vorbis/vorbisfile.h>
25 
26 class VorbisAudio;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : VorbisAudioCursor
30 // Description : Interfaces with the libvorbisfile library to
31 // implement decoding of Ogg Vorbis audio files.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_MOVIES VorbisAudioCursor : public MovieAudioCursor {
34 PUBLISHED:
35  VorbisAudioCursor(VorbisAudio *src, istream *stream);
36  virtual ~VorbisAudioCursor();
37  virtual void seek(double offset);
38 
39 public:
40  virtual void read_samples(int n, PN_int16 *data);
41 
42  bool _is_valid;
43 
44 private:
45  // Callbacks passed to libvorbisfile that read via VFS.
46  static size_t cb_read_func(void *ptr, size_t size, size_t nmemb, void *datasource);
47  static int cb_seek_func(void *datasource, ogg_int64_t offset, int whence);
48  static int cb_close_func(void *datasource);
49  static long cb_tell_func(void *datasource);
50 
51 protected:
52 #ifndef CPPPARSER
53  OggVorbis_File _ov;
54 #endif
55 
56  int _bitstream;
57  double _byte_rate;
58  int _block_align;
59  int _bytes_per_sample;
60  bool _is_float;
61 
62  streampos _data_start;
63  streampos _data_pos;
64  size_t _data_size;
65 
66 public:
67  static TypeHandle get_class_type() {
68  return _type_handle;
69  }
70  static void init_type() {
71  MovieAudioCursor::init_type();
72  register_type(_type_handle, "VorbisAudioCursor",
73  MovieAudioCursor::get_class_type());
74  }
75  virtual TypeHandle get_type() const {
76  return get_class_type();
77  }
78  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
79 
80 private:
81  static TypeHandle _type_handle;
82 };
83 
84 #include "vorbisAudioCursor.I"
85 
86 #endif // HAVE_VORBIS
87 
88 #endif // VORBISAUDIOCURSOR_H
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
A MovieAudio is actually any source that provides a sequence of audio samples.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual void seek(double offset)
Skips to the specified offset within the file.