AudioSource.cxx
Go to the documentation of this file.00001 #include "AudioSource.hxx"
00002 #include "ProcessingFactory.hxx"
00003 #include "Audio.hxx"
00004
00005 namespace CLAM
00006 {
00007
00008 namespace
00009 {
00010 static const char* metadata[] = {
00011 "key", "AudioSource",
00012 "category", "Audio I/O",
00013 "description", "AudioSource",
00014 "port_source_type", typeid(float).name(),
00015 "icon", "source.svg",
00016 "embedded_svg", "source.svg",
00017 0
00018 };
00019 static FactoryRegistrator<ProcessingFactory, AudioSource> reg = metadata;
00020 }
00021
00022 AudioSource::Config::~Config() { }
00023
00024 bool AudioSource::Do()
00025 {
00026 for (Ports::iterator it = _ports.begin(); it != _ports.end(); ++it)
00027 {
00028 Port& port = (*it);
00029 AudioOutPort* out = port.mPort;
00030
00031 CLAM::Audio& so=out->GetAudio();
00032 CLAM_DEBUG_ASSERT(!port.mFloatBuffer || !port.mDoubleBuffer, "AudioSource: Just one buffer should be set");
00033 CLAM_DEBUG_ASSERT(port.mFloatBuffer || port.mDoubleBuffer, "AudioSource: No external buffer set");
00034 CLAM_DEBUG_ASSERT(port.mBufferSize>0, "AudioSource: internal buffer size must be greater than 0");
00035 CLAM::TData * audioBuffer = so.GetBuffer().GetPtr();
00036
00037 if (port.mFloatBuffer)
00038 for (unsigned i=0; i<port.mBufferSize; i++)
00039 audioBuffer[i] = port.mFloatBuffer[i];
00040 else
00041 for (unsigned i=0; i<port.mBufferSize; i++)
00042 audioBuffer[i] = port.mDoubleBuffer[i];
00043
00044 for (int i=port.mBufferSize; i<out->GetSize(); i++)
00045 audioBuffer[i] = 0.;
00046
00047 out->Produce();
00048 }
00049 return true;
00050 }
00051
00052 void AudioSource::SetExternalBuffer(const float* buf, unsigned nframes, unsigned index)
00053 {
00054 CLAM_ASSERT(index < _ports.size(), "AudioOutPort index out of range");
00055 Port& port = _ports[index];
00056 port.mPort->SetSize(nframes);
00057 port.mPort->SetHop(nframes);
00058 port.mFloatBuffer = buf;
00059 port.mBufferSize = nframes;
00060 port.mDoubleBuffer = 0;
00061 }
00062
00063 void AudioSource::SetExternalBuffer(const double* buf, unsigned nframes, unsigned index)
00064 {
00065 CLAM_ASSERT(index < _ports.size(), "AudioOutPort index out of range");
00066 Port& port = _ports[index];
00067 port.mPort->SetSize(nframes);
00068 port.mPort->SetHop(nframes);
00069 port.mDoubleBuffer = buf;
00070 port.mBufferSize = nframes;
00071 port.mFloatBuffer = 0;
00072 }
00073
00074 }
00075