• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

examples/example6/SoundPlayer.h

Go to the documentation of this file.
00001 #ifndef FCAM_BEEPER_H
00002 #define FCAM_BEEPER_H
00003 
00006 #include <string>
00007 
00008 #include <FCam/FCam.h>
00009 #include <FCam/Action.h>
00010 #include <FCam/Device.h>
00011 
00012 // PulseAudio headers
00013 #ifdef HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif
00016 #include <stdio.h>
00017 #include <unistd.h>
00018 #include <string.h>
00019 #include <errno.h>
00020 #include <fcntl.h>
00021 #include <pulse/simple.h>
00022 #include <pulse/error.h>
00023 #include <pulse/gccmacro.h>
00024 
00025 #define BUFSIZE 1024
00026 
00027 /*
00028  * A synchronized beeper example. As a device,
00029  * it inherits from FCam::Device, and declares
00030  * nested classes that inherit from CopyableAction
00031  */
00032 class SoundPlayer : public FCam::Device {
00033     
00034 public:
00035     
00036     SoundPlayer();
00037     ~SoundPlayer();
00038     
00039     /*
00040      * An action representing the playback of a .WAV file.
00041      */
00042     class SoundAction : public FCam::CopyableAction<SoundAction> {
00043     public:
00044 
00045         /* Constructors and destructor */
00046         ~SoundAction();
00047         SoundAction(SoundPlayer * b);
00048         SoundAction(SoundPlayer * b, int time);
00049         SoundAction(const SoundAction &);
00050         
00051         /* Implementation of doAction() as required */
00052         void doAction();
00053         
00054         /* Load the specified file into buffer and prepares playback */
00055         void setWavFile(const char * filename);
00056         
00057         /* Return the underlying device */
00058         SoundPlayer * getPlayer() const { return player; }
00059 
00060     protected:
00061         
00062         SoundPlayer * player;
00063         unsigned int *refCount;
00064         std::string filename;
00065         unsigned char * buffer; // reference-counted dump of wave file.
00066         int size;
00067     };
00068     
00069     /* Normally, this is where a device would add metadata tags to a
00070      * just-created frame , based on the timestamps in the
00071      * Frame. However, we don't have anything useful to add here, so
00072      * tagFrame does nothing. */
00073     void tagFrame(FCam::Frame) {}
00074     
00075     /* Play a buffer */
00076     void playBuffer(unsigned char * buffer, size_t size);
00077     
00078     /* Returns latency in microseconds */
00079     int getLatency();
00080     
00081 protected:
00082     pa_simple * connection;
00083     
00084 };
00085 
00086 #endif

Generated on Fri Sep 24 2010 15:52:59 for FCam by  doxygen 1.7.1