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