Panda3D

userDataAudio.h

00001 // Filename: userDataAudio.h
00002 // Created by: jyelon (02Jul07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef USERDATAAUDIO_H
00016 #define USERDATAAUDIO_H
00017 
00018 #include "movieAudio.h"
00019 #include "datagramIterator.h"
00020 #include "pdeque.h"
00021 
00022 class MovieAudioCursor;
00023 class UserDataAudioCursor;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : UserDataAudio
00027 // Description : A UserDataAudio is a way for the user to manually
00028 //               supply raw audio samples. remove_after_read means the
00029 //               data will be removed if read once. Else data will
00030 //               be stored (enable looping and seeking).
00031 //               Expects data as 16 bit signed (word); Example for stereo:
00032 //               1.word = 1.channel,2.word = 2.channel,
00033 //               3.word = 1.channel,4.word = 2.channel, etc.
00034 ////////////////////////////////////////////////////////////////////
00035 class EXPCL_PANDA_MOVIES UserDataAudio : public MovieAudio {
00036 
00037  PUBLISHED:
00038   UserDataAudio(int rate, int channels, bool remove_after_read=true);
00039   virtual ~UserDataAudio();
00040   virtual PT(MovieAudioCursor) open();
00041 
00042   void append(PN_int16 *data, int n);
00043   void append(DatagramIterator *src, int len=0x40000000);
00044   void append(const string &str);
00045   void done(); // A promise not to write any more samples.  
00046 
00047  private:
00048   void read_samples(int n, PN_int16 *data);
00049   void update_cursor();
00050   int _desired_rate;
00051   int _desired_channels;
00052   UserDataAudioCursor *_cursor;
00053   pdeque<PN_int16> _data;
00054   bool _aborted;
00055   bool _remove_after_read;
00056   friend class UserDataAudioCursor;
00057   
00058  public:
00059   static TypeHandle get_class_type() {
00060     return _type_handle;
00061   }
00062   static void init_type() {
00063     MovieAudio::init_type();
00064     register_type(_type_handle, "UserDataAudio",
00065                   MovieAudio::get_class_type());
00066   }
00067   virtual TypeHandle get_type() const {
00068     return get_class_type();
00069   }
00070   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00071 
00072  private:
00073   static TypeHandle _type_handle;
00074 };
00075 
00076 #include "userDataAudio.I"
00077 
00078 #endif
 All Classes Functions Variables Enumerations