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