Libraryless. Click here for Pure Java version (5980L/34K).
1 | sclass AudioSampleOps {
|
2 | // implementation of gain modifier |
3 | srecord noeq Gain(double factor, IAudioSample original) implements IAudioSample {
|
4 | public double sampleRate() { ret original.sampleRate(); }
|
5 | public int channels() { ret original.channels(); }
|
6 | public DoubleRange bounds() { ret original.bounds(); }
|
7 | |
8 | public double sampleSum(int channel, double start, double end) {
|
9 | ret original.sampleSum(channel, start, end)*factor; |
10 | } |
11 | |
12 | // coalesce consecutive gains |
13 | public IAudioSample gain(double factor) {
|
14 | ret original.gain(this.factor*factor); |
15 | } |
16 | } |
17 | |
18 | // Implementation of the time-shift modifier. |
19 | // moves the input <shift> samples to the left (cuts off beginning). |
20 | // Shift can be fractional - we're in integral image (audio) wonderland after all |
21 | // where a traditional pixel has no meaning. |
22 | srecord noeq TimeShift(double shift, IAudioSample original) implements IAudioSample {
|
23 | public double sampleRate() { ret original.sampleRate(); }
|
24 | public int channels() { ret original.channels(); }
|
25 | public DoubleRange bounds() { ret shiftDoubleRange(original.bounds(), -shift); }
|
26 | |
27 | public double sampleSum(int channel, double start, double end) {
|
28 | ret original.sampleSum(channel, start+shift, end+shift); |
29 | } |
30 | |
31 | // coalesce consecutive time-shifts |
32 | public IAudioSample timeShift(double shift) {
|
33 | ret original.timeShift(this.shift+shift); |
34 | } |
35 | } |
36 | |
37 | // Implementation of the speed-up modifier which transforms every frequency f to f*factor. |
38 | // This is for convenience, you could also just call sampleSum() directly with larger intervals. |
39 | sclass SpeedUp implements IAudioSample {
|
40 | double factor, invFactor; |
41 | IAudioSample original; |
42 | |
43 | *(double *factor, IAudioSample *original) {
|
44 | if (factor < 1) fail("Can't slow down. " + factor);
|
45 | invFactor = 1/factor; |
46 | } |
47 | |
48 | public double sampleRate() { ret original.sampleRate()*invFactor; }
|
49 | public int channels() { ret original.channels(); }
|
50 | public DoubleRange bounds() { ret scaleDoubleRange(original.bounds(), invFactor); }
|
51 | |
52 | public double sampleSum(int channel, double start, double end) {
|
53 | ret original.sampleSum(channel, start*factor, end*factor)*invFactor; |
54 | } |
55 | |
56 | // coalesce consecutive speed-ups |
57 | public IAudioSample speedUp(double factor) {
|
58 | ret original.speedUp(this.factor*factor); |
59 | } |
60 | } |
61 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1032975 |
| Snippet name: | AudioSampleOps |
| Eternal ID of this version: | #1032975/2 |
| Text MD5: | 155297c21bbe2d864eee8dcdb814f6cf |
| Transpilation MD5: | 4ea72373e6f0221933796bd6d40f5ebf |
| Author: | stefan |
| Category: | javax / stefan's os |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-10-11 07:30:56 |
| Source code size: | 2456 bytes / 61 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 466 / 691 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |