Git Product home page Git Product logo

arduino-library-audio's Introduction

arduino-library-audio

Arduino Audio Library for stm32 platform

There is one Audio library for Arduino Due (https://github.com/arduino-org/Arduino/tree/master/libraries/Audio). This library has only three "commands"

1. begin
2. prepare
3. write

This commands are not sufficient for Audio Interface of Otto board because there are no commands to use the microphones and to select the output channel.

For this reason we can use Processing Sound library: https://processing.org/reference/libraries/sound/

AUDIO API definition

AudioDevice

  • Constructor: AudioDevice(theParent, sampleRate, bufferSize)

  • Description: Audio Device allows for configuring the audio server. If you need a low latency server you can reduce the buffer size. Allowed values are power of 2. For changing the sample rate pass the appropriate value in the constructor.

  • Example:

    import processing.sound.*;
    AudioDevice myAudioServer;
    
    void setup() {
       myAudioServer = new AudioDevice(this, 44100, 128);
     }
    
     void loop() {
     }
    

AudioIn

  • Constructor: AudioIn(theParent, in)

  • Description: Audio Device allows for configuring the audio server. If you need a low AudioIn let's you grab the audio input

  • Methods:

  • start(): Starts the input stream.

  • play(): Start the Input Stream and route it to the Audio Hardware Output

  • set(): Set multiple parameters at once.

  • amp(): Change the amplitude/volume of the input steam.

  • add(): Offset the output of the input stream by given value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the input stream.

  • Example:

    import processing.sound.*;
    AudioIn in;
    
    void setup() {
    
       // Create the Input stream
       in = new AudioIn(this, 0);
       in.play();
    }
    
    void loop() {
    }
    

SoundFile

  • Constructor: SoundFile(theParent, path)

  • Description: This is a Soundfile Player which allows to play back and manipulate soundfiles. Supported formats are: WAV, AIF/AIFF, MP3.

  • Methods:

  • frames(): Returns the number of frames/samples of the sound file.

  • sampleRate(): Returns the sample rate of the soundfile.

  • channels(): Returns the number of channels in the soundfile.

  • duration(): Returns the duration of the the soundfile.

  • play(): Starts the playback of a soundfile. Only plays the soundfile once.

  • loop(): Starts the playback of a soundfile to loop.

  • jump(): Jump to a specific position in the file while continuing to play.

  • cue(): Cues the playhead to a fixed position in the soundfile. Note that the time parameter supports only integer values.

  • set(): Set multiple parameters at once

  • pan(): Move the sound in a stereo panorama, only supports Mono Files

  • rate(): Change the playback rate of the soundfile.

  • amp(): Changes the amplitude/volume of the player.

  • add(): Offset the output of the player by given value

  • stop(): Stops the player

  • Example:

    import processing.sound.*;
    SoundFile file;
    
    void setup() {
    
      // Load a soundfile from the /data folder of the
      // sketch and play it back
      file = new SoundFile(this, "sample.mp3");
      file.play();
    }
    
    void loop() {
    }
    

LowPass

  • Constructor: LowPass(parent)

  • Description: This is a low pass filter.

  • Methods:

  • process(): Start the filter

  • stop(): Stop the filter

  • freq(): Sets the cut off frequency for the filter

  • Example:

     import processing.sound.*;
    
     WhiteNoise noise;
     LowPass lowPass;
    
     float amp=0.0;
    
     void setup() {
    
       // Create a noise generator and a bandpass filter
       noise = new WhiteNoise(this);
       lowPass = new LowPass(this);
    
       noise.play(0.5);
       lowPass.process(noise, 800);
     }
    
     void loop() {
     }
    

HighPass

  • Constructor: HighPass(parent)

  • Description: This is a high pass filter.

  • Methods:

    • process(): Start the filter
    • stop(): Stop the filter
    • freq(): Sets the cut off frequency for the filter
  • Example:

     import processing.sound.*;
    
     WhiteNoise noise;
     HighPass highPass;
    
     float amp=0.0;
    
     void setup() {
    
        // Create a noise generator and a bandpass filter
        noise = new WhiteNoise(this);
        highPass = new HighPass(this);
    
        noise.play(0.5);
        highPass.process(noise, 5000);
      }
    
      void loop() {
      }
    

BandPass

  • Constructor: BandPass(parent)

  • Description: This is a high pass filter.

  • Methods:

  • process(): Start the Filter

  • set(): Sets frequency and bandwidth of the filter with one method.

  • freq(): Set the cutoff frequency for the filter

  • bw():Set the bandwidth for the filter.

  • stop(): Stops the filter.

  • Example:

     import processing.sound.*;
    
     WhiteNoise noise;
     BandPass bandPass;
    
     float amp=0.0;
    
     void setup() {
    
     // Create a noise generator and a bandpass filter
     noise = new WhiteNoise(this);
     bandPass = new BandPass(this);
    
      noise.play(0.5);
      bandPass.process(noise, 100, 50);
     }
    
     void loop() {
     }
    

Delay

  • Constructor: Delay(theParent)

  • Description: This is a simple Delay Effect.

  • Methods:

  • process(): Start the delay effect

  • set(): Set delay time and feedback values at once

  • time(): Changes the delay time of the effect.

  • feedback(): Change the feedback of the delay effect.

  • stop(): Stop the delay effect.

  • Example:

     import processing.sound.*;
    
     AudioIn in;
     Delay delay;
    
     void setup() {
    
       // create the input stream
       in = new AudioIn(this, 0);
    
       // create a delay effect
       delay = new Delay(this);
    
       // start the input stream
       in.play();
    
       // Patch the delay
       delay.process(in, 5);
       delay.time(0.5);
     }
    
     void loop() {
     }
    

Reverb

  • Constructor: Reverb(theParent)

  • Description: This is a simple Reverb Effect.

  • Methods:

  • process(): Start the reverb effect.

  • set(): Set multiple parameters at once

  • room(): Change the room size of the reverb effect.

  • damp(): Change the dampening of the reverb effect

  • wet(): Change the dry/wet ratio of the delay effect

  • stop(): Stop the reverb effect

  • Example:

     import processing.sound.*;
    
     AudioIn in;
     Reverb reverb;
    
     void setup() {
    
       // create the input stream
       in = new AudioIn(this, 0);
    
       // create a reverb effect
       reverb = new Reverb(this);
    
       // start the input stream
       in.play();
       reverb.process(in);
     }
    
     void loop() {
     }
    

Amplitude

  • Constructor: Amplitude(theParent)

  • Description: This is a volume analyzer. It calculates the root mean square of the amplitude of each audio block and returns that value.

  • Methods:

  • input(): Defines the audio input source of the amplitude analyzer.

  • analyze(): Queries a value from the analyzer and returns a float between 0. and 1.

  • Example:

     import processing.sound.*;
     Amplitude amp;
     AudioIn in;
    
     void setup() {
       // Create an Input stream which is routed into the Amplitude analyzer
       amp = new Amplitude(this);
       in = new AudioIn(this, 0);
       in.start();
       amp.input(in);
     }
    
     void loop() {
       println(amp.analyze());
     }
    

FFT

  • Constructor: FFT(theParent, fftSize)

  • Description: This is a Fast Fourier Transform (FFT) analyzer. It calculates the normalized power spectrum of an audio stream the moment it is queried with the analyze() method.

  • Methods:

  • input(): Define the audio input for the analyzer.

  • analyze(): Queries a value from the analyzer and returns a vector the size of the pre-defined number of bands.

  • Example:

     import processing.sound.*;
    
     FFT fft;
     AudioIn in;
     int bands = 512;
     float[] spectrum = new float[bands];
    
     void setup() {
       Serial.begin(9600)
    
       // Create an Input stream which is routed into
       // the Amplitude analyzer
       fft = new FFT(this, bands);
       in = new AudioIn(this, 0);
    
       // start the Audio Input
       in.start();
    
       // patch the AudioIn
       fft.input(in);
     }
    
     void loop() {
       fft.analyze(spectrum);
    
       for(int i = 0; i < bands; i++){
       // The result of the FFT is normalized
       // print the value for frequency i band
       Serial.println(spectrum[i]);
       }
    }
    

WhiteNoise

  • Constructor: WhiteNoise(theParent)

  • Description: This is a White Noise Generator. White Noise has a flat spectrum.

  • Methods:

  • play(): Start the generator

  • set(): Set multiple parameters at once.

  • amp(): Change the amplitude/volume of the generator

  • add(): Offset the generator by a given Value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the generator

  • Example:

     import processing.sound.*;
     WhiteNoise noise;
    
     void setup() {
       // Create the noise generator
       noise = new WhiteNoise(this);
       noise.play();
     }
    
     void loop() {
     }
    

PinkNoise

  • Constructor: PinkNoise(theParent)

  • Description: This is a Pink Noise Generator. Pink Noise has a decrease of 3dB per octave.

  • Methods:

  • play(): Start the generator

  • set(): Set multiple parameters at once.

  • amp(): Change the amplitude/volume of the generator

  • add(): Offset the generator by a given Value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the generator

  • Example:

     import processing.sound.*;
     PinkNoise noise;
    
     void setup() {
       // Create the noise generator
       noise = new PinkNoise(this);
       noise.play();
     }
    
     void loop() {
     }
    

BrownNoise

  • Constructor: BrownNoise(theParent)

  • Description: This is a Brown Noise Generator. Brown Noise has a decrease of 6dB per octave.

  • Methods:

  • play(): Start the generator

  • set(): Set multiple parameters at once.

  • amp(): Change the amplitude/volume of the generator

  • add(): Offset the generator by a given Value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the generator

  • Example:

     import processing.sound.*;
     BrownNoise noise;
    
     void setup() {
       // Create the noise generator
       noise = new BrownNoise(this);
       noise.play();
     }
    
     void loop() {
    

SinOsc

  • Constructor: SinOsc(theParent)

  • Description: This is a simple Sine Wave Oscillator.

  • Methods:

  • play(): Starts the oscillator

  • set(): Set multiple parameters at once

  • freq(): Set the frequency of the oscillator in Hz.

  • __amp() __: Set the amplitude/volume of the oscillator

  • add(): Offset the output of the oscillator by given value

  • pan(): Move the sound in a stereo panorama

  • __stop() __: Stop the oscillator.

  • Example:

     import processing.sound.*;
     SinOsc sine;
    
     void setup() {
       // Create the sine oscillator.
       sine = new SinOsc(this);
       sine.play();
     }
    
     void loop() {
    }
    

SawOsc

  • Constructor: SawOsc(theParent)

  • Description: This is a simple Sawtooth Wave Oscillator.

  • Methods:

  • play(): Starts the oscillator

  • set(): Set multiple parameters at once

  • freq(): Set the frequency of the oscillator in Hz.

  • amp(): Set the amplitude/volume of the oscillator

  • add(): Offset the output of the oscillator by given value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the oscillator.

  • Example:

     import processing.sound.*;
     SawOsc saw;
    
    void setup() {
       // Create sawtooth wave oscillator.
       saw = new SawOsc(this);
       saw.play();
      }
    
     void loop() {
     }
    

SqrOsc

  • Constructor: SqrOsc(theParent)

  • Description: This is a simple Square Wave Oscillator.

  • Methods:

  • play(): Starts the oscillator

  • set(): Set multiple parameters at once

  • freq(): Set the frequency of the oscillator in Hz.

  • amp(): Set the amplitude/volume of the oscillator

  • add(): Offset the output of the oscillator by given value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the oscillator.

  • Example:

     import processing.sound.*;
     SqrOsc square;
    
    void setup() {
       // Create square wave oscillator.
       square = new SqrOsc(this);
       square.play();
      }
    
     void loop() {
     }
    

TriOsc

  • Constructor: TriOsc(theParent)

  • Description: This is a simple Triangle Wave Oscillator.

  • Methods:

  • play(): Starts the oscillator

  • set(): Set multiple parameters at once

  • freq(): Set the frequency of the oscillator in Hz.

  • amp(): Set the amplitude/volume of the oscillator

  • add(): Offset the output of the oscillator by given value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the oscillator.

  • Example:

     import processing.sound.*;
     TriOsc tiangle;
    
    void setup() {
       // Create triangle wave oscillator.
       triangle = new TriOsc(this);
       triangle.play();
      }
    
     void loop() {
     }
    

Pulse

  • Constructor: Pulse(theParent)

  • Description: This is a simple Pulse Oscillator.

  • Methods:

  • play(): Starts the oscillator

  • set(): Set multiple parameters at once

  • freq(): Set the frequency of the oscillator in Hz.

  • amp(): Set the amplitude/volume of the oscillator

  • add(): Offset the output of the oscillator by given value

  • pan(): Move the sound in a stereo panorama

  • stop(): Stop the oscillator.

  • Example:

     import processing.sound.*;
     Pulse pulse;
    
     void setup() {
       // Create and start the sine oscillator.
       pulse = new Pulse(this);
    
       //Start the Pulse Oscillator.
       pulse.play();
     }
    
     void loop() {
     }
    

Env

  • Constructor: Env(theParent)

  • Description: This is a ASR Envelope Generator.

  • Methods:

  • play(): Triggers the envelope

  • Example:

     import processing.sound.*;
    
     TriOsc triOsc;
     Env env;
    
     float attackTime = 0.001;
     float sustainTime = 0.004;
     float sustainLevel = 0.3;
     float releaseTime = 0.4;
    
     void setup() {
        // Create triangle wave
       triOsc = new TriOsc(this);
    
       // Create the envelope
       env  = new Env(this);
     }
    
     void loop() {
     }
    

arduino-library-audio's People

Contributors

alfran avatar sergiotomasello avatar

Watchers

 avatar  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.