Changeset 3416:aeaea539f960 in roaraudio


Ignore:
Timestamp:
02/11/10 19:23:00 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

implemented most of the rest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/sample.c

    r3415 r3416  
    112112 const char * name; 
    113113} _roar_pa_format[] = { 
    114  {PA_SAMPLE_INVALID, NULL} 
     114 {PA_SAMPLE_U8,     "u8"   }, 
     115 {PA_SAMPLE_ALAW,   "aLaw" }, 
     116 {PA_SAMPLE_ULAW,   "uLaw" }, 
     117 {PA_SAMPLE_S16LE,  "s16le"}, 
     118 {PA_SAMPLE_S16BE,  "s16be"}, 
     119 {PA_SAMPLE_INVALID, NULL  } 
    115120}; 
    116121 
    117 const char *pa_sample_format_to_string(pa_sample_format_t f); 
     122const char *pa_sample_format_to_string(pa_sample_format_t f) { 
     123 int i; 
     124 
     125 for (i = 0; _roar_pa_format[i].name != NULL; i++) 
     126  if ( _roar_pa_format[i].format == f ) 
     127   return _roar_pa_format[i].name; 
     128 
     129 return NULL; 
     130} 
    118131 
    119132/** Parse a sample format text. Inverse of pa_sample_format_to_string() */ 
    120 pa_sample_format_t pa_parse_sample_format(const char *format); 
     133pa_sample_format_t pa_parse_sample_format(const char *format) { 
     134 int i; 
     135 
     136 for (i = 0; _roar_pa_format[i].name != NULL; i++) 
     137  if ( !strcasecmp(_roar_pa_format[i].name, format) ) 
     138   return _roar_pa_format[i].format; 
     139 
     140 return PA_SAMPLE_INVALID; 
     141} 
    121142 
    122143/** Maximum required string length for pa_sample_spec_snprint() */ 
     
    124145 
    125146/** Pretty print a sample type specification to a string */ 
    126 char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec); 
     147char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) { 
     148 if ( s == NULL || l == 0 || spec == NULL ) 
     149  return NULL; 
     150 
     151 if ( pa_sample_spec_valid(spec) ) { 
     152  snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels, spec->rate); 
     153 } else { 
     154  snprintf(s, l, "Invalid"); 
     155 } 
     156 
     157 return s; 
     158} 
    127159 
    128160/** Pretty print a byte size value. (i.e. "2.5 MiB") */ 
    129 char* pa_bytes_snprint(char *s, size_t l, unsigned v); 
     161char* pa_bytes_snprint(char *s, size_t l, unsigned v) { 
     162 double val = v; 
     163 int    i; 
     164 const char pre[] = "KMGTP"; 
     165 
     166 if ( v <= 1024 ) { 
     167  snprintf(s, l, "%u B", v); 
     168  return s; 
     169 } 
     170 
     171 for (i = 0; pre[i] != 0; i++) { 
     172  val /= 1024; 
     173  if ( val <= 1024 ) { 
     174   snprintf(s, l, "%0.1f %ciB", val, pre[i]); 
     175   return s; 
     176  } 
     177 } 
     178 
     179 snprintf(s, l, "%0.1f %ciB", val*1024., pre[i-1]); 
     180 return s; 
     181} 
    130182 
    131183//ll 
Note: See TracChangeset for help on using the changeset viewer.