Panda3D
wavAudioCursor.h
1 // Filename: wavAudioCursor.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 WAVAUDIOCURSOR_H
16 #define WAVAUDIOCURSOR_H
17 
18 #include "pandabase.h"
19 #include "movieAudioCursor.h"
20 #include "streamReader.h"
21 
22 class WavAudio;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : WavAudioCursor
26 // Description : Used for reading PCM .wav files. Supported formats
27 // are linear PCM, IEEE float, A-law and mu-law.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDA_MOVIES WavAudioCursor : public MovieAudioCursor {
30 PUBLISHED:
31  WavAudioCursor(WavAudio *src, istream *stream);
32  virtual ~WavAudioCursor();
33  virtual void seek(double offset);
34 
35 public:
36  virtual void read_samples(int n, PN_int16 *data);
37 
38  bool _is_valid;
39 
40 protected:
41  // Format codes as used by wave files.
42  enum Format {
43  F_pcm = 0x0001,
44  F_float = 0x0003,
45  F_alaw = 0x0006,
46  F_mulaw = 0x0007,
47 
48  F_extensible = 0xfffe,
49  };
50 
51  istream *_stream;
52  StreamReader _reader;
53 
54  Format _format;
55  double _byte_rate;
56  int _block_align;
57  int _bytes_per_sample;
58 
59  streampos _data_start;
60  streampos _data_pos;
61  size_t _data_size;
62 
63 public:
64  static TypeHandle get_class_type() {
65  return _type_handle;
66  }
67  static void init_type() {
68  MovieAudioCursor::init_type();
69  register_type(_type_handle, "WavAudioCursor",
70  MovieAudioCursor::get_class_type());
71  }
72  virtual TypeHandle get_type() const {
73  return get_class_type();
74  }
75  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
76 
77 private:
78  static TypeHandle _type_handle;
79 };
80 
81 #include "wavAudioCursor.I"
82 
83 #endif // WAVAUDIOCURSOR_H
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
Used for reading PCM .wav files.
A MovieAudio is actually any source that provides a sequence of audio samples.
A native PCM .wav loader.
Definition: wavAudio.h:28
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A class to read sequential binary data directly from an istream.
Definition: streamReader.h:30
virtual void seek(double offset)
Skips to the specified offset within the file.