PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Synth_envfuncs.cpp Source File

Synth_envfuncs.cpp

Go to the documentation of this file.
00001 /**************************************************************************/
00002 /*!
00003     @file     Synth_envfuncs.cpp
00004     @author   Jonne Valola
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2016, Jonne Valola
00011     All rights reserved.
00012 
00013     Redistribution and use in source and binary forms, with or without
00014     modification, are permitted provided that the following conditions are met:
00015     1. Redistributions of source code must retain the above copyright
00016     notice, this list of conditions and the following disclaimer.
00017     2. Redistributions in binary form must reproduce the above copyright
00018     notice, this list of conditions and the following disclaimer in the
00019     documentation and/or other materials provided with the distribution.
00020     3. Neither the name of the copyright holders nor the
00021     names of its contributors may be used to endorse or promote products
00022     derived from this software without specific prior written permission.
00023 
00024     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00025     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00028     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 */
00035 /**************************************************************************/
00036 
00037 #include "Synth.h "
00038 
00039 /** ENVELOPE FUNCTIONS **/
00040 
00041 void noADSR(OSC* o){
00042 }
00043 
00044 void attackFunc(OSC* o){
00045     if (o->adsrvol >= o->vol) {
00046         if (o->decay) {
00047             o->adsrvol = o->vol;
00048             o->adsrphase = 2;
00049         } else {
00050             o->adsrvol = o->sustain;
00051             o->adsrphase = 3;
00052         }
00053         return;
00054     }
00055     o->adsrvol += o->attack;
00056 }
00057 
00058 void decayFunc(OSC* o){
00059     if (o->adsrvol >= o->sustain + o->decay) {
00060         o->adsrvol -= o->decay;
00061         return;
00062     } else {
00063         o->adsrvol = o->sustain;
00064         o->adsrphase = 3;
00065     }
00066 }
00067 
00068 void releaseFunc(OSC* o){
00069     if (o->adsrvol > o->release) o->adsrvol -= o->release;
00070     else o->adsrvol = 0;
00071     if (!o->adsrvol) { // we have hit zero volume level
00072         if (o->loop) {
00073                 if (o->attack) {
00074                     o->adsrvol = 0;
00075                 } else {
00076                     o->adsrvol = o->vol;
00077                 }
00078                 if (o->echo) o->echodiv++;
00079                 o->adsrphase = 1;
00080                 return;
00081         }
00082         else {
00083                 o->adsrphase = 0;
00084                 o->adsrvol = 0;
00085                 return;
00086         }
00087     }
00088 }
00089 
00090 
00091 
00092 
00093