Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/slmml/Oscillator.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations) (download)
Sat May 23 15:29:19 2009 UTC (14 years, 9 months ago) by hikarin
File size: 5992 byte(s)
[ocmml/slmml] * added NDoc-styled comments more
1 /*
2 Copyright (c) 2009, hkrn All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer. Redistributions in binary
9 form must reproduce the above copyright notice, this list of conditions and
10 the following disclaimer in the documentation and/or other materials
11 provided with the distribution. Neither the name of the hkrn nor
12 the names of its contributors may be used to endorse or promote products
13 derived from this software without specific prior written permission.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
19 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25 DAMAGE.
26 */
27
28 //
29 // $Id$
30 //
31
32 using System;
33 using SlMML.Modulators;
34
35 namespace SlMML
36 {
37 public enum OscillatorForm
38 {
39 Sine,
40 Saw,
41 Triangle,
42 Pulse,
43 Noise,
44 FCPulse,
45 FCTriangle,
46 FCNoise,
47 FCShortNoise,
48 FCDPCM,
49 GBWave,
50 GBLongNoise,
51 GBShortNoise,
52 Max
53 }
54
55 /// <summary>
56 /// ���������������������������������������������������������������������������������
57 /// </summary>
58 public class Oscillator
59 {
60 #region ���������������������������������������������������������
61 public Oscillator()
62 {
63 m_modulators = new IModulator[(int)OscillatorForm.Max];
64 m_modulators[(int)OscillatorForm.Sine] = new Sine();
65 m_modulators[(int)OscillatorForm.Saw] = new Saw();
66 m_modulators[(int)OscillatorForm.Triangle] = new Triangle();
67 m_modulators[(int)OscillatorForm.Pulse] = new Pulse();
68 m_modulators[(int)OscillatorForm.Noise] = new Noise();
69 m_modulators[(int)OscillatorForm.FCPulse] = new Pulse();
70 m_modulators[(int)OscillatorForm.FCTriangle] = new FCTriangle();
71 m_modulators[(int)OscillatorForm.FCNoise] = new FCNoise();
72 m_modulators[(int)OscillatorForm.FCShortNoise] = new FCNoise();
73 m_modulators[(int)OscillatorForm.FCDPCM] = new FCDPCM();
74 m_modulators[(int)OscillatorForm.GBWave] = new GBWave();
75 m_modulators[(int)OscillatorForm.GBLongNoise] = new GBLongNoise();
76 m_modulators[(int)OscillatorForm.GBShortNoise] = new GBShortNoise();
77 Form = OscillatorForm.Pulse;
78 }
79 #endregion
80
81 #region ���������������������������
82 /// <summary>
83 /// ������������������������������������������������������������������������������������������
84 /// </summary>
85 /// <param name="form"></param>
86 /// <returns></returns>
87 public IModulator ModulatorFromForm(OscillatorForm form)
88 {
89 int index = Math.Min(Math.Max((int)form, 0), (int)(OscillatorForm.Max - 1));
90 return m_modulators[index];
91 }
92
93 /// <summary>
94 /// ������������������������������LFO���������������������������������������������
95 /// </summary>
96 public void MakeAsLFO()
97 {
98 if (m_modulators[(int)OscillatorForm.Noise] != null)
99 {
100 Noise noise = (Noise)m_modulators[(int)OscillatorForm.Noise];
101 noise.ShouldResetPhase = false;
102 }
103 }
104 #endregion
105
106 #region ������������������������������
107 /// <summary>
108 /// ���������������������������������������������
109 /// </summary>
110 public OscillatorForm Form
111 {
112 set
113 {
114 int index = Math.Min(Math.Max((int)value, 0), (int)(OscillatorForm.Max - 1));
115 m_form = (OscillatorForm)index;
116 switch (m_form)
117 {
118 case OscillatorForm.Noise:
119 Noise noise = (Noise)m_modulators[(int)OscillatorForm.Noise];
120 noise.RestoreFrequency();
121 break;
122 case OscillatorForm.FCNoise:
123 FCNoise fcNoise = (FCNoise)m_modulators[(int)OscillatorForm.FCNoise];
124 fcNoise.SetLongMode();
125 break;
126 case OscillatorForm.FCShortNoise:
127 FCNoise fcShortNoise = (FCNoise)m_modulators[(int)OscillatorForm.FCShortNoise];
128 fcShortNoise.SetShortMode();
129 break;
130 default:
131 break;
132 }
133 }
134 get
135 {
136 return m_form;
137 }
138 }
139
140 /// <summary>
141 /// ���������������������������������������������������������������������������������������������������
142 /// </summary>
143 public IModulator CurrentModulator
144 {
145 get
146 {
147 return m_modulators[(int)Form];
148 }
149 }
150 #endregion
151
152 #region ���������������������������
153 IModulator[] m_modulators;
154 OscillatorForm m_form;
155 #endregion
156 }
157 }

Properties

Name Value
svn:keywords Id

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26