Changeset 3416:aeaea539f960 in roaraudio
- Timestamp:
- 02/11/10 19:23:00 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/sample.c
r3415 r3416 112 112 const char * name; 113 113 } _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 } 115 120 }; 116 121 117 const char *pa_sample_format_to_string(pa_sample_format_t f); 122 const 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 } 118 131 119 132 /** Parse a sample format text. Inverse of pa_sample_format_to_string() */ 120 pa_sample_format_t pa_parse_sample_format(const char *format); 133 pa_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 } 121 142 122 143 /** Maximum required string length for pa_sample_spec_snprint() */ … … 124 145 125 146 /** 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); 147 char* 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 } 127 159 128 160 /** Pretty print a byte size value. (i.e. "2.5 MiB") */ 129 char* pa_bytes_snprint(char *s, size_t l, unsigned v); 161 char* 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 } 130 182 131 183 //ll
Note: See TracChangeset
for help on using the changeset viewer.