00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "common.h"
00024 #include "GStreamerSource.h"
00025
00026
00027 #ifdef MARSYAS_GSTREAMER
00028 #include "gst-decode.h"
00029 #endif //MARSYAS_GSTREAMER
00030
00031 using std::ostringstream;
00032 using namespace Marsyas;
00033
00034 GStreamerSource::GStreamerSource(mrs_string name):AbsSoundFileSource("GStreamerSource", name)
00035 {
00036 data_ = NULL;
00037 phaseOffset_ = 0.0;
00038 hasData_ = false;
00039 addControls();
00040 }
00041
00042
00043
00044 GStreamerSource::~GStreamerSource()
00045 {
00046 delete data_;
00047 }
00048
00049 MarSystem* GStreamerSource::clone() const
00050 {
00051 return new GStreamerSource(*this);
00052 }
00053
00054 void
00055 GStreamerSource::addControls()
00056 {
00057 addctrl("mrs_natural/nChannels",2);
00058 addctrl("mrs_real/frequency",44100.0);
00059 setctrlState("mrs_real/frequency",true);
00060 addctrl("mrs_natural/size", 0);
00061 addctrl("mrs_natural/pos", 0);
00062 setctrlState("mrs_natural/pos", true);
00063 addctrl("mrs_string/filename", "gst-source");
00064 setctrlState("mrs_string/filename", true);
00065 addctrl("mrs_bool/hasData", true);
00066 addctrl("mrs_bool/noteon", false);
00067 setctrlState("mrs_bool/noteon", true);
00068 addctrl("mrs_string/filetype", "raw");
00069 }
00070 void GStreamerSource::getHeader(mrs_string fileName)
00071 {
00072 #ifdef MARSYAS_GSTREAMER
00073 audioVector result = gst_decode_file((gchar*)fileName.c_str());
00074
00075 data_ = (mrs_real*)result.data;
00076 fileSize_ = (mrs_natural)result.size;
00077 if (fileSize_ > 0) {
00078 hasData_ = false;
00079 }
00080 sampleCount_ = fileSize_ / sizeof(mrs_natural);
00081 #endif
00082 }
00083
00084 void GStreamerSource::myUpdate(MarControlPtr sender)
00085 {
00086 (void) sender;
00087
00088
00089 inSamples_ = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00090 inObservations_ = getctrl("mrs_natural/inObservations")->to<mrs_natural>();
00091 israte_ = getctrl("mrs_real/israte")->to<mrs_real>();
00092
00093 setctrl("mrs_natural/onSamples", inSamples_);
00094 setctrl("mrs_natural/onObservations", inObservations_);
00095 setctrl("mrs_real/osrate", israte_);
00096
00097 filename_ = getctrl("mrs_string/filename")->to<mrs_string>();
00098 pos_ = getctrl("mrs_natural/pos")->to<mrs_natural>();
00099
00100 rate_ = fileSize_ * getctrl("mrs_real/frequency")->to<mrs_real>() / israte_;
00101 }
00102
00103
00104 void GStreamerSource::myProcess(realvec& in,realvec &out)
00105 {
00106 MRSMSG("Retrieving data from GStreamerSource\n");
00107 (void) in;
00108
00109 mrs_natural i;
00110 mrs_natural index = pos_;
00111
00112 if (!getctrl("mrs_bool/noteon")->isTrue()) {
00113 return;
00114 }
00115
00116 if (!hasData_) {
00117 return;
00118 }
00119
00120 for (i = 0; i < inSamples_; ++i ) {
00121
00122 if (index >= sampleCount_) {
00123 out(0,i) = 0.0;
00124 } else {
00125 out(0,i) = data_[index++];
00126 }
00127 }
00128 }