Skip to content

Commit

Permalink
Merge from default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cannam committed Jan 31, 2024
2 parents 888eed2 + f0d702e commit 0d10012
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 16 deletions.
24 changes: 23 additions & 1 deletion com/breakfastquay/rubberband/RubberBandStretcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ License, or (at your option) any later version. See the file

package com.breakfastquay.rubberband;

import java.util.Map;
import java.util.Set;

public class RubberBandStretcher
{
public RubberBandStretcher(int sampleRate, int channels,
Expand All @@ -45,6 +48,8 @@ public RubberBandStretcher(int sampleRate, int channels,
public native double getTimeRatio();
public native double getPitchScale();

public native int getPreferredStartPad();
public native int getStartDelay();
public native int getLatency();

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

public native void setExpectedInputDuration(long samples);
public native int getProcessSizeLimit();
public native void setMaxProcessSize(int samples);

public native int getSamplesRequired();

//!!! todo: setKeyFrameMap
public native void setKeyFrameMap(long[] from, long[] to);
public void setKeyFrameMap(Map<Long, Long> m) {
Set<Long> keys = m.keySet();
int n = keys.size();
long[] from = new long[n];
long[] to = new long[n];
int i = 0;
for (Long k : keys) {
from[i] = k.longValue();
to[i] = m.get(k).longValue();
++i;
}
setKeyFrameMap(from, to);
}

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

public static final int OptionEngineFaster = 0x00000000;
public static final int OptionEngineFiner = 0x20000000;

public static final int DefaultOptions = 0x00000000;
public static final int PercussiveOptions = 0x00102000;

Expand Down
110 changes: 110 additions & 0 deletions com/breakfastquay/rubberband/test/RubberBandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

package com.breakfastquay.rubberband.test;

import com.breakfastquay.rubberband.RubberBandStretcher;

import java.util.TreeMap;

public class RubberBandTest
{

public static void main(String[] args) {

int channels = 1;
int rate = 44100;

RubberBandStretcher stretcher = new RubberBandStretcher
(rate,
channels,
RubberBandStretcher.OptionEngineFiner +
RubberBandStretcher.OptionProcessOffline,
1.0,
1.0);

stretcher.setTimeRatio(1.5);
stretcher.setPitchScale(0.8);

System.err.println
(String.format("Channel count: %d\n" +
"Time ratio: %f\n" +
"Pitch scale: %f\n" +
"Preferred start pad: %d\n" +
"Start delay: %d\n" +
"Process size limit: %d",
stretcher.getChannelCount(),
stretcher.getTimeRatio(),
stretcher.getPitchScale(),
stretcher.getPreferredStartPad(),
stretcher.getStartDelay(),
stretcher.getProcessSizeLimit()
));

int blocksize = 1024;
int blocks = 400;
double freq = 440.0;

stretcher.setMaxProcessSize(blocksize);

TreeMap<Long, Long> keyFrameMap = new TreeMap<Long, Long>();
keyFrameMap.put((long)(3 * rate), (long)(4 * rate));
keyFrameMap.put((long)(5 * rate), (long)(5 * rate));
stretcher.setKeyFrameMap(keyFrameMap);

float[][] buffer = new float[channels][blocksize];

int i0 = 0;

for (int block = 0; block < blocks; ++block) {

for (int c = 0; c < channels; ++c) {
for (int i = 0; i < blocksize; ++i) {
buffer[c][i] = (float)Math.sin
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
if (i0 % rate == 0) {
buffer[c][i] = 1.f;
}
++i0;
}
}

stretcher.study(buffer, block + 1 == blocks);
}

i0 = 0;

for (int block = 0; block < blocks; ++block) {

for (int c = 0; c < channels; ++c) {
for (int i = 0; i < blocksize; ++i) {
buffer[c][i] = (float)Math.sin
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
if (i0 % rate == 0) {
buffer[c][i] = 1.f;
}
++i0;
}
}

stretcher.process(buffer, block + 1 == blocks);

while (true) {
int available = stretcher.available();
if (available <= 0) {
break;
}
int requested = available;
if (requested > blocksize) {
requested = blocksize;
}
int obtained = stretcher.retrieve(buffer, 0, requested);
for (int i = 0; i < obtained; ++i) {
System.out.println(Float.toString(buffer[0][i]));
}
}
}

stretcher.dispose();
}

}

7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ java_sources = [
'com/breakfastquay/rubberband/RubberBandStretcher.java',
]

java_test_sources = [
'com/breakfastquay/rubberband/test/RubberBandTest.java',
]

program_sources = [
'main/main.cpp',
]
Expand Down Expand Up @@ -655,7 +659,8 @@ if have_jni
# NB the JNI library is not versioned
install: true,
)
jar('rubberband', 'com/breakfastquay/rubberband/RubberBandStretcher.java')
jar('rubberband', java_sources)
jar('rubberband-test', java_test_sources)
else
target_summary += { 'JNI library': false }
if not have_java
Expand Down
2 changes: 2 additions & 0 deletions rubberband/RubberBandStretcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

#undef RUBBERBAND_DLLEXPORT
#ifdef _MSC_VER
#ifndef RUBBERBAND_STATIC
#define RUBBERBAND_DLLEXPORT __declspec(dllexport)
#endif
#else
#define RUBBERBAND_DLLEXPORT
#endif
Expand Down
2 changes: 2 additions & 0 deletions rubberband/rubberband-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ extern "C" {

#undef RB_EXTERN
#ifdef _MSC_VER
#ifndef RUBBERBAND_STATIC
#define RB_EXTERN extern __declspec(dllexport)
#endif
#else
#define RB_EXTERN extern
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/common/Resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ D_IPP::D_IPP(Resampler::Quality /* quality */,
// elements with indices greater than m_time + length for the
// right filter wing for the last element.

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

m_state = new IppsResamplingPolyphase_32f *[m_channels];

Expand Down Expand Up @@ -305,7 +305,7 @@ D_IPP::resample(float *const BQ_R__ *const BQ_R__ out,
{
if (ratio > m_factor) {
m_factor = ratio;
m_history = int(m_window * 0.5 * max(1.0, 1.0 / m_factor)) + 1;
m_history = int(m_window * 0.5 * std::max(1.0, 1.0 / m_factor)) + 1;
}

if (m_debugLevel > 2) {
Expand Down Expand Up @@ -348,7 +348,7 @@ D_IPP::resampleInterleaved(float *const BQ_R__ out,
{
if (ratio > m_factor) {
m_factor = ratio;
m_history = int(m_window * 0.5 * max(1.0, 1.0 / m_factor)) + 1;
m_history = int(m_window * 0.5 * std::max(1.0, 1.0 / m_factor)) + 1;
}

if (m_debugLevel > 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/sysutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ system_is_multiprocessor()

#ifdef _WIN32

void gettimeofday(struct timeval *tv, void *tz)
void gettimeofday(struct timeval *tv, void * /* tz */)
{
union {
long long ns100;
Expand Down
13 changes: 13 additions & 0 deletions src/common/sysutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
# define R__
#endif

#ifndef RUBBERBAND_ENABLE_WARNINGS
#if defined(_MSC_VER)
#pragma warning(disable:4127; disable:4244; disable:4267)
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wconversion"
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wfloat-conversion"
#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#endif
#endif

#ifdef __clang__
# define RTENTRY__ __attribute__((annotate("realtime")))
#else
Expand Down
4 changes: 4 additions & 0 deletions src/ext/getopt/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <stdlib.h>
#include <string.h>

#ifdef _MSC_VER
#pragma warning (disable: 4131; disable: 4706)
#endif

int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
Expand Down
4 changes: 4 additions & 0 deletions src/ext/getopt/getopt_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#include <stdio.h>
#include <stdarg.h>

#ifdef _MSC_VER
#pragma warning (disable: 4131; disable: 4996)
#endif

GETOPT_API extern char opterrmsg[128];
char opterrmsg[128]; /* last error message is stored here */

Expand Down
3 changes: 1 addition & 2 deletions src/faster/StretcherChannelData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ R2Stretcher::ChannelData::construct(const std::set<size_t> &sizes,

unityResetLow = 16000.f;

for (std::set<size_t>::const_iterator i = sizes.begin();
i != sizes.end(); ++i) {
for (i = sizes.begin(); i != sizes.end(); ++i) {
ffts[*i] = new FFT(*i);
if (sizeof(process_t) == sizeof(double)) {
ffts[*i]->initDouble();
Expand Down
2 changes: 1 addition & 1 deletion src/finer/R3Stretcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ R3Stretcher::consume(bool final)

while (true) {

Profiler profiler("R3Stretcher::consume/loop");
Profiler profiler2("R3Stretcher::consume/loop");

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

0 comments on commit 0d10012

Please sign in to comment.