~ubuntu-branches/ubuntu/vivid/soundscaperenderer/vivid

« back to all changes in this revision

Viewing changes to apf/examples/jack_dynamic_inputs.cpp

  • Committer: Package Import Robot
  • Author(s): IOhannes m zmölnig (Debian/GNU)
  • Date: 2014-05-08 16:58:09 UTC
  • Revision ID: package-import@ubuntu.com-20140508165809-7tz9dhu5pvo5wy25
Tags: upstream-0.4.1~dfsg
Import upstream version 0.4.1~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * Copyright © 2012-2014 Institut für Nachrichtentechnik, Universität Rostock *
 
3
 * Copyright © 2006-2012 Quality & Usability Lab,                             *
 
4
 *                       Telekom Innovation Laboratories, TU Berlin           *
 
5
 *                                                                            *
 
6
 * This file is part of the Audio Processing Framework (APF).                 *
 
7
 *                                                                            *
 
8
 * The APF is free software:  you can redistribute it and/or modify it  under *
 
9
 * the terms of the  GNU  General  Public  License  as published by the  Free *
 
10
 * Software Foundation, either version 3 of the License,  or (at your option) *
 
11
 * any later version.                                                         *
 
12
 *                                                                            *
 
13
 * The APF is distributed in the hope that it will be useful, but WITHOUT ANY *
 
14
 * WARRANTY;  without even the implied warranty of MERCHANTABILITY or FITNESS *
 
15
 * FOR A PARTICULAR PURPOSE.                                                  *
 
16
 * See the GNU General Public License for more details.                       *
 
17
 *                                                                            *
 
18
 * You should  have received a copy  of the GNU General Public License  along *
 
19
 * with this program.  If not, see <http://www.gnu.org/licenses/>.            *
 
20
 *                                                                            *
 
21
 *                                 http://AudioProcessingFramework.github.com *
 
22
 ******************************************************************************/
 
23
 
 
24
// A small example of the MimoProcessor with varying JACK input ports.
 
25
// This is a stand-alone program.
 
26
 
 
27
#include "apf/mimoprocessor.h"
 
28
#include "apf/combine_channels.h"  // for apf::CombineChannels
 
29
#include "apf/jack_policy.h"
 
30
#include "apf/posix_thread_policy.h"
 
31
 
 
32
class MyProcessor : public apf::MimoProcessor<MyProcessor
 
33
                    , apf::jack_policy
 
34
                    , apf::posix_thread_policy>
 
35
{
 
36
  public:
 
37
    using Input = MimoProcessorBase::DefaultInput;
 
38
 
 
39
    class Output : public MimoProcessorBase::DefaultOutput
 
40
    {
 
41
      public:
 
42
        explicit Output(const Params& p)
 
43
          : MimoProcessorBase::DefaultOutput(p)
 
44
          , _combiner(this->parent.get_input_list(), *this)
 
45
        {}
 
46
 
 
47
        APF_PROCESS(Output, MimoProcessorBase::DefaultOutput)
 
48
        {
 
49
          float weight = 1.0f/static_cast<float>(
 
50
              this->parent.get_input_list().size());
 
51
          _combiner.process(simple_predicate(weight));
 
52
        }
 
53
 
 
54
      private:
 
55
        class simple_predicate
 
56
        {
 
57
          public:
 
58
            explicit simple_predicate(float weight) : _weight(weight) {}
 
59
 
 
60
            // trivial, all inputs are used; no crossfade/interpolation
 
61
            apf::CombineChannelsResult::type select(const Input&)
 
62
            {
 
63
              return apf::CombineChannelsResult::constant;
 
64
            }
 
65
 
 
66
            float operator()(float in) { return in * _weight; }
 
67
 
 
68
          private:
 
69
            float _weight;
 
70
        };
 
71
 
 
72
        apf::CombineChannels<rtlist_proxy<Input>, Output> _combiner;
 
73
    };
 
74
 
 
75
    MyProcessor()
 
76
    {
 
77
      this->add<Output>();
 
78
    }
 
79
};
 
80
 
 
81
int main()
 
82
{
 
83
  int in_channels = 20;
 
84
 
 
85
  MyProcessor engine;
 
86
  engine.activate();
 
87
 
 
88
  sleep(2);
 
89
 
 
90
  std::vector<MyProcessor::Input*> inputs;
 
91
 
 
92
  for (int i = 1; i <= in_channels; ++i)
 
93
  {
 
94
    MyProcessor::Input::Params p;
 
95
    p.set("id", i * 10);
 
96
    inputs.push_back(engine.add(p));
 
97
    sleep(1);
 
98
  }
 
99
 
 
100
  sleep(2);
 
101
 
 
102
  // remove the inputs one by one ...
 
103
  while (inputs.begin() != inputs.end())
 
104
  {
 
105
    engine.rem(inputs.front());
 
106
    engine.wait_for_rt_thread();
 
107
    inputs.erase(inputs.begin());
 
108
    sleep(1);
 
109
  }
 
110
 
 
111
  sleep(2);
 
112
 
 
113
  engine.deactivate();
 
114
}
 
115
 
 
116
// Settings for Vim (http://www.vim.org/), please do not remove:
 
117
// vim:softtabstop=2:shiftwidth=2:expandtab:textwidth=80:cindent