Panda3D
userDataAudio.h
1 // Filename: userDataAudio.h
2 // Created by: jyelon (02Jul07)
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 USERDATAAUDIO_H
16 #define USERDATAAUDIO_H
17 
18 #include "movieAudio.h"
19 #include "datagramIterator.h"
20 #include "pdeque.h"
21 
22 class MovieAudioCursor;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : UserDataAudio
27 // Description : A UserDataAudio is a way for the user to manually
28 // supply raw audio samples. remove_after_read means the
29 // data will be removed if read once. Else data will
30 // be stored (enable looping and seeking).
31 // Expects data as 16 bit signed (word); Example for stereo:
32 // 1.word = 1.channel,2.word = 2.channel,
33 // 3.word = 1.channel,4.word = 2.channel, etc.
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDA_MOVIES UserDataAudio : public MovieAudio {
36 
37  PUBLISHED:
38  UserDataAudio(int rate, int channels, bool remove_after_read=true);
39  virtual ~UserDataAudio();
40  virtual PT(MovieAudioCursor) open();
41 
42  void append(PN_int16 *data, int n);
43  void append(DatagramIterator *src, int len=0x40000000);
44  void append(const string &str);
45  void done(); // A promise not to write any more samples.
46 
47  private:
48  void read_samples(int n, PN_int16 *data);
49  void update_cursor();
50  int _desired_rate;
51  int _desired_channels;
52  UserDataAudioCursor *_cursor;
53  pdeque<PN_int16> _data;
54  bool _aborted;
55  bool _remove_after_read;
56  friend class UserDataAudioCursor;
57 
58  public:
59  static TypeHandle get_class_type() {
60  return _type_handle;
61  }
62  static void init_type() {
63  MovieAudio::init_type();
64  register_type(_type_handle, "UserDataAudio",
65  MovieAudio::get_class_type());
66  }
67  virtual TypeHandle get_type() const {
68  return get_class_type();
69  }
70  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
71 
72  private:
73  static TypeHandle _type_handle;
74 };
75 
76 #include "userDataAudio.I"
77 
78 #endif
A UserDataAudioCursor is a means to manually supply a sequence of raw audio samples.
A MovieAudio is actually any source that provides a sequence of audio samples.
A UserDataAudio is a way for the user to manually supply raw audio samples.
Definition: userDataAudio.h:35
A class to retrieve the individual data elements previously stored in a Datagram. ...
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