CLAM-Development  1.4.0
AudioBufferSink.cxx
Go to the documentation of this file.
1 #include "AudioBufferSink.hxx"
2 #include "ProcessingFactory.hxx"
3 #include "Audio.hxx"
4 
5 #include <iostream>
6 
7 namespace CLAM
8 {
9 
10 namespace
11 {
12  static const char* metadata[] = {
13  "key", "AudioBufferSink",
14  "category", "Audio I/O",
15  "description", "AudioBufferSink",
16  "port_sink_type", typeid(Audio).name(),
17  "icon", "sink.svg",
18  "embedded_svg", "sink.svg",
19  0
20  };
21  static FactoryRegistrator<ProcessingFactory, AudioBufferSink> reg = metadata;
22 }
23 
25 {
26  for (Ports::iterator it = _ports.begin(); it != _ports.end(); ++it)
27  {
28  Port& port = (*it);
29  InPort<Audio>* in = port.mPort;
30 
31  const CLAM::Audio& so=in->GetData();
32 
33  CLAM_DEBUG_ASSERT(port.mFloatBuffer, "No float buffer");
34  CLAM_DEBUG_ASSERT(!port.mDoubleBuffer, "There should not be double buffer");
35  CLAM_DEBUG_ASSERT(so.GetSize()>0, "internal buffer size must be greater than 0");
36  const CLAM::TData * audioBuffer = so.GetBuffer().GetPtr();
37 
38  for (unsigned i=0; i<so.GetSize(); i++)
39  port.mFloatBuffer[i] = audioBuffer[i];
40 
41  in->Consume();
42  }
43 
44  return true;
45 }
46 
47 void AudioBufferSink::SetExternalBuffer(float* buf, unsigned nframes, unsigned index)
48 {
49  CLAM_ASSERT(index < _ports.size(), "InPort<Audio> index out of range");
50  Port& port = _ports[index];
51  port.mPort->SetSize(1);
52  port.mPort->SetHop(1);
53  port.mFloatBuffer = buf;
54  port.mBufferSize = nframes;
55  port.mDoubleBuffer = 0;
56 
57 }
58 
59 void AudioBufferSink::SetExternalBuffer(double* buf, unsigned nframes, unsigned index)
60 {
61  CLAM_ASSERT(index < _ports.size(), "InPort<Audio> index out of range");
62  Port& port = _ports[index];
63  port.mPort->SetSize(1);
64  port.mPort->SetHop(1);
65  port.mDoubleBuffer = buf;
66  port.mBufferSize = nframes;
67  port.mFloatBuffer = 0;
68 }
69 
70 } //namespace CLAM
71