Advertisement
Guest User

jdkdrum-fixpoint.patch

a guest
Oct 15th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.12 KB | None | 0 0
  1. diff -rupN jdkdrum/jdkdrum.c jdkdrum-fixpoint/jdkdrum.c
  2. --- jdkdrum/jdkdrum.c   2004-05-13 13:47:35.000000000 -0400
  3. +++ jdkdrum-fixpoint/jdkdrum.c  2015-10-14 21:57:48.000000000 -0400
  4. @@ -138,19 +138,19 @@ int merge_buffer(
  5.    signed short *buf,
  6.    int buflen,
  7.    int pos,
  8. -  float vol,
  9. -  float pan
  10. +  int vol,
  11. +  int pan
  12.    )
  13.  {
  14.    int i;
  15. -  float left_vol = (2.0-(pan+1.0))*0.5 * vol;
  16. -  float right_vol = (pan+1.0)*0.5 * vol;
  17. +  int left_vol = (65536-pan) * vol >> 16;
  18. +  int right_vol = pan * vol >> 16;
  19.    
  20.    for( i=0; i<buflen; i++ )
  21.    {           
  22.      
  23. -    audiobuf[(pos*2)+0] += (signed short)((float)buf[i] * left_vol);
  24. -    audiobuf[(pos*2)+1] += (signed short)((float)buf[i] * right_vol);
  25. +    audiobuf[(pos*2)+0] += (signed short)(((int)buf[i] * left_vol) >> 16);
  26. +    audiobuf[(pos*2)+1] += (signed short)(((int)buf[i] * right_vol) >> 16);
  27.      
  28.      pos++;
  29.      if( pos>repeatpos )
  30. @@ -169,15 +169,15 @@ int merge_read_file(
  31.    int repeatpos,
  32.    const char *fname,
  33.    int pos,
  34. -  float vol,
  35. -  float pan
  36. +  int vol,
  37. +  int pan
  38.    )
  39.  {
  40.    FILE *f = fopen(fname,"rb");
  41.    if( f )
  42.    {
  43. -    float left_vol = (2.0-(pan+1.0))*0.5 * vol;
  44. -    float right_vol = (pan+1.0)*0.5 * vol;
  45. +    int left_vol = (65536-pan) * vol >> 16;
  46. +    int right_vol = pan * vol >> 16;
  47.      
  48.      while( !feof(f) )
  49.      {         
  50. @@ -186,8 +186,8 @@ int merge_read_file(
  51.        if( fread(&val,2,1,f)!=1 )
  52.          break;
  53.        
  54. -      audiobuf[(pos*2)+0] += (signed short)((float)val * left_vol);
  55. -      audiobuf[(pos*2)+1] += (signed short)((float)val * right_vol);
  56. +      audiobuf[(pos*2)+0] += (signed short)(((int)val * left_vol) >> 16);
  57. +      audiobuf[(pos*2)+1] += (signed short)(((int)val * right_vol) >> 16);
  58.        
  59.        pos++;
  60.        if( pos>repeatpos )
  61. @@ -204,25 +204,25 @@ int merge_read_file(
  62.  }
  63.  
  64.  
  65. -
  66. +/**********************************
  67.  int merge_echo_read_file(
  68.    signed short *audiobuf,
  69.    int repeatpos,
  70.    const char *fname,
  71.    int pos,
  72. -  float vol,
  73. -  float pan,
  74. +  int vol,
  75. +  int pan,
  76.    int echo_left_time,
  77.    int echo_right_time,
  78. -  float echo_left_volume,
  79. -  float echo_right_volume
  80. +  int echo_left_volume,
  81. +  int echo_right_volume
  82.    )
  83.  {
  84.    FILE *f = fopen(fname,"rb");
  85.    if( f )
  86.    {
  87. -    float left_vol = (2.0-(pan+1.0))*0.5 * vol;
  88. -    float right_vol = (pan+1.0)*0.5 * vol;
  89. +    int left_vol = (65536-pan) * vol >> 16;
  90. +    int right_vol = pan * vol >> 16;
  91.      
  92.      while( !feof(f) )
  93.      {         
  94. @@ -232,16 +232,16 @@ int merge_echo_read_file(
  95.          break;
  96.        
  97.        audiobuf[(((pos+echo_left_time)%repeatpos)*2)+0]
  98. -        += (signed short)((float)val * echo_left_volume * left_vol );
  99. +        += (signed short)((int)val * echo_left_volume * left_vol) >> 16;
  100.        
  101.        audiobuf[(((pos+echo_right_time)%repeatpos)*2)+1]
  102. -        += (signed short)((float)val * echo_right_volume  * right_vol);
  103. +        += (signed short)((int)val * echo_right_volume  * right_vol) >> 16;
  104.        
  105. -      audiobuf[(pos*2)+1] += (signed short)((float)val * right_vol );
  106. +      audiobuf[(pos*2)+1] += (signed short)((int)val * right_vol) >> 16;
  107.        
  108.        
  109. -      audiobuf[(pos*2)+0] += (signed short)((float)val * left_vol);
  110. -      audiobuf[(pos*2)+1] += (signed short)((float)val * right_vol);
  111. +      audiobuf[(pos*2)+0] += (signed short)((int)val * left_vol) >> 16;
  112. +      audiobuf[(pos*2)+1] += (signed short)((int)val * right_vol) >> 16;
  113.        
  114.        pos++;
  115.        if( pos>repeatpos )
  116. @@ -258,7 +258,7 @@ int merge_echo_read_file(
  117.    
  118.    return -1;
  119.  }
  120. -
  121. +*****************************/
  122.  
  123.  
  124.  signed short * load_instrument(
  125. @@ -323,12 +323,12 @@ int merge_text_pattern(
  126.    {       
  127.      for( i=0; i<16; ++i )
  128.      {
  129. -      float vol=0.0f;
  130. -      float pan=(float)(rand()%200) / 100.0 - 1.0;
  131. +      int vol=0;
  132. +      int pan=rand() % 65536;
  133.        
  134.        if( pattern[i]>='1' && pattern[i]<='9' )
  135.        {
  136. -        vol = (pattern[i]-'0') * 0.1;
  137. +        vol = (pattern[i]-'0') * 65536 / 10;
  138.          merge_buffer(
  139.            audiobuf,
  140.            repeatpos,
  141. @@ -362,19 +362,22 @@ int merge_multi_pattern(
  142.  {
  143.    int i;
  144.    int step_position[16];  
  145. -  float tempo_bpm = 135.0;
  146. -  float tempo_bps;
  147. +  //float tempo_bpm = 135.0;
  148. +  int tempo_bpm = 135;
  149. +  //float tempo_bps;
  150.    int beats_per_measure=4;
  151.    int repeatpos;
  152.    signed short *audiobuf_to_use = audiobuf[audiobuf_current_playing^1];
  153.    
  154. -  fscanf( in, "%f", &tempo_bpm );
  155. +  //fscanf( in, "%f", &tempo_bpm );
  156. +  fscanf( in, "%d", &tempo_bpm );
  157.    if( feof(in) )
  158.      return -1;
  159.    
  160.    //fprintf( stderr, "%f\n", tempo_bpm );
  161. -  tempo_bps = tempo_bpm / 60
  162. -  repeatpos = (long)(((float)SAMPLE_RATE) / tempo_bps ) * beats_per_measure;
  163. +  //tempo_bps = tempo_bpm / 60;   
  164. +  //repeatpos = (long)(((float)(SAMPLE_RATE * 60)) / tempo_bpm ) * beats_per_measure;
  165. +  repeatpos = ((long)SAMPLE_RATE * 60 * beats_per_measure) / tempo_bpm;
  166.    
  167.    
  168.    for( i=0; i<16; ++i )
  169. diff -rupN jdkdrum/jdkdrum.h jdkdrum-fixpoint/jdkdrum.h
  170. --- jdkdrum/jdkdrum.h   2004-05-13 13:48:05.000000000 -0400
  171. +++ jdkdrum-fixpoint/jdkdrum.h  2015-10-14 10:23:14.000000000 -0400
  172. @@ -47,8 +47,8 @@ int merge_buffer(
  173.    signed short *buf,
  174.    int buflen,
  175.    int pos,
  176. -  float vol,
  177. -  float pan
  178. +  int vol,
  179. +  int pan
  180.    );
  181.  
  182.  int merge_read_file(
  183. @@ -56,8 +56,8 @@ int merge_read_file(
  184.    int repeatpos,
  185.    const char *fname,
  186.    int pos,
  187. -  float vol,
  188. -  float pan
  189. +  int vol,
  190. +  int pan
  191.    );
  192.  
  193.  int merge_echo_read_file(
  194. @@ -65,12 +65,12 @@ int merge_echo_read_file(
  195.    int repeatpos,
  196.    const char *fname,
  197.    int pos,
  198. -  float vol,
  199. -  float pan,
  200. +  int vol,
  201. +  int pan,
  202.    int echo_left_time,
  203.    int echo_right_time,
  204. -  float echo_left_volume,
  205. -  float echo_right_volume
  206. +  int echo_left_volume,
  207. +  int echo_right_volume
  208.    );
  209.  signed short * load_instrument(
  210.    const char *fname,
  211. diff -rupN jdkdrum/makefile jdkdrum-fixpoint/makefile
  212. --- jdkdrum/makefile    2003-01-18 05:31:21.000000000 -0500
  213. +++ jdkdrum-fixpoint/makefile   2015-10-15 08:24:38.596265630 -0400
  214. @@ -1,6 +1,7 @@
  215.  
  216.  CFLAGS = -O2 -g
  217. -LDFLAGS = -lm -lpthread
  218. +#LDFLAGS = -lm -lpthread
  219. +LDFLAGS = -lpthread
  220.  
  221.  all : jdkdrum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement