3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
28 #include "generator.h"
38 int generator_play(struct generator
* g
, int * lwave
, int * rwave
,
39 int size
, double inc
, int loop_start
, int loop_end
,
40 double lvol
, double rvol
, int sustain
)
42 if(g
->mode
!= GEN_MODE_FREE
) return(0);
44 g
->mode
=GEN_MODE_PLAYING
;
48 g
->loop_start
=(double) loop_start
;
49 g
->loop_end
=(double) loop_end
;
61 int generator_release(struct generator
* g
)
63 /* if free or already released, fail */
64 if(g
->mode
== GEN_MODE_FREE
||
65 g
->mode
== GEN_MODE_RELEASED
)
68 /* if stopped or no sustain, become free immediately */
69 if(g
->mode
== GEN_MODE_STOPPED
|| g
->sustain
== 0)
71 g
->mode
=GEN_MODE_FREE
;
75 /* generator is released */
76 g
->mode
=GEN_MODE_RELEASED
;
78 /* calculates delta volume values */
79 g
->dlvol
=g
->lvol
/ (double) g
->sustain
;
80 g
->drvol
=g
->rvol
/ (double) g
->sustain
;
82 /* put generator in auto-stop */
83 /* g->loop_start=-1; */
84 g
->loop_end
=(double) g
->size
;
90 void generator(struct generator
* g
, int * left
, int * right
)
94 /* return if generator is not active */
95 if(g
->mode
==GEN_MODE_STOPPED
|| g
->mode
==GEN_MODE_FREE
)
99 l
=get_sample(g
->lwave
, g
->loop_end
, g
->cursor
);
100 r
=get_sample(g
->rwave
, g
->loop_end
, g
->cursor
);
102 /* increment pointer */
105 /* test boundaries */
106 if(g
->cursor
> g
->loop_end
)
109 if(g
->loop_start
== -1)
110 g
->mode
=GEN_MODE_STOPPED
;
112 g
->cursor
=g
->loop_start
;
115 l
=(int)((double)l
* g
->lvol
);
116 r
=(int)((double)r
* g
->rvol
);
118 if(g
->mode
== GEN_MODE_RELEASED
&& g
->sustain
!= -1)
124 if(--g
->sustain
== 0)
125 g
->mode
=GEN_MODE_FREE
;
130 if(--g
->portamento
== 0)
141 int generator_portamento(struct generator
* g
, int portamento
,
144 /* generator must be playing */
145 if(g
->mode
!= GEN_MODE_PLAYING
)
148 g
->portamento
=portamento
;
149 g
->dest_inc
=dest_inc
;
150 g
->dinc
=((dest_inc
- g
->inc
) / (double) portamento
);