All Projects → bartolsthoorn → Nvdsp

bartolsthoorn / Nvdsp

Licence: mit
iOS/OSX DSP for audio (with Novocaine)

Labels

Projects that are alternatives of or similar to Nvdsp

ad-server
advertising server
Stars: ✭ 31 (-92.19%)
Mutual labels:  dsp
Dubstep Data
Put data inside dubstep drops
Stars: ✭ 262 (-34.01%)
Mutual labels:  dsp
Pitch Detection
collection of O(NlogN) pitch detection implementations
Stars: ✭ 335 (-15.62%)
Mutual labels:  dsp
music220a
The code examples for Music 220A
Stars: ✭ 51 (-87.15%)
Mutual labels:  dsp
Ofxpdsp
openFrameworks addon for audio synthesis and generative music
Stars: ✭ 255 (-35.77%)
Mutual labels:  dsp
Daisysp
A Powerful, Open Source DSP Library in C++
Stars: ✭ 291 (-26.7%)
Mutual labels:  dsp
RpiANC
Active Noise Control on Raspberry Pi
Stars: ✭ 49 (-87.66%)
Mutual labels:  dsp
Spectro
🎶 Real-time audio spectrogram generator for the web
Stars: ✭ 383 (-3.53%)
Mutual labels:  dsp
Noaa Apt
NOAA APT weather satellite image decoder, for Linux, Windows, RPi 2+ and OSX
Stars: ✭ 257 (-35.26%)
Mutual labels:  dsp
Sporth
A small stack-based audio language.
Stars: ✭ 325 (-18.14%)
Mutual labels:  dsp
vult
Vult is a transcompiler well suited to write high-performance DSP code
Stars: ✭ 316 (-20.4%)
Mutual labels:  dsp
NMSIS
Nuclei Microcontroller Software Interface Standard Development Repo
Stars: ✭ 24 (-93.95%)
Mutual labels:  dsp
Pysptk
A python wrapper for Speech Signal Processing Toolkit (SPTK).
Stars: ✭ 297 (-25.19%)
Mutual labels:  dsp
matchering-cli
🎚️ Simple Matchering 2.0 Command Line Application
Stars: ✭ 28 (-92.95%)
Mutual labels:  dsp
Dplug
Audio plugin framework. VST2/VST3/AU/AAX/LV2 for Linux/macOS/Windows.
Stars: ✭ 341 (-14.11%)
Mutual labels:  dsp
intfftk
Fully pipelined Integer Scaled / Unscaled Radix-2 Forward/Inverse Fast Fourier Transform (FFT) IP-core for newest Xilinx FPGAs (Source language - VHDL / Verilog). GNU GPL 3.0.
Stars: ✭ 43 (-89.17%)
Mutual labels:  dsp
Vult
Vult is a transcompiler well suited to write high-performance DSP code
Stars: ✭ 272 (-31.49%)
Mutual labels:  dsp
Dx7 Supercollider
My accurate Yamaha DX-7 clone. Programmed in Supercollider.
Stars: ✭ 395 (-0.5%)
Mutual labels:  dsp
Csdr
A simple DSP library and command-line tool for Software Defined Radio.
Stars: ✭ 358 (-9.82%)
Mutual labels:  dsp
Amsynth
Analog Modelling Synthesizer
Stars: ✭ 313 (-21.16%)
Mutual labels:  dsp

Audio Filters on iOS and OSX

Implement high quality audio filters with just a few lines of code and Novocaine, or your own audio library of choice.

NVDSP comes with a wide variety of audio filters:

  • All Pass Filter (NVAllpassFilter)
  • Band Pass Filter, 0dB gain (NVBandpassFilter)
  • Band Pass Filter, Q gain (NVBandpassQPeakGainFilter)
  • High Pass Filter (NVHighpassFilter)
  • High Shelving Filter (NVHighShelvingFilter)
  • Low Shelving Filter (NVLowShelvingFilter)
  • Low Pass Filter (NVLowPassFilter)
  • Notch Filter (NVNotchFilter)
  • Peaking EQ Filter (NVPeakingEQFilter)

Combining it with Novocaine (highpass filter)

To start out I recommend you to get a fresh copy of Novocaine and open Novocaine's excellent example project. Then import NVDSP and the Filters folder and start your filtering journey.

// ... import Novocaine here ... 
#import "NVDSP/NVDSP.h"
#import "NVDSP/Filters/NVHighpassFilter.h"

// init Novocaine audioManager
audioManager = [Novocaine audioManager];
float samplingRate = audioManager.samplingRate;

// init fileReader which we will later fetch audio from
NSURL *inputFileURL = [[NSBundle mainBundle] URLForResource:@"Trentemoller-Miss-You" withExtension:@"mp3"];

fileReader = [[AudioFileReader alloc] 
                  initWithAudioFileURL:inputFileURL 
                  samplingRate:audioManager.samplingRate
                  numChannels:audioManager.numOutputChannels];

// setup Highpass filter
NVHighpassFilter *HPF;
HPF = [[NVHighpassFilter alloc] initWithSamplingRate:samplingRate];

HPF.cornerFrequency = 2000.0f;
HPF.Q = 0.5f;

// setup audio output block
[fileReader play];
[audioManager setOutputBlock:^(float *outData, UInt32 numFrames, UInt32 numChannels) {
    [fileReader retrieveFreshAudio:outData numFrames:numFrames numChannels:numChannels];
    
    [HPF filterData:outData numFrames:numFrames numChannels:numChannels];
}];

Note that NVDSP works with raw audio buffers, so it can also work with other libraries instead of Novocaine.

More examples

Peaking EQ filter

// import Novocaine.h and NVDSP.h
#import "NVDSP/Filter/NVPeakingEQFilter.h"
NVPeakingEQFilter *PEF = [[NVPeakingEQFilter alloc] initWithSamplingRate:audioManager.samplingRate];
PEF.centerFrequency = 1000.0f;
PEF.Q = 3.0f;
PEF.G = 20.0f;
[PEF filterData:data numFrames:numFrames numChannels:numChannels];

Lowpass filter

// import Novocaine.h and NVDSP.h
#import "NVDSP/Filter/NVLowpassFilter.h"
NVLowpassFilter *LPF = [[NVLowpassFilter alloc] initWithSamplingRate:audioManager.samplingRate];
LPF.cornerFrequency = 800.0f;
LPF.Q = 0.8f;
[LPF filterData:data numFrames:numFrames numChannels:numChannels];

Notch filter

// import Novocaine.h and NVDSP.h
#import "NVDSP/Filter/NVNotchFilter.h"
NVNotchFilter *NF = [[NVNotchFilter alloc] initWithSamplingRate:audioManager.samplingRate];
NF.centerFrequency = 3000.0f;
NF.Q = 0.8f;
[NF filterData:data numFrames:numFrames numChannels:numChannels];

Bandpass filter

There are two types of bandpass filters:

* 0 dB gain bandpass filter (NVBandpassFilter.h)
* Peak gain Q bandpass filter (NVBandpassQPeakGainFilter.h)
// import Novocaine.h and NVDSP.h
#import "NVDSP/Filter/NVBandpassFilter.h"
NVBandpassFilter *BPF = [[NVBandpassFilter alloc] initWithSamplingRate:audioManager.samplingRate];
BPF.centerFrequency = 2500.0f;
BPF.Q = 0.9f;
[BPF filterData:data numFrames:numFrames numChannels:numChannels];

Measure dB level (ranging from -51.0f to 0.0f)

// import Novocaine.h and NVDSP.h
#import "NVDSP/Utilities/NVSoundLevelMeter.h"
NVSoundLevelMeter *SLM = [[NVSoundLevelMeter alloc] init];
float dB = [SLM getdBLevel:outData numFrames:numFrames numChannels:numChannels];
NSLog(@"dB level: %f", dB);
// NSLogging in an output loop will most likely cause hickups/clicky noises, but it does log the dB level!
// To get a proper dB value, you have to call the getdBLevel method a few times (it has memory of previous values)
// You call this inside the input or outputBlock: [audioManager setOutputBlock:^...

Applying overall gain.

All sample values (typically -1.0f .. 1.0f when not clipping) are multiplied by the gain value.

// import Novocaine.h and NVDSP.h
NVDSP *generalDSP = [[NVDSP alloc] init];
[generalDSP applyGain:outData length:numFrames*numChannels gain:0.8];

Convert stereo (left/right) to mono

This converts a left and right buffer into a mono signal. It takes the average of the samples.

// Deinterleave stereo buffer into seperate left and right
float *left = (float *)malloc((numFrames + 2) * sizeof(float));
float *right = (float *)malloc((numFrames + 2) * sizeof(float));
[generalDSP deinterleave:data left:left right:right length:numFrames];

// Convert left and right to a mono 2 channel buffer
[generalDSP mono:data left:left right:right length:numFrames];

// Free buffers
free(left);
free(right);

Clipping

Multiple peaking EQs with high gains can cause clipping. Clipping is basically sample data that exceeds the maximum or minimum value of 1.0f or -1.0f respectively. Clipping will cause really loud and dirty noises, like a bad overdrive effect. You can use the method counterClipping to prevent clipping (it will reduce the sound level).

// import Novocaine.h and NVDSP.h
#import "NVDSP/Utilities/NVClippingDetection.h"
NVClippingDetection *CDT = [[NVClippingDetection alloc] init];
// ... possible clipped outData ...//
[CDT counterClipping:outData numFrames:numFrames numChannels:numChannels];
// ... outData is now safe ...//

// or get the amount of clipped samples:
 - (float) getClippedSamples:(float *)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;
// or get the percentage of clipped samples:
 - (float) getClippedPercentage:(float*)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;
// or get the maximum value of a clipped sample that was found
 - (float) getClippingSample:(float *)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;

Example project

See /Examples/NVDSPExample for a simple iOS XcodeProject example. Please note the Novocaine bundled with it might be outdated.

A thing to note

The NVDSP class is written in C++, so the classes that use it will have to be Objective-C++. Change all the files that use NVDSP from MyClass.m to MyClass.mm.

Thanks to

Alex Wiltschko - Creator of Novocaine

Yasoshima - Writer of this article, revealing how vDSP_deq22 works. (and google translate, I don't speak Japanese)

hrnt - Helpful on IRC #iphonedev (freenode)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].