{"id":1412,"url":"https://github.com/bartolsthoorn/NVDSP","last_synced_at":"2025-08-02T04:31:19.320Z","repository":{"id":3317841,"uuid":"4360705","full_name":"bartolsthoorn/NVDSP","owner":"bartolsthoorn","description":"iOS/OSX DSP for audio (with Novocaine)","archived":false,"fork":false,"pushed_at":"2017-06-05T09:19:32.000Z","size":8284,"stargazers_count":414,"open_issues_count":8,"forks_count":80,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-04-24T19:01:48.093Z","etag":null,"topics":["audio-filters","dsp","ios","novocaine"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bartolsthoorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-17T16:56:05.000Z","updated_at":"2024-04-08T12:23:40.000Z","dependencies_parsed_at":"2022-08-26T02:50:48.535Z","dependency_job_id":null,"html_url":"https://github.com/bartolsthoorn/NVDSP","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartolsthoorn%2FNVDSP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartolsthoorn%2FNVDSP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartolsthoorn%2FNVDSP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartolsthoorn%2FNVDSP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartolsthoorn","download_url":"https://codeload.github.com/bartolsthoorn/NVDSP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228438931,"owners_count":17920017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio-filters","dsp","ios","novocaine"],"created_at":"2024-01-05T20:15:45.859Z","updated_at":"2024-12-06T08:31:03.717Z","avatar_url":"https://github.com/bartolsthoorn.png","language":"Objective-C","funding_links":[],"categories":["Media"],"sub_categories":["Audio","Other free courses"],"readme":"## Audio Filters on iOS and OSX\n\nImplement high quality audio filters with just a few lines of code and [Novocaine](https://github.com/alexbw/novocaine), or your own audio library of choice.\n\nNVDSP comes with a wide variety of audio filters:\n\n+ All Pass Filter (NVAllpassFilter)\n+ Band Pass Filter, 0dB gain (NVBandpassFilter)\n+ Band Pass Filter, Q gain (NVBandpassQPeakGainFilter)\n+ High Pass Filter (NVHighpassFilter)\n+ High Shelving Filter (NVHighShelvingFilter)\n+ Low Shelving Filter (NVLowShelvingFilter)\n+ Low Pass Filter (NVLowPassFilter)\n+ Notch Filter (NVNotchFilter)\n+ Peaking EQ Filter (NVPeakingEQFilter)\n\n### Combining it with Novocaine (highpass filter)\nTo start out I recommend you to get a fresh copy of [Novocaine](https://github.com/alexbw/novocaine) and open Novocaine's excellent example project. Then import NVDSP and the Filters folder and start your filtering journey.\n``` objective-c\n// ... import Novocaine here ... \n#import \"NVDSP/NVDSP.h\"\n#import \"NVDSP/Filters/NVHighpassFilter.h\"\n\n// init Novocaine audioManager\naudioManager = [Novocaine audioManager];\nfloat samplingRate = audioManager.samplingRate;\n\n// init fileReader which we will later fetch audio from\nNSURL *inputFileURL = [[NSBundle mainBundle] URLForResource:@\"Trentemoller-Miss-You\" withExtension:@\"mp3\"];\n\nfileReader = [[AudioFileReader alloc] \n                  initWithAudioFileURL:inputFileURL \n                  samplingRate:audioManager.samplingRate\n                  numChannels:audioManager.numOutputChannels];\n\n// setup Highpass filter\nNVHighpassFilter *HPF;\nHPF = [[NVHighpassFilter alloc] initWithSamplingRate:samplingRate];\n\nHPF.cornerFrequency = 2000.0f;\nHPF.Q = 0.5f;\n\n// setup audio output block\n[fileReader play];\n[audioManager setOutputBlock:^(float *outData, UInt32 numFrames, UInt32 numChannels) {\n    [fileReader retrieveFreshAudio:outData numFrames:numFrames numChannels:numChannels];\n    \n    [HPF filterData:outData numFrames:numFrames numChannels:numChannels];\n}];\n```\nNote that NVDSP works with raw audio buffers, so it can also work with other libraries instead of Novocaine.\n\n### More examples\n#### Peaking EQ filter\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Filter/NVPeakingEQFilter.h\"\nNVPeakingEQFilter *PEF = [[NVPeakingEQFilter alloc] initWithSamplingRate:audioManager.samplingRate];\nPEF.centerFrequency = 1000.0f;\nPEF.Q = 3.0f;\nPEF.G = 20.0f;\n[PEF filterData:data numFrames:numFrames numChannels:numChannels];\n```\n\n#### Lowpass filter\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Filter/NVLowpassFilter.h\"\nNVLowpassFilter *LPF = [[NVLowpassFilter alloc] initWithSamplingRate:audioManager.samplingRate];\nLPF.cornerFrequency = 800.0f;\nLPF.Q = 0.8f;\n[LPF filterData:data numFrames:numFrames numChannels:numChannels];\n```\n\n#### Notch filter\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Filter/NVNotchFilter.h\"\nNVNotchFilter *NF = [[NVNotchFilter alloc] initWithSamplingRate:audioManager.samplingRate];\nNF.centerFrequency = 3000.0f;\nNF.Q = 0.8f;\n[NF filterData:data numFrames:numFrames numChannels:numChannels];\n```\n\n#### Bandpass filter\nThere are two types of bandpass filters:\n\n    * 0 dB gain bandpass filter (NVBandpassFilter.h)\n    * Peak gain Q bandpass filter (NVBandpassQPeakGainFilter.h)\n\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Filter/NVBandpassFilter.h\"\nNVBandpassFilter *BPF = [[NVBandpassFilter alloc] initWithSamplingRate:audioManager.samplingRate];\nBPF.centerFrequency = 2500.0f;\nBPF.Q = 0.9f;\n[BPF filterData:data numFrames:numFrames numChannels:numChannels];\n```\n\n#### Measure dB level (ranging from -51.0f to 0.0f)\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Utilities/NVSoundLevelMeter.h\"\nNVSoundLevelMeter *SLM = [[NVSoundLevelMeter alloc] init];\nfloat dB = [SLM getdBLevel:outData numFrames:numFrames numChannels:numChannels];\nNSLog(@\"dB level: %f\", dB);\n// NSLogging in an output loop will most likely cause hickups/clicky noises, but it does log the dB level!\n// To get a proper dB value, you have to call the getdBLevel method a few times (it has memory of previous values)\n// You call this inside the input or outputBlock: [audioManager setOutputBlock:^...\n```\n\n#### Applying overall gain. \nAll sample values (typically -1.0f .. 1.0f when not clipping) are multiplied by the gain value.\n``` objective-c\n// import Novocaine.h and NVDSP.h\nNVDSP *generalDSP = [[NVDSP alloc] init];\n[generalDSP applyGain:outData length:numFrames*numChannels gain:0.8];\n```\n\n#### Convert stereo (left/right) to mono\nThis converts a left and right buffer into a mono signal. It takes the average of the samples.\n```objective-c\n// Deinterleave stereo buffer into seperate left and right\nfloat *left = (float *)malloc((numFrames + 2) * sizeof(float));\nfloat *right = (float *)malloc((numFrames + 2) * sizeof(float));\n[generalDSP deinterleave:data left:left right:right length:numFrames];\n\n// Convert left and right to a mono 2 channel buffer\n[generalDSP mono:data left:left right:right length:numFrames];\n\n// Free buffers\nfree(left);\nfree(right);\n```\n\n### Clipping\nMultiple 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).\n\n``` objective-c\n// import Novocaine.h and NVDSP.h\n#import \"NVDSP/Utilities/NVClippingDetection.h\"\nNVClippingDetection *CDT = [[NVClippingDetection alloc] init];\n// ... possible clipped outData ...//\n[CDT counterClipping:outData numFrames:numFrames numChannels:numChannels];\n// ... outData is now safe ...//\n\n// or get the amount of clipped samples:\n - (float) getClippedSamples:(float *)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;\n// or get the percentage of clipped samples:\n - (float) getClippedPercentage:(float*)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;\n// or get the maximum value of a clipped sample that was found\n - (float) getClippingSample:(float *)data numFrames:(UInt32)numFrames numChannels:(UInt32)numChannels;\n```\n\n### Example project\nSee `/Examples/NVDSPExample` for a simple iOS XcodeProject example. Please note the Novocaine bundled with it might be outdated.\n\n### A thing to note\nThe 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.\n\n### Thanks to\nAlex Wiltschko - Creator of [Novocaine](http://alexbw.github.com/novocaine/)\n\nYasoshima - Writer of [this article](http://objective-audio.jp/2008/02/biquad-filter.html), revealing how vDSP_deq22 works. (and google translate, I don't speak Japanese)\n\nhrnt - Helpful on IRC #iphonedev (freenode)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartolsthoorn%2FNVDSP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartolsthoorn%2FNVDSP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartolsthoorn%2FNVDSP/lists"}