Mercurial > hg > jslab
comparison src/samer/units/Wavetable.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.units; | |
11 import samer.core.*; | |
12 import samer.maths.*; | |
13 import samer.maths.random.*; | |
14 | |
15 /** | |
16 Periodic generator: generates periodic signal from | |
17 a wave table | |
18 */ | |
19 | |
20 public class Wavetable implements Generator | |
21 { | |
22 int start, end, j; | |
23 Vec vec; | |
24 double [] pp; | |
25 | |
26 public Wavetable(Vec vec) { | |
27 this(vec,0,vec.size()); | |
28 } | |
29 | |
30 public Wavetable(Vec vec, int start, int end) | |
31 { | |
32 this.vec = vec; | |
33 this.start = start; | |
34 this.end = end; | |
35 pp = vec.array(); | |
36 j = start; | |
37 } | |
38 | |
39 public int period() { return end-start; } | |
40 public void dispose() {} | |
41 public double next() | |
42 { | |
43 double r=pp[j++]; | |
44 if (j>=end) j=start; | |
45 return r; | |
46 } | |
47 | |
48 public void next(double [] x) | |
49 { | |
50 int remaining=x.length; | |
51 int iput=0; | |
52 | |
53 while (remaining>0) { | |
54 int avail = end-j; | |
55 int block = remaining > avail ? avail : remaining; | |
56 | |
57 System.arraycopy( pp, j, x,iput, block); | |
58 j+=block; iput+=block; remaining-=block; | |
59 if (j>=end) j=start; | |
60 } | |
61 } | |
62 | |
63 public String toString() { return "wavetable"; } | |
64 } | |
65 | |
66 |