Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ else()
set(CMAKE_CXX_FLAGS "-O2 -Wall -Wno-deprecated-register")
endif()

add_definitions(-DDR_WAV_IMPLEMENTATION)
add_definitions(-DDR_WAV_NO_WCHAR)
add_definitions(-DDR_FLAC_IMPLEMENTATION)
add_definitions(-DDR_FLAC_NO_WCHAR)
add_definitions(-DDR_MP3_IMPLEMENTATION)
add_definitions(-DDR_MP3_FLOAT_OUTPUT)
add_definitions(-DSTB_VORBIS_NO_PUSHDATA_API)

add_definitions(-DOUTSIDE_SPEEX)
add_definitions(-DRANDOM_PREFIX=sptk_speex)
add_definitions(-DFLOATING_POINT)

add_definitions(-DENABLE_SINC_BEST_CONVERTER)
add_definitions(-DENABLE_SINC_MEDIUM_CONVERTER)
add_definitions(-DENABLE_SINC_FAST_CONVERTER)

set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third_party)

Expand All @@ -47,6 +63,7 @@ set(CC_SOURCES
${THIRD_PARTY_DIR}/REAPER/wave/codec_riff.cc
${THIRD_PARTY_DIR}/REAPER/wave/wave.cc
${THIRD_PARTY_DIR}/REAPER/wave/wave_io.cc
${THIRD_PARTY_DIR}/SpeexDSP/resample.cc
${THIRD_PARTY_DIR}/SWIPE/swipe.cc
${THIRD_PARTY_DIR}/SWIPE/vector.cc
${THIRD_PARTY_DIR}/Snack/jkGetF0.cc
Expand All @@ -61,6 +78,10 @@ set(CC_SOURCES
${THIRD_PARTY_DIR}/WORLD/matlabfunctions.cc
${THIRD_PARTY_DIR}/WORLD/stonemask.cc
${THIRD_PARTY_DIR}/WORLD/synthesis.cc
${THIRD_PARTY_DIR}/libsamplerate/samplerate.cc
${THIRD_PARTY_DIR}/libsamplerate/src_linear.cc
${THIRD_PARTY_DIR}/libsamplerate/src_sinc.cc
${THIRD_PARTY_DIR}/libsamplerate/src_zoh.cc
${SOURCE_DIR}/analysis/adaptive_generalized_cepstral_analysis.cc
${SOURCE_DIR}/analysis/adaptive_mel_cepstral_analysis.cc
${SOURCE_DIR}/analysis/adaptive_mel_generalized_cepstral_analysis.cc
Expand Down Expand Up @@ -203,6 +224,10 @@ set(CC_SOURCES
${SOURCE_DIR}/math/two_dimensional_real_valued_fast_fourier_transform.cc
${SOURCE_DIR}/math/vandermonde_system_solver.cc
${SOURCE_DIR}/postfilter/mel_cepstrum_postfilter.cc
${SOURCE_DIR}/resampler/libsamplerate_resampler.cc
${SOURCE_DIR}/resampler/r8brain_resampler.cc
${SOURCE_DIR}/resampler/resampler.cc
${SOURCE_DIR}/resampler/speex_resampler.cc
${SOURCE_DIR}/utils/data_symmetrizing.cc
${SOURCE_DIR}/utils/misc_utils.cc
${SOURCE_DIR}/utils/sptk_utils.cc
Expand Down Expand Up @@ -374,6 +399,7 @@ set(MAIN_SOURCES
${SOURCE_DIR}/main/ramp.cc
${SOURCE_DIR}/main/rand.cc
${SOURCE_DIR}/main/raw2wav.cc
${SOURCE_DIR}/main/resamp.cc
${SOURCE_DIR}/main/reverse.cc
${SOURCE_DIR}/main/rlevdur.cc
${SOURCE_DIR}/main/rmse.cc
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ SPTK incorporates the following third-party libraries:
| **WORLD Analysis-Synthesis** | [WORLD](https://github.com/mmorise/World) | 3-Clause BSD License |
| **Audio Format Conversion** | [dr_libs](https://github.com/mackron/dr_libs) | Public Domain / MIT License |
| | [stb](https://github.com/nothings/stb) | Public Domain / MIT License |
| **Sample Rate Conversion** | [libsamplerate](https://github.com/libsndfile/libsamplerate) | 2-Clause BSD License |
| | [SpeexDSP](https://github.com/xiph/speexdsp) | 3-Clause BSD License |
| | [r8brain](https://github.com/avaneev/r8brain-free-src) | MIT License |
| **Command-line Parser** | [ya_getopt](https://github.com/kubo/ya_getopt) | 2-Clause BSD License |

## Citation
Expand Down
2 changes: 1 addition & 1 deletion doc/main/raw2wav.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ raw2wav

.. seealso::

:ref:`wav2raw` :ref:`x2x`
:ref:`wav2raw` :ref:`x2x` :ref:`resamp`
13 changes: 13 additions & 0 deletions doc/main/resamp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _resamp:

resamp
======

.. doxygenfile:: resamp.cc

.. seealso::

:ref:`wav2raw` :ref:`raw2wav`

.. doxygenclass:: sptk::Resampler
:members:
2 changes: 1 addition & 1 deletion doc/main/wav2raw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ wav2raw

.. seealso::

:ref:`raw2wav` :ref:`x2x`
:ref:`raw2wav` :ref:`x2x` :ref:`resamp`
111 changes: 111 additions & 0 deletions include/SPTK/resampler/libsamplerate_resampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_RESAMPLER_LIBSAMPLERATE_RESAMPLER_H_
#define SPTK_RESAMPLER_LIBSAMPLERATE_RESAMPLER_H_

#include <vector> // std::vector

#include "SPTK/resampler/resampler_interface.h"
#include "SPTK/utils/sptk_utils.h"
#include "libsamplerate/samplerate.h"

namespace sptk {

/**
* Resample data sequence using libsamplerate library.
*/
class LibsamplerateResampler : public ResamplerInterface {
public:
/**
* @return Minimum quality of resampling.
*/
static int GetMinimumQuality() {
return InvertQuality(libsamplerate::SRC_LINEAR);
}

/**
* @return Maximum quality of resampling.
*/
static int GetMaximumQuality() {
return InvertQuality(libsamplerate::SRC_SINC_BEST_QUALITY);
}

/**
* @param[in] input_sampling_rate Input sampling rate in Hz.
* @param[in] output_sampling_rate Output sampling rate in Hz.
* @param[in] vector_length Length of vector (number of channels).
* @param[in] buffer_length Length of buffer used in resampling.
* @param[in] quality Quality of resampling.
*/
LibsamplerateResampler(double input_sampling_rate,
double output_sampling_rate, int vector_length,
int buffer_length, int quality);

~LibsamplerateResampler() override {
if (state_) libsamplerate::src_delete(state_);
}

/**
* Clear internal state.
*/
void Clear() override {
if (state_) libsamplerate::src_reset(state_);
}

/**
* @return Latency of this resampler in samples.
*/
int GetLatency() override;

/**
* @return True if this object is valid.
*/
bool IsValid() const override {
return is_valid_;
}

/**
* @param[in] inputs Input samples (interleaved if multi-channel).
* @param[out] outputs Output samples (interleaved if multi-channel).
* @return True on success, false on failure.
*/
bool Get(const std::vector<double>& inputs,
std::vector<double>* outputs) override;

private:
static int InvertQuality(int quality) {
return libsamplerate::SRC_LINEAR - quality;
}

const double input_sampling_rate_;
const double output_sampling_rate_;
const int vector_length_;
const int buffer_length_;

libsamplerate::SRC_STATE* state_;

bool is_valid_;

std::vector<float> input_buffer_;
std::vector<float> output_buffer_;

DISALLOW_COPY_AND_ASSIGN(LibsamplerateResampler);
};

} // namespace sptk

#endif // SPTK_RESAMPLER_LIBSAMPLERATE_RESAMPLER_H_
108 changes: 108 additions & 0 deletions include/SPTK/resampler/r8brain_resampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_RESAMPLER_R8BRAIN_RESAMPLER_H_
#define SPTK_RESAMPLER_R8BRAIN_RESAMPLER_H_

#include <memory> // std::unique_ptr
#include <vector> // std::vector

#include "SPTK/resampler/resampler_interface.h"
#include "SPTK/utils/sptk_utils.h"

#ifndef CPPCHECK
#include "r8brain/CDSPResampler.h"
#endif // CPPCHECK

namespace sptk {

/**
* Resample data sequence using r8brain library.
*/
class R8brainResampler : public ResamplerInterface {
public:
/**
* @return Minimum quality of resampling.
*/
static int GetMinimumQuality() {
return 0;
}

/**
* @return Maximum quality of resampling.
*/
static int GetMaximumQuality() {
return 0;
}

/**
* @param[in] input_sampling_rate Input sampling rate in Hz.
* @param[in] output_sampling_rate Output sampling rate in Hz.
* @param[in] vector_length Length of input vector (number of channels).
* @param[in] buffer_length Length of buffer used in resampling.
* @param[in] quality Quality of resampling.
*/
R8brainResampler(double input_sampling_rate, double output_sampling_rate,
int vector_length, int buffer_length, int quality);

~R8brainResampler() override {
}

/**
* Clear internal state.
*/
void Clear() override {
for (const std::unique_ptr<r8b::CDSPResampler24>& resampler : resamplers_) {
resampler->clear();
}
}

/**
* @return Latency of this resampler in samples.
*/
int GetLatency() override {
return IsValid() ? resamplers_[0]->getInLenBeforeOutPos(0) : 0;
}

/**
* @return True if this object is valid.
*/
bool IsValid() const override {
return is_valid_;
}

/**
* @param[in] inputs Input samples (interleaved if multi-channel).
* @param[out] outputs Output samples (interleaved if multi-channel).
* @return True on success, false on failure.
*/
bool Get(const std::vector<double>& inputs,
std::vector<double>* outputs) override;

private:
const int vector_length_;
const int buffer_length_;

std::vector<std::unique_ptr<r8b::CDSPResampler24> > resamplers_;

bool is_valid_;

DISALLOW_COPY_AND_ASSIGN(R8brainResampler);
};

} // namespace sptk

#endif // SPTK_RESAMPLER_R8BRAIN_RESAMPLER_H_
Loading