AudioSink.cxx

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