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     //std::cout << "AudioBufferSink::SetExternalBuffer using float" << std::endl;
00050         CLAM_ASSERT(index < _ports.size(), "InPort<Audio> index out of range");
00051         Port& port = _ports[index];
00052         port.mPort->SetSize(1);
00053         port.mPort->SetHop(1);
00054         port.mFloatBuffer = buf;
00055         port.mBufferSize = nframes;
00056         port.mDoubleBuffer = 0;
00057 
00058 }
00059 
00060 void AudioBufferSink::SetExternalBuffer(double* buf, unsigned nframes, unsigned index)
00061 {
00062     //std::cout << "AudioBufferSink::SetExternalBuffer using double" << std::endl;
00063         CLAM_ASSERT(index < _ports.size(), "InPort<Audio> index out of range");
00064         Port& port = _ports[index];
00065         port.mPort->SetSize(1);
00066         port.mPort->SetHop(1);
00067         port.mDoubleBuffer = buf;
00068         port.mBufferSize = nframes;
00069         port.mFloatBuffer = 0;
00070 }
00071 
00072 } //namespace CLAM
00073 
Generated by  doxygen 1.6.3