Advertisement
Guest User

SsPitchFromNote

a guest
May 23rd, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. // Frequency = (Pitch * 44100) >> 12;
  2.  
  3. USHORT _svm_ptable[]=
  4. {
  5.     4096, 4110, 4125, 4140, 4155, 4170, 4185, 4200,
  6.     4216, 4231, 4246, 4261, 4277, 4292, 4308, 4323,
  7.     4339, 4355, 4371, 4386, 4402, 4418, 4434, 4450,
  8.     4466, 4482, 4499, 4515, 4531, 4548, 4564, 4581,
  9.     4597, 4614, 4630, 4647, 4664, 4681, 4698, 4715,
  10.     4732, 4749, 4766, 4783, 4801, 4818, 4835, 4853,
  11.     4870, 4888, 4906, 4924, 4941, 4959, 4977, 4995,
  12.     5013, 5031, 5050, 5068, 5086, 5105, 5123, 5142,
  13.     5160, 5179, 5198, 5216, 5235, 5254, 5273, 5292,
  14.     5311, 5331, 5350, 5369, 5389, 5408, 5428, 5447,
  15.     5467, 5487, 5507, 5527, 5547, 5567, 5587, 5607,
  16.     5627, 5648, 5668, 5688, 5709, 5730, 5750, 5771,
  17.     5792, 5813, 5834, 5855, 5876, 5898, 5919, 5940,
  18.     5962, 5983, 6005, 6027, 6049, 6070, 6092, 6114,
  19.     6137, 6159, 6181, 6203, 6226, 6248, 6271, 6294,
  20.     6316, 6339, 6362, 6385, 6408, 6431, 6455, 6478,
  21.     6501, 6525, 6549, 6572, 6596, 6620, 6644, 6668,
  22.     6692, 6716, 6741, 6765, 6789, 6814, 6839, 6863,
  23.     6888, 6913, 6938, 6963, 6988, 7014, 7039, 7064,
  24.     7090, 7116, 7141, 7167, 7193, 7219, 7245, 7271,
  25.     7298, 7324, 7351, 7377, 7404, 7431, 7458, 7485,
  26.     7512, 7539, 7566, 7593, 7621, 7648, 7676, 7704,
  27.     7732, 7760, 7788, 7816, 7844, 7873, 7901, 7930,
  28.     7958, 7987, 8016, 8045, 8074, 8103, 8133, 8162,
  29.     8192
  30. };
  31.  
  32. SHORT SsPitchFromNote(SHORT note, SHORT fine, UCHAR center, UCHAR shift) {
  33.  
  34.     unsigned int pitch;
  35.     SHORT calc, type;
  36.     signed int add, sfine;//, ret;
  37.  
  38.     sfine=fine+shift;
  39.     if(sfine<0) sfine+=7;
  40.     sfine>>=3;
  41.  
  42.     add=0;
  43.     if(sfine>15)
  44.     {
  45.         add=1;
  46.         sfine-=16;
  47.     }
  48.    
  49.     calc=add+(note-(center-60));//((center + 60) - note) + add;
  50.     pitch=_svm_ptable[16*(calc%12)+(short)sfine];
  51.     type=calc/12-5;
  52.  
  53.     // regular shift
  54.     if(type>0) return pitch << type;
  55.     // negative shift
  56.     if(type<0) return pitch >> -type;
  57.  
  58.     return pitch;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement