1 /* SpiralSynth
2 * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "Delay.h"
20
21 static const int DELAYBUFFERSIZE=SpiralInfo::SAMPLERATE;
22
23
Delay()24 Delay::Delay() :
25 m_Write(0),
26 m_Delay(0.5),
27 m_Feedback(0.5)
28 {
29 m_Buffer = new short[DELAYBUFFERSIZE];
30 }
31
~Delay()32 Delay::~Delay()
33 {
34 delete[] m_Buffer;
35 }
36
GetOutput(short * data)37 void Delay::GetOutput(short *data)
38 {
39 int n=0;
40 long Length=static_cast<long>(m_Delay*DELAYBUFFERSIZE);
41 long temp=0;
42
43 while (n<SpiralInfo::BUFSIZE)
44 {
45 temp=static_cast<long>(data[n]+m_Buffer[m_Write]*m_Feedback);
46
47 if (temp>SpiralInfo::MAXSAMPLE) temp=SpiralInfo::MAXSAMPLE;
48 if (temp<-SpiralInfo::MAXSAMPLE) temp=-SpiralInfo::MAXSAMPLE;
49
50 m_Buffer[m_Write]=static_cast<short>(temp);
51
52 data[n]=m_Buffer[m_Write];
53
54 n++;
55 m_Write++;
56 if (m_Write>Length) m_Write=0;
57 }
58 }
59
Randomise()60 void Delay::Randomise()
61 {
62 m_Delay=RandFloat();
63 m_Feedback=RandFloat();
64 }
65
66
67 istream &operator>>(istream &s, Delay &o)
68 {
69 s>>o.m_Delay>>o.m_Feedback;
70 return s;
71 }
72
73 ostream &operator<<(ostream &s, Delay &o)
74 {
75 s<<o.m_Delay<<" "<<o.m_Feedback<<" ";
76 return s;
77 }
78