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