GithubHelp home page GithubHelp logo

xiao11lam / signalsmith-stretch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from signalsmith-audio/signalsmith-stretch

0.0 0.0 0.0 105 KB

C++ polyphonic pitch/time library (GitHub mirror)

Home Page: https://signalsmith-audio.co.uk/code/stretch/

License: MIT License

C++ 100.00%

signalsmith-stretch's Introduction

Signalsmith Stretch: C++ pitch/time library

This is a C++11 library for pitch and time stretching, using the final approach from the ADC22 presentation Four Ways To Write A Pitch-Shifter.

It can handle a wide-range of pitch-shifts (multiple octaves) but time-stretching sounds best for more modest changes (between 0.75x and 1.5x). There are some audio examples on the main project page.

How to use it

#include "signalsmith-stretch.h"

signalsmith::stretch::SignalsmithStretch<float> stretch;

Configuring

The easiest way to configure is a .preset???() method:

stretch.presetDefault(channels, sampleRate);
stretch.presetCheaper(channels, sampleRate);

If you want to test out different block-sizes etc. then you can use .configure() manually.

stretch.configure(channels, blockSamples, intervalSamples);

You can query the current configuration:

int block = stretch.blockSamples();
int interval = stretch.intervalSamples();
int inputLatency = stretch.inputLatency();
int outputLatency = stretch.outputLatency();

Processing (and resetting)

// Clears internal buffers
stretch.reset();

float **inputBuffers, **outputBuffers;
int inputSamples, outputSamples;
stretch.process(inputBuffers, inputSamples, outputBuffers, outputSamples);

The .process() method takes anything where buffer[channel][index] gives you a sample. This could be a float ** or a double ** or some custom object.

Pitch-shifting

stretch.setTransposeFactor(2); // up one octave

stretch.setTransposeSemitones(12); // also one octave

You can set a "tonality limit", which uses a non-linear frequency map to preserve a bit more of the timbre:

stretch.setTransposeSemitones(4, 8000/sampleRate);

Alternatively, you can set a custom frequency map, mapping input frequencies to output frequencies (both normalised against the sample-rate):

stretch.setFreqMap([](float inputFreq) {
	return inputFreq*2; // up one octave
});

Time-stretching

To get a time-stretch, hand differently-sized input/output buffers to .process(). There's no maximum block size for either input or output.

Since the buffer lengths (inputSamples and outputSamples above) are integers, it's up to you to make sure that the block lengths average out to the ratio you want over time.

Compiling

Just include signalsmith-stretch.h in your build.

It's pretty slow if optimisation is disabled though, so you might want to enable optimisation just where it's used.

DSP Library

This uses the Signalsmith DSP library for FFTs and other bits and bobs.

For convenience, a copy of the library is included (with its own LICENSE.txt) in dsp/, but if you're already using this elsewhere then you should remove this copy to avoid versioning issues.

License

MIT License for now - get in touch if you need anything else.

signalsmith-stretch's People

Contributors

geraintluff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.