Skip to content

Commit 0d10012

Browse files
committed
Merge from default branch
2 parents 888eed2 + f0d702e commit 0d10012

14 files changed

+243
-16
lines changed

com/breakfastquay/rubberband/RubberBandStretcher.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ License, or (at your option) any later version. See the file
2323

2424
package com.breakfastquay.rubberband;
2525

26+
import java.util.Map;
27+
import java.util.Set;
28+
2629
public class RubberBandStretcher
2730
{
2831
public RubberBandStretcher(int sampleRate, int channels,
@@ -45,6 +48,8 @@ public RubberBandStretcher(int sampleRate, int channels,
4548
public native double getTimeRatio();
4649
public native double getPitchScale();
4750

51+
public native int getPreferredStartPad();
52+
public native int getStartDelay();
4853
public native int getLatency();
4954

5055
public native void setTransientsOption(int options);
@@ -54,11 +59,25 @@ public RubberBandStretcher(int sampleRate, int channels,
5459
public native void setPitchOption(int options);
5560

5661
public native void setExpectedInputDuration(long samples);
62+
public native int getProcessSizeLimit();
5763
public native void setMaxProcessSize(int samples);
5864

5965
public native int getSamplesRequired();
6066

61-
//!!! todo: setKeyFrameMap
67+
public native void setKeyFrameMap(long[] from, long[] to);
68+
public void setKeyFrameMap(Map<Long, Long> m) {
69+
Set<Long> keys = m.keySet();
70+
int n = keys.size();
71+
long[] from = new long[n];
72+
long[] to = new long[n];
73+
int i = 0;
74+
for (Long k : keys) {
75+
from[i] = k.longValue();
76+
to[i] = m.get(k).longValue();
77+
++i;
78+
}
79+
setKeyFrameMap(from, to);
80+
}
6281

6382
public native void study(float[][] input, int offset, int n, boolean finalBlock);
6483
public void study(float[][] input, boolean finalBlock) {
@@ -120,6 +139,9 @@ private native void initialise(int sampleRate, int channels, int options,
120139
public static final int OptionChannelsApart = 0x00000000;
121140
public static final int OptionChannelsTogether = 0x10000000;
122141

142+
public static final int OptionEngineFaster = 0x00000000;
143+
public static final int OptionEngineFiner = 0x20000000;
144+
123145
public static final int DefaultOptions = 0x00000000;
124146
public static final int PercussiveOptions = 0x00102000;
125147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
package com.breakfastquay.rubberband.test;
3+
4+
import com.breakfastquay.rubberband.RubberBandStretcher;
5+
6+
import java.util.TreeMap;
7+
8+
public class RubberBandTest
9+
{
10+
11+
public static void main(String[] args) {
12+
13+
int channels = 1;
14+
int rate = 44100;
15+
16+
RubberBandStretcher stretcher = new RubberBandStretcher
17+
(rate,
18+
channels,
19+
RubberBandStretcher.OptionEngineFiner +
20+
RubberBandStretcher.OptionProcessOffline,
21+
1.0,
22+
1.0);
23+
24+
stretcher.setTimeRatio(1.5);
25+
stretcher.setPitchScale(0.8);
26+
27+
System.err.println
28+
(String.format("Channel count: %d\n" +
29+
"Time ratio: %f\n" +
30+
"Pitch scale: %f\n" +
31+
"Preferred start pad: %d\n" +
32+
"Start delay: %d\n" +
33+
"Process size limit: %d",
34+
stretcher.getChannelCount(),
35+
stretcher.getTimeRatio(),
36+
stretcher.getPitchScale(),
37+
stretcher.getPreferredStartPad(),
38+
stretcher.getStartDelay(),
39+
stretcher.getProcessSizeLimit()
40+
));
41+
42+
int blocksize = 1024;
43+
int blocks = 400;
44+
double freq = 440.0;
45+
46+
stretcher.setMaxProcessSize(blocksize);
47+
48+
TreeMap<Long, Long> keyFrameMap = new TreeMap<Long, Long>();
49+
keyFrameMap.put((long)(3 * rate), (long)(4 * rate));
50+
keyFrameMap.put((long)(5 * rate), (long)(5 * rate));
51+
stretcher.setKeyFrameMap(keyFrameMap);
52+
53+
float[][] buffer = new float[channels][blocksize];
54+
55+
int i0 = 0;
56+
57+
for (int block = 0; block < blocks; ++block) {
58+
59+
for (int c = 0; c < channels; ++c) {
60+
for (int i = 0; i < blocksize; ++i) {
61+
buffer[c][i] = (float)Math.sin
62+
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
63+
if (i0 % rate == 0) {
64+
buffer[c][i] = 1.f;
65+
}
66+
++i0;
67+
}
68+
}
69+
70+
stretcher.study(buffer, block + 1 == blocks);
71+
}
72+
73+
i0 = 0;
74+
75+
for (int block = 0; block < blocks; ++block) {
76+
77+
for (int c = 0; c < channels; ++c) {
78+
for (int i = 0; i < blocksize; ++i) {
79+
buffer[c][i] = (float)Math.sin
80+
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
81+
if (i0 % rate == 0) {
82+
buffer[c][i] = 1.f;
83+
}
84+
++i0;
85+
}
86+
}
87+
88+
stretcher.process(buffer, block + 1 == blocks);
89+
90+
while (true) {
91+
int available = stretcher.available();
92+
if (available <= 0) {
93+
break;
94+
}
95+
int requested = available;
96+
if (requested > blocksize) {
97+
requested = blocksize;
98+
}
99+
int obtained = stretcher.retrieve(buffer, 0, requested);
100+
for (int i = 0; i < obtained; ++i) {
101+
System.out.println(Float.toString(buffer[0][i]));
102+
}
103+
}
104+
}
105+
106+
stretcher.dispose();
107+
}
108+
109+
}
110+

meson.build

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ java_sources = [
6565
'com/breakfastquay/rubberband/RubberBandStretcher.java',
6666
]
6767

68+
java_test_sources = [
69+
'com/breakfastquay/rubberband/test/RubberBandTest.java',
70+
]
71+
6872
program_sources = [
6973
'main/main.cpp',
7074
]
@@ -655,7 +659,8 @@ if have_jni
655659
# NB the JNI library is not versioned
656660
install: true,
657661
)
658-
jar('rubberband', 'com/breakfastquay/rubberband/RubberBandStretcher.java')
662+
jar('rubberband', java_sources)
663+
jar('rubberband-test', java_test_sources)
659664
else
660665
target_summary += { 'JNI library': false }
661666
if not have_java

rubberband/RubberBandStretcher.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
#undef RUBBERBAND_DLLEXPORT
3232
#ifdef _MSC_VER
33+
#ifndef RUBBERBAND_STATIC
3334
#define RUBBERBAND_DLLEXPORT __declspec(dllexport)
35+
#endif
3436
#else
3537
#define RUBBERBAND_DLLEXPORT
3638
#endif

rubberband/rubberband-c.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ extern "C" {
3535

3636
#undef RB_EXTERN
3737
#ifdef _MSC_VER
38+
#ifndef RUBBERBAND_STATIC
3839
#define RB_EXTERN extern __declspec(dllexport)
40+
#endif
3941
#else
4042
#define RB_EXTERN extern
4143
#endif

src/common/Resampler.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ D_IPP::D_IPP(Resampler::Quality /* quality */,
192192
// elements with indices greater than m_time + length for the
193193
// right filter wing for the last element.
194194

195-
m_history = int(m_window * 0.5 * max(1.0, 1.0 / m_factor)) + 1;
195+
m_history = int(m_window * 0.5 * std::max(1.0, 1.0 / m_factor)) + 1;
196196

197197
m_state = new IppsResamplingPolyphase_32f *[m_channels];
198198

@@ -305,7 +305,7 @@ D_IPP::resample(float *const BQ_R__ *const BQ_R__ out,
305305
{
306306
if (ratio > m_factor) {
307307
m_factor = ratio;
308-
m_history = int(m_window * 0.5 * max(1.0, 1.0 / m_factor)) + 1;
308+
m_history = int(m_window * 0.5 * std::max(1.0, 1.0 / m_factor)) + 1;
309309
}
310310

311311
if (m_debugLevel > 2) {
@@ -348,7 +348,7 @@ D_IPP::resampleInterleaved(float *const BQ_R__ out,
348348
{
349349
if (ratio > m_factor) {
350350
m_factor = ratio;
351-
m_history = int(m_window * 0.5 * max(1.0, 1.0 / m_factor)) + 1;
351+
m_history = int(m_window * 0.5 * std::max(1.0, 1.0 / m_factor)) + 1;
352352
}
353353

354354
if (m_debugLevel > 2) {

src/common/sysutils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ system_is_multiprocessor()
152152

153153
#ifdef _WIN32
154154

155-
void gettimeofday(struct timeval *tv, void *tz)
155+
void gettimeofday(struct timeval *tv, void * /* tz */)
156156
{
157157
union {
158158
long long ns100;

src/common/sysutils.h

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@
4545
# define R__
4646
#endif
4747

48+
#ifndef RUBBERBAND_ENABLE_WARNINGS
49+
#if defined(_MSC_VER)
50+
#pragma warning(disable:4127; disable:4244; disable:4267)
51+
#elif defined(__GNUC__)
52+
#pragma GCC diagnostic ignored "-Wconversion"
53+
#elif defined(__clang__)
54+
#pragma clang diagnostic ignored "-Wsign-conversion"
55+
#pragma clang diagnostic ignored "-Wfloat-conversion"
56+
#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
57+
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
58+
#endif
59+
#endif
60+
4861
#ifdef __clang__
4962
# define RTENTRY__ __attribute__((annotate("realtime")))
5063
#else

src/ext/getopt/getopt.c

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include <stdlib.h>
3636
#include <string.h>
3737

38+
#ifdef _MSC_VER
39+
#pragma warning (disable: 4131; disable: 4706)
40+
#endif
41+
3842
int opterr = 1, /* if error message should be printed */
3943
optind = 1, /* index into parent argv vector */
4044
optopt, /* character checked for validity */

src/ext/getopt/getopt_long.c

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include <stdio.h>
5555
#include <stdarg.h>
5656

57+
#ifdef _MSC_VER
58+
#pragma warning (disable: 4131; disable: 4996)
59+
#endif
60+
5761
GETOPT_API extern char opterrmsg[128];
5862
char opterrmsg[128]; /* last error message is stored here */
5963

src/faster/StretcherChannelData.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ R2Stretcher::ChannelData::construct(const std::set<size_t> &sizes,
8989

9090
unityResetLow = 16000.f;
9191

92-
for (std::set<size_t>::const_iterator i = sizes.begin();
93-
i != sizes.end(); ++i) {
92+
for (i = sizes.begin(); i != sizes.end(); ++i) {
9493
ffts[*i] = new FFT(*i);
9594
if (sizeof(process_t) == sizeof(double)) {
9695
ffts[*i]->initDouble();

src/finer/R3Stretcher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ R3Stretcher::consume(bool final)
10061006

10071007
while (true) {
10081008

1009-
Profiler profiler("R3Stretcher::consume/loop");
1009+
Profiler profiler2("R3Stretcher::consume/loop");
10101010

10111011
int readSpace = cd0->inbuf->getReadSpace();
10121012
m_log.log(2, "consume: read space", readSpace);

0 commit comments

Comments
 (0)