Files
librubberband/src/RubberBandStretcher.cpp

147 lines
3.8 KiB
C++
Raw Normal View History

2007-11-06 21:41:16 +00:00
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rubber Band
An audio time-stretching and pitch-shifting library.
Copyright 2007-2008 Chris Cannam.
2007-11-06 21:41:16 +00:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "StretcherImpl.h"
2008-06-09 20:46:37 +00:00
#include "rubberband.h"
2007-11-06 21:41:16 +00:00
2008-06-09 20:46:37 +00:00
struct RubberBandState_
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
RubberBand::StretcherImpl *m_impl;
};
2007-11-06 21:41:16 +00:00
2008-06-09 20:46:37 +00:00
RubberBandState rubberband_new(unsigned int sampleRate,
unsigned int channels,
RubberBandOptions options, //!!! sort out RubberBand namespacing
double initialTimeRatio,
double initialPitchScale)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
RubberBandState_ *state = new RubberBandState_();
state->m_impl = new RubberBand::StretcherImpl
(sampleRate, channels, options,
initialTimeRatio, initialPitchScale);
return state;
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_delete(RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
delete state->m_impl;
delete state;
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_reset(RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->reset();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_time_ratio(RubberBandState state, double ratio)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setTimeRatio(ratio);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_pitch_scale(RubberBandState state, double scale)
{
2008-06-09 20:46:37 +00:00
state->m_impl->setPitchScale(scale);
}
2008-06-09 20:46:37 +00:00
double rubberband_get_time_ratio(const RubberBandState state)
{
2008-06-09 20:46:37 +00:00
return state->m_impl->getTimeRatio();
}
2008-06-09 20:46:37 +00:00
double rubberband_get_pitch_scale(const RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
return state->m_impl->getPitchScale();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
unsigned int rubberband_get_latency(const RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
return state->m_impl->getLatency();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_transients_option(RubberBandState state, RubberBandOptions options)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setTransientsOption(options);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_phase_option(RubberBandState state, RubberBandOptions options)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setPhaseOption(options);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_formant_option(RubberBandState state, RubberBandOptions options)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setFormantOption(options);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_pitch_option(RubberBandState state, RubberBandOptions options)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setPitchOption(options);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_expected_input_duration(RubberBandState state, unsigned int samples)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setExpectedInputDuration(samples);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
unsigned int rubberband_get_samples_required(const RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
return state->m_impl->getSamplesRequired();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_max_process_size(RubberBandState state, unsigned int samples)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setMaxProcessSize(samples);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_study(RubberBandState state, const float *const *input, unsigned int samples, int final)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->study(input, samples, final != 0);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_process(RubberBandState state, const float *const *input, unsigned int samples, int final)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->process(input, samples, final != 0);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
int rubberband_available(const RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
return state->m_impl->available();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
unsigned int rubberband_retrieve(const RubberBandState state, float *const *output, unsigned int samples)
{
2008-06-09 20:46:37 +00:00
return state->m_impl->retrieve(output, samples);
}
2008-06-09 20:46:37 +00:00
unsigned int rubberband_get_channel_count(const RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
return state->m_impl->getChannelCount();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_calculate_stretch(RubberBandState state)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->calculateStretch();
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_debug_level(RubberBandState state, int level)
2007-11-06 21:41:16 +00:00
{
2008-06-09 20:46:37 +00:00
state->m_impl->setDebugLevel(level);
2007-11-06 21:41:16 +00:00
}
2008-06-09 20:46:37 +00:00
void rubberband_set_default_debug_level(int level)
{
2008-06-09 20:46:37 +00:00
RubberBand::StretcherImpl::setDefaultDebugLevel(level);
}