Code Monkey home page Code Monkey logo

ataudioprocessinglibrary's Introduction

A ready-to-use collection of high performance unit generators and functions for DSP programming.

Depends on Apple's Accelerate framework, so iOS and macOS only.

Content

Ugens

Delay

SingleDelay

Distortion

SaturatedAmp

Effects

Chorus

SpringReverb

Filters

AllpassFilter

FIRLP

SVF

OnePoleLPHP

TwoPoleSVFS

BiquadSVF

Generators

ParabolicWM

TriLFOStereo

LFO

Utility

midiToFreq(noteNumber)

frequencyToMIDI(freq)

clamp(input, low, high)

threePointShaper(in, start, mid, end)

twoPointShaper(in, outStart, outEnd)

linearToLog(input, minIn, maxIn, minOut, maxOut)

dBToAmp(input)

Usage

Link against Accelerate.framework, then include ATAudioProcessing.hpp.

Use the .calculateBlock method, then copy the .output into buffer.

The process function in a subclass of Apple's DSPKernel will look like this:

// The code is looking complex, but calculation done per vectorized block, 
// so it's quite outperformer the sample-by-sample approach.

// ParabolicWM oscillator;
// oscillator.init(sampleRate, channelCount, calculationBlockSize, oversamplingFactor);

void process(AUAudioFrameCount frameCount, AUAudioFrameCount bufferOffset) override {
    AudioBuffer *out = outBufferListPtr->mBuffers;
    
    for (int frameOffset = 0; frameOffset < frameCount; frameOffset+=calculationBlockSize) {
        // to improve performance per block calculation is used
        
        //
        // Fill the rest of the output from the previous iteration
        // (in the case of variable framerate)
        //
        
        if (frameCount - frameOffset < preGenWriteIndex) {
            preGenWriteIndex = frameCount - frameOffset;
        }
        
        if (preGenWriteIndex != 0) {
            for (int channel = 0; channel < numberOfChannels; ++channel) {
                sample_t *outChannel = (sample_t *)out[channel].mData;
                memcpy(outChannel+frameOffset, &oscillator.output[channel][postGenWriteIndex],
                       preGenWriteIndex*sizeof(sample_t));
            }
        }
        
        if (preGenWriteIndex + frameOffset == frameCount) {
            postGenWriteIndex += preGenWriteIndex;
            break;
        }

        //
        // calculate the block
        // here should be your DSP
        //
        oscillator.calculateBlock(440, 0.5, 1);
        
        //
        // copy the output
        //
        if (frameCount - frameOffset < calculationBlockSize) {
            postGenWriteIndex = frameCount - frameOffset - preGenWriteIndex;
        }

        for (int channel = 0; channel < numberOfChannels; ++channel) {
            sample_t *outChannel = (sample_t *)out[channel].mData;
            memcpy(outChannel+frameOffset+preGenWriteIndex, &oscillator.output[channel][0],
                postGenWriteIndex*sizeof(sample_t));
        }
    }
    
    preGenWriteIndex = calculationBlockSize - postGenWriteIndex;
}

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.