~ubuntu-branches/ubuntu/lucid/ecasound2.2/lucid

« back to all changes in this revision

Viewing changes to libecasound/audiofx_mixing.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2009-11-02 18:22:35 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091102182235-4ngh7699dmkgonyu
Tags: 2.7.0-1
* New upstream release.
* Depend on libreadline-dev instead of libreadline5-dev by request of
  Mattias Klose. It's now libreadline6-dev. (closes: #553748)
* Update menu file to use section Applications/ instead of Apps/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// audiofx_mixing.cpp: Effects for channel mixing and routing
3
 
// Copyright (C) 1999-2002,2006,2008 Kai Vehmanen
 
3
// Copyright (C) 1999-2002,2006,2008,2009 Kai Vehmanen
4
4
//
5
5
// Attributes:
6
6
//     eca-style-version: 3 (see Ecasound Programmer's Guide)
21
21
// ------------------------------------------------------------------------
22
22
 
23
23
#include <kvu_dbc.h>
 
24
#include <kvu_numtostr.h>
24
25
 
25
26
#include "samplebuffer_iterators.h"
26
27
#include "audiofx_mixing.h"
312
313
    t_iter.next();
313
314
  }
314
315
}
 
316
 
 
317
EFFECT_CHANNEL_ORDER::EFFECT_CHANNEL_ORDER (void)
 
318
  : sbuf_repp(0), 
 
319
    out_channels_rep(0)
 
320
{
 
321
}
 
322
 
 
323
EFFECT_CHANNEL_ORDER* EFFECT_CHANNEL_ORDER::clone(void) const
 
324
{
 
325
  EFFECT_CHANNEL_ORDER *obj =
 
326
    new EFFECT_CHANNEL_ORDER();
 
327
  /* note: obj->sbuf_repp is shared but this is ok */
 
328
  return obj;
 
329
}
 
330
 
 
331
int EFFECT_CHANNEL_ORDER::output_channels(int i_channels) const
 
332
{
 
333
  return out_channels_rep;
 
334
}
 
335
 
 
336
void EFFECT_CHANNEL_ORDER::parameter_description(int param, struct PARAM_DESCRIPTION *pd) const
 
337
{
 
338
  /* these apply for all params */
 
339
  pd->default_value = 1;
 
340
  pd->description = "channel";
 
341
  pd->bounded_above = false;
 
342
  pd->upper_bound = 0.0f;
 
343
  pd->bounded_below = true;
 
344
  pd->lower_bound = 1.0f;
 
345
  pd->toggled = false;
 
346
  pd->integer = true;
 
347
  pd->logarithmic = false;
 
348
  pd->output = false;
 
349
}
 
350
 
 
351
void EFFECT_CHANNEL_ORDER::set_parameter(int param, CHAIN_OPERATOR::parameter_t value)
 
352
{
 
353
  int src_ch = static_cast<int>(value);
 
354
  int dst_ch = param;
 
355
 
 
356
  if (dst_ch > 0) {
 
357
    if (dst_ch > static_cast<int>(chsrc_map_rep.size())) {
 
358
      chsrc_map_rep.resize(dst_ch);
 
359
    }
 
360
 
 
361
    chsrc_map_rep[dst_ch - 1] = src_ch - 1;
 
362
 
 
363
    /* step: reset highest non-zero channel */
 
364
    int n;
 
365
    for(n = chsrc_map_rep.size() - 1;
 
366
        n >= 0; n--) {
 
367
      if (chsrc_map_rep[n] >= 0) 
 
368
        break;
 
369
    }
 
370
    out_channels_rep = n + 1;
 
371
  }
 
372
}
 
373
 
 
374
CHAIN_OPERATOR::parameter_t EFFECT_CHANNEL_ORDER::get_parameter(int param) const
 
375
{
 
376
 
 
377
  /* note: we ignore zero-src channel at the end of
 
378
   *       chsrc_map_rep to avoid infinite loops in
 
379
   *       e.g. ECA_OBJECT_FACTORY */
 
380
  if (param > 0 &&
 
381
      param <= out_channels_rep) {
 
382
    
 
383
    DBC_CHECK(out_channels_rep <= static_cast<int>(chsrc_map_rep.size()));
 
384
 
 
385
    /* return 1...N */
 
386
    return chsrc_map_rep[param - 1] + 1;
 
387
  }
 
388
 
 
389
  return 0.0;
 
390
}
 
391
 
 
392
std::string EFFECT_CHANNEL_ORDER::parameter_names(void) const 
 
393
{
 
394
  std::string params;
 
395
  int ch = 0;
 
396
  while(ch < out_channels_rep) {
 
397
    params += "src-ch-" + kvu_numtostr(ch + 1);
 
398
    ++ch;
 
399
    if (ch != out_channels_rep)
 
400
      params += ",";
 
401
  }
 
402
  return params;
 
403
  //return param_names_rep;
 
404
}
 
405
 
 
406
void EFFECT_CHANNEL_ORDER::init(SAMPLE_BUFFER *insample)
 
407
{
 
408
  sbuf_repp = insample;
 
409
  bouncebuf_rep.number_of_channels(sbuf_repp->number_of_channels());
 
410
  bouncebuf_rep.length_in_samples(sbuf_repp->length_in_samples());
 
411
 
 
412
  f_iter.init(&bouncebuf_rep);
 
413
  t_iter.init(insample);
 
414
}
 
415
 
 
416
void EFFECT_CHANNEL_ORDER::release(void)
 
417
{
 
418
  sbuf_repp = 0;
 
419
}
 
420
 
 
421
void EFFECT_CHANNEL_ORDER::process(void)
 
422
{
 
423
  /* step: copy input buffer to a temporary buffer */
 
424
  bouncebuf_rep.copy_all_content(*sbuf_repp);
 
425
 
 
426
  /* step: route channels bouncebuf_rep -> sbuf_repp */
 
427
  for(int dst_ch = 0; dst_ch < out_channels_rep; dst_ch++) {
 
428
    int src_ch = chsrc_map_rep[dst_ch];
 
429
 
 
430
    /* for development use only */
 
431
#if 0
 
432
    std::fprintf(stderr, "%sout#%d <-- in#%d (avail in=%d, out=%d)\n",
 
433
                 dst_ch == 0 ? "---\n" : "",
 
434
                 dst_ch, src_ch,
 
435
                 bouncebuf_rep.number_of_channels(),
 
436
                 sbuf_repp->number_of_channels());
 
437
#endif
 
438
 
 
439
    if (src_ch >= 0 && src_ch < bouncebuf_rep.number_of_channels()) {
 
440
      f_iter.begin(src_ch);
 
441
      t_iter.begin(dst_ch);
 
442
      while(!f_iter.end() && !t_iter.end()) {
 
443
        *t_iter.current() = *f_iter.current();
 
444
        f_iter.next();
 
445
        t_iter.next();
 
446
      }
 
447
    }
 
448
    else {
 
449
      sbuf_repp->make_silent(dst_ch);
 
450
    }
 
451
  }
 
452
 
 
453
  /* step: make sure output buf has exactly N channels */
 
454
  sbuf_repp->number_of_channels(out_channels_rep);
 
455
}