1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rubber Band Library
5     An audio time-stretching and pitch-shifting library.
6     Copyright 2007-2014 Particular Programs Ltd.
7 
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 
14     Alternatively, if you have a valid commercial licence for the
15     Rubber Band Library obtained by agreement with the copyright
16     holders, you may redistribute and/or modify it under the terms
17     described in that licence.
18 
19     If you wish to distribute code using the Rubber Band Library
20     under terms other than those of the GNU General Public License,
21     you must obtain a valid commercial licence before doing so.
22 */
23 
24 package com.breakfastquay.rubberband;
25 
26 public class RubberBandStretcher
27 {
28     public RubberBandStretcher(int sampleRate, int channels,
29 			       int options,
30 			       double initialTimeRatio,
31 			       double initialPitchScale) {
32 	handle = 0;
33 	initialise(sampleRate, channels, options,
34 		   initialTimeRatio, initialPitchScale);
35     }
36 
37     public native void dispose();
38 
39     public native void reset();
40 
41     public native void setTimeRatio(double ratio);
42     public native void setPitchScale(double scale);
43 
44     public native int getChannelCount();
45     public native double getTimeRatio();
46     public native double getPitchScale();
47 
48     public native int getLatency();
49 
50     public native void setTransientsOption(int options);
51     public native void setDetectorOption(int options);
52     public native void setPhaseOption(int options);
53     public native void setFormantOption(int options);
54     public native void setPitchOption(int options);
55 
56     public native void setExpectedInputDuration(long samples);
57     public native void setMaxProcessSize(int samples);
58 
59     public native int getSamplesRequired();
60 
61     //!!! todo: setKeyFrameMap
62 
63     public native void study(float[][] input, int offset, int n, boolean finalBlock);
64     public void study(float[][] input, boolean finalBlock) {
65 	study(input, 0, input[0].length, finalBlock);
66     }
67 
68     public native void process(float[][] input, int offset, int n, boolean finalBlock);
69     public void process(float[][] input, boolean finalBlock) {
70 	process(input, 0, input[0].length, finalBlock);
71     }
72 
73     public native int available();
74 
75     public native int retrieve(float[][] output, int offset, int n);
76     public int retrieve(float[][] output) {
77 	return retrieve(output, 0, output[0].length);
78     }
79 
80     private native void initialise(int sampleRate, int channels, int options,
81 				   double initialTimeRatio,
82 				   double initialPitchScale);
83     private long handle;
84 
85     public static final int OptionProcessOffline       = 0x00000000;
86     public static final int OptionProcessRealTime      = 0x00000001;
87 
88     public static final int OptionStretchElastic       = 0x00000000;
89     public static final int OptionStretchPrecise       = 0x00000010;
90 
91     public static final int OptionTransientsCrisp      = 0x00000000;
92     public static final int OptionTransientsMixed      = 0x00000100;
93     public static final int OptionTransientsSmooth     = 0x00000200;
94 
95     public static final int OptionDetectorCompound     = 0x00000000;
96     public static final int OptionDetectorPercussive   = 0x00000400;
97     public static final int OptionDetectorSoft         = 0x00000800;
98 
99     public static final int OptionPhaseLaminar         = 0x00000000;
100     public static final int OptionPhaseIndependent     = 0x00002000;
101 
102     public static final int OptionThreadingAuto        = 0x00000000;
103     public static final int OptionThreadingNever       = 0x00010000;
104     public static final int OptionThreadingAlways      = 0x00020000;
105 
106     public static final int OptionWindowStandard       = 0x00000000;
107     public static final int OptionWindowShort          = 0x00100000;
108     public static final int OptionWindowLong           = 0x00200000;
109 
110     public static final int OptionSmoothingOff         = 0x00000000;
111     public static final int OptionSmoothingOn          = 0x00800000;
112 
113     public static final int OptionFormantShifted       = 0x00000000;
114     public static final int OptionFormantPreserved     = 0x01000000;
115 
116     public static final int OptionPitchHighSpeed       = 0x00000000;
117     public static final int OptionPitchHighQuality     = 0x02000000;
118     public static final int OptionPitchHighConsistency = 0x04000000;
119 
120     public static final int OptionChannelsApart        = 0x00000000;
121     public static final int OptionChannelsTogether     = 0x10000000;
122 
123     public static final int DefaultOptions             = 0x00000000;
124     public static final int PercussiveOptions          = 0x00102000;
125 
126     static {
127 	System.loadLibrary("rubberband-jni");
128     }
129 };
130 
131