Changeset 6007:54e5f37d531c in roaraudio


Ignore:
Timestamp:
04/12/14 12:37:36 (10 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_str2usec()

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/libroar.h

    r5961 r6007  
    236236                            } 
    237237 
     238int_least32_t roar_str2usec(const char * str); 
    238239int roar_usleep(uint_least32_t t); 
    239240int roar_sleep(int t); 
  • libroar/libroar.c

    r5961 r6007  
    9999} 
    100100 
     101int_least32_t roar_str2usec(const char * str) { 
     102 int_least32_t man = 0, expo = 0, extra_expo = 0; 
     103 int_least32_t * cur = &man; 
     104 register unsigned char c; 
     105 int mneg = 0, eneg = 0; 
     106 int * neg = &mneg; 
     107 int after_point = 0; 
     108 
     109 for (; (c = *str); str++) { 
     110  if ( c >= '0' && c <= '9' ) { 
     111   *cur *= 10; 
     112   *cur += c - '0'; 
     113   if ( after_point ) 
     114    extra_expo--; 
     115  } else if ( c == '.' ) { 
     116   after_point = 1; 
     117  } else if ( c == '-' ) { 
     118   *neg = 1; 
     119  } else if ( c == '+' ) { 
     120   *neg = 0; 
     121  } else if ( c == 'e' ) { 
     122   cur = &expo; 
     123   neg = &eneg; 
     124   after_point = 0; 
     125  } else if ( c == 'm' ) { 
     126   extra_expo += -3; 
     127  } else if ( c == 'u' || c == 181 ) { 
     128   extra_expo += -6; 
     129  } else if ( c == 's' ) { 
     130   // ignore. 
     131  } 
     132 } 
     133 
     134 if ( eneg ) 
     135  expo *= -1; 
     136 
     137 expo += 6 + extra_expo; 
     138 
     139 if ( expo < 0 ) { 
     140  for (; expo; expo++) 
     141   man /= 10; 
     142 } else if ( expo > 0 ) { 
     143  for (; expo; expo--) 
     144   man *= 10; 
     145 } 
     146 
     147 return mneg ? -man : man; 
     148} 
     149 
    101150int roar_usleep(uint_least32_t t) { 
    102151#ifdef ROAR_TARGET_WIN32 
  • plugins/universal/filter-slfi-random.c

    r6005 r6007  
    100100 
    101101  if ( !strcmp(kv->key, "time-max") ) { 
    102    time_max = atoi(kv->value); 
     102   time_max = roar_str2usec(kv->value); 
    103103   if ( time_max < 0 ) 
    104104    time_max = 2000000L; 
Note: See TracChangeset for help on using the changeset viewer.