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