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

« back to all changes in this revision

Viewing changes to libecasound/osc-sine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2008-09-26 09:58:52 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080926095852-k3v9ewhmxpaltusw
Tags: 2.5.2-3
yodl 2.13.1 removed --unique-output option. Remove --unique-output
accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// osc-sine.cpp: Sine oscillator
3
 
// Copyright (C) 1999,2001 Kai Vehmanen
 
3
// Copyright (C) 1999,2001,2008 Kai Vehmanen
 
4
//
 
5
// Attributes:
 
6
//     eca-style-version: 3 (see Ecasound Programmer's Guide)
4
7
//
5
8
// This program is fre software; you can redistribute it and/or modify
6
9
// it under the terms of the GNU General Public License as published by
26
29
#include "osc-sine.h"
27
30
#include "eca-logger.h"
28
31
 
29
 
CONTROLLER_SOURCE::parameter_t SINE_OSCILLATOR::value(void)
 
32
CONTROLLER_SOURCE::parameter_t SINE_OSCILLATOR::value(double pos_secs)
30
33
{
31
 
  curval = (sin(phase) + 1.0) / 2.0;
32
 
  phase += phasemod * (position_in_seconds_exact() - last_global_pos_rep);
33
 
  last_global_pos_rep = position_in_seconds_exact();
34
 
  return(curval);
 
34
  parameter_t retval, phase;
 
35
 
 
36
  phase = 2.0 * M_PI * (pos_secs / period_len_rep);
 
37
  retval = sin(phase + phase_offset());
 
38
 
 
39
  /* note: scale return value to proper [0,1] range */
 
40
  retval += 1.0;
 
41
  retval /= 2.0;
 
42
 
 
43
  return retval;
35
44
}
36
45
 
37
46
SINE_OSCILLATOR::SINE_OSCILLATOR (double freq, double initial_phase) :
38
 
  OSCILLATOR(freq, initial_phase) {
39
 
 
40
 
  last_global_pos_rep = 0.0f;
41
 
 
 
47
  OSCILLATOR(freq, initial_phase)
 
48
{
42
49
  set_parameter(1, get_parameter(1));
43
50
  set_parameter(2, get_parameter(2));
44
51
}
46
53
void SINE_OSCILLATOR::init(void)
47
54
{
48
55
  MESSAGE_ITEM otemp;
49
 
  otemp << "(osc-sine) Sine oscillator created; frequency ";
 
56
  otemp << "Sine oscillator created; frequency ";
50
57
  otemp.setprecision(3);
51
58
  otemp << frequency();
52
59
  otemp << " and initial phase of "; 
59
66
  switch (param) {
60
67
  case 1: 
61
68
    frequency(v);
62
 
    L = 1.0 / frequency();   // length of one wave in seconds
63
 
    phasemod = 2.0 * M_PI / L; 
 
69
    /* note: cache length of one period in seconds */
 
70
    if (v > 0)
 
71
      period_len_rep = 1.0 / frequency();
 
72
    else
 
73
      period_len_rep = 0;
64
74
    break;
65
75
 
66
76
  case 2: 
67
77
    phase_offset(static_cast<double>(v * M_PI));
68
 
    phase = phase_offset();
69
78
    break;
70
79
  }
71
80
}
74
83
{
75
84
  switch (param) {
76
85
  case 1: 
77
 
    return(frequency());
 
86
    return frequency();
78
87
  case 2: 
79
 
    return(phase_offset() / M_PI);
 
88
    return phase_offset() / M_PI;
80
89
  }
81
90
  return(0.0);
82
91
}