Giter Site home page Giter Site logo

peerasak-u / real-time-audio-fft Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomer8007/real-time-audio-fft

0.0 1.0 0.0 126 KB

iOS library for analysing/visualising audio data at real-time

License: MIT License

Objective-C 87.90% C 8.18% C++ 3.92%

real-time-audio-fft's Introduction

Real-time audio analysis and FFT for iOS

This library helps you visualize or process sound as it is played by providing you with a currently-played spectrum data and samples, at any given time.

Features

  • Provides accurate and high-resolution data, partially written in C
  • Uses Apple's (fast) implementation of FFT - vDSP API from the Accelerate framework
  • Makes use of FFT overlapping (of 512 frames) for better timing
  • Can process real-time input from the microphone too

How to use

For playing audio files:

Initialization

self.audioFile = [[AudioFile alloc] init];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"My Song" withExtension:@"mp3"];
[self.audioFile loadAudioWithURL:url withCompletionCallback:^(NSError *error)
{
   /* check error */
        
   // Let it play...
   error = [self.audioFile play];
        
   /* check error again */
}];

Getting live data

// Later in the program, for example in your update() function...
LiveAudioData realtimeAudioData = self.audioFile.liveAudioData;
LiveAudioChannelData leftChannel = realtimeAudioData.channel1;

if (leftChannel.containsData)
{
    // Get realtime frequencies data and waveform as pure float arrays
    float (*fftResults)[CHUNK_SIZE] = (float (*)[CHUNK_SIZE])leftChannel.fftResults.data;
    float *waveform = leftChannel.samples.data;
    UInt64 numFFTChunksAvailable = leftChannel.fftResults.numChunksAvailable;
    UInt64 numSamplesAvailable = leftChannel.samples.numSamplesAvailable;

    // Process the spectrum or the samples in various ways,
    // e.g drawing them to screen to create audio visualizations

    int frequency = 70;
    int bin = FrequencyToBinIndex(frequency, self.audioFile.playedAudioFormat.mSampleRate, CHUNK_SIZE);
    float bassMagnitudeInChannel1 = fftResults[0][bin];
    int height = bassMagnitudeInChannel1 / 2;
    self.band1.frame = CGRectMake(50, 500 - height, 15, height);

    // etc.
}

real-time-audio-fft's People

Contributors

tomer8007 avatar

Watchers

James Cloos 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.