home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / Util.C < prev    next >
Encoding:
C/C++ Source or Header  |  2004-08-24  |  2.6 KB  |  102 lines

  1. /*
  2.   ZynAddSubFX - a software synthesizer
  3.  
  4.   Util.C - Miscellaneous functions
  5.   Copyright (C) 2002-2004 Nasca Octavian Paul
  6.   Author: Nasca Octavian Paul
  7.  
  8.   This program is free software; you can redistribute it and/or modify
  9.   it under the terms of version 2 of the GNU General Public License 
  10.   as published by the Free Software Foundation.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License (version 2) for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License (version 2)
  18.   along with this program; if not, write to the Free Software Foundation,
  19.   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  20.  
  21. */
  22.  
  23. #include "Util.h"
  24. #include <math.h>
  25. #include <stdio.h>
  26.  
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include <fcntl.h>
  30. #include <unistd.h>
  31. #include <errno.h>
  32. #include <string.h>
  33.  
  34. int SAMPLE_RATE=44100;
  35. int SOUND_BUFFER_SIZE=256;
  36. int OSCIL_SIZE=512;
  37.  
  38.  
  39. Config config;
  40. REALTYPE *denormalkillbuf;
  41.  
  42.  
  43. /*
  44.  * Transform the velocity according the scaling parameter (velocity sensing)
  45.  */
  46. REALTYPE VelF(REALTYPE velocity,unsigned char scaling){
  47.     REALTYPE x;
  48.     x=pow(VELOCITY_MAX_SCALE,(64.0-scaling)/64.0);
  49.     if ((scaling==127)||(velocity>0.99)) return(1.0);
  50.        else return(pow(velocity,x));
  51. };
  52.  
  53. /*
  54.  * Get the detune in cents 
  55.  */
  56. REALTYPE getdetune(unsigned char type,unsigned short int coarsedetune,unsigned short int finedetune){
  57.     REALTYPE det=0.0,octdet=0.0,cdet=0.0,findet=0.0;
  58.     //Get Octave
  59.     int octave=coarsedetune/1024;
  60.     if (octave>=8) octave-=16;
  61.     octdet=octave*1200.0;
  62.  
  63.     //Coarse and fine detune
  64.     int cdetune=coarsedetune%1024;
  65.     if (cdetune>512) cdetune-=1024;
  66.     
  67.     int fdetune=finedetune-8192;
  68.  
  69.     switch (type){
  70. //    case 1: is used for the default (see below)
  71.     case 2:    cdet=fabs(cdetune*10.0);
  72.         findet=fabs(fdetune/8192.0)*10.0;
  73.         break;
  74.     case 3:    cdet=fabs(cdetune*100);
  75.         findet=pow(10,fabs(fdetune/8192.0)*3.0)/10.0-0.1;
  76.         break;
  77.     case 4:    cdet=fabs(cdetune*701.95500087);//perfect fifth
  78.         findet=(pow(2,fabs(fdetune/8192.0)*12.0)-1.0)/4095*1200;
  79.         break;
  80.       //case ...: need to update N_DETUNE_TYPES, if you'll add more
  81.     default:cdet=fabs(cdetune*50.0);
  82.         findet=fabs(fdetune/8192.0)*35.0;//almost like "Paul's Sound Designer 2"
  83.         break;
  84.     };
  85.     if (finedetune<8192) findet=-findet;
  86.     if (cdetune<0) cdet=-cdet;
  87.     
  88.     det=octdet+cdet+findet;
  89.     return(det);
  90. };
  91.  
  92.  
  93. bool fileexists(char *filename){
  94.     struct stat tmp;
  95.     int result=stat(filename,&tmp);
  96.     if (result>=0) return(true);
  97.     
  98.     return(false);
  99. };
  100.  
  101.  
  102.