Class: PaddleC::PulseAudio::SampleFormat
- Inherits:
-
Object
- Object
- PaddleC::PulseAudio::SampleFormat
- Defined in:
- ext/paddlec/pulseaudio.c,
ext/paddlec/pulseaudio.c
Overview
Describe the data type in wich elements of a sample frame are stored.
Class Method Summary collapse
-
.symbols ⇒ Array<Symbol>
Return an array of valid formats as symbols.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#big_endian? ⇒ Boolean?
Returns
truewhen the format is big endian,falsewhen little endian. - #initialize(val) ⇒ PaddleC::PulseAudio::SampleFormat constructor
-
#inspect ⇒ String
Return the PulseAudio name of the sample format.
-
#little_endian? ⇒ Boolean?
Returns
truewhen the format is little endian,falsewhen big endian. -
#size ⇒ Integer?
Returns size in bytes of the format.
-
#to_s ⇒ String
Return a descriptive string for the sample format.
-
#to_sym ⇒ Symbol?
A symbol, or
nilif the format is invalid. -
#valid? ⇒ Boolean
Tell if the format is a valid sample format.
Constructor Details
#initialize(val) ⇒ PaddleC::PulseAudio::SampleFormat
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/paddlec/pulseaudio.c', line 196
static VALUE paddlec_pulseaudio_sample_format_initialize(VALUE self, VALUE val)
{
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (rb_obj_is_kind_of(val, rb_cSymbol))
val = rb_funcallv(val, rb_intern("to_s"), 0, NULL);
if (rb_obj_is_kind_of(val, rb_cString))
*format = pa_parse_sample_format(StringValueCStr(val));
else if (rb_obj_is_kind_of(val, rb_cInteger))
*format = (pa_sample_format_t)NUM2INT(val);
else if (rb_obj_is_kind_of(val, c_PASampleFormat))
*format = paddlec_pulseaudio_sample_format_get_val(val);
else
rb_raise(rb_eTypeError, "expecting a String, a Symbol, an Integer or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_PASampleFormat), rb_class_name(rb_class_of(val)));
if (*format < 0 || *format >= PA_SAMPLE_MAX)
*format = PA_SAMPLE_INVALID;
return self;
}
|
Class Method Details
.symbols ⇒ Array<Symbol>
Return an array of valid formats as symbols.
434 435 436 437 438 439 440 441 442 443 444 |
# File 'ext/paddlec/pulseaudio.c', line 434
static VALUE paddlec_pulseaudio_sample_format_symbols(VALUE self)
{
VALUE res;
int i;
res = rb_ary_new_capa(PA_SAMPLE_MAX);
for (i = 0; i < (int)PA_SAMPLE_MAX; i++)
rb_ary_store(res, i, ID2SYM(rb_intern(pa_sample_format_to_string((pa_sample_format_t)i))));
return res;
}
|
Instance Method Details
#==(other) ⇒ Boolean
417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'ext/paddlec/pulseaudio.c', line 417
static VALUE paddlec_pulseaudio_sample_format_isequ(VALUE self, VALUE other)
{
const pa_sample_format_t *myformat, *hisformat;
if (rb_class_of(other) != c_PASampleFormat)
return Qfalse;
myformat = paddlec_pulseaudio_sample_format_get_struct(self);
hisformat = paddlec_pulseaudio_sample_format_get_struct(other);
return ((*hisformat == *myformat) ? Qtrue : Qfalse);
}
|
#big_endian? ⇒ Boolean?
Returns true when the format is big endian, false when little endian. Returns nil when endianness does not apply to the format, or endianess is unknown.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'ext/paddlec/pulseaudio.c', line 365
static VALUE paddlec_pulseaudio_sample_format_is_be(VALUE self)
{
VALUE res;
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (!pa_sample_format_valid(*format)) {
res = Qnil;
}
else {
switch (pa_sample_format_is_be(*format)) {
case 1:
res = Qtrue;
break;
case 0:
res = Qfalse;
break;
default:
res = Qnil;
}
}
return res;
}
|
#inspect ⇒ String
Return the PulseAudio name of the sample format.
270 271 272 273 274 275 |
# File 'ext/paddlec/pulseaudio.c', line 270
static VALUE paddlec_pulseaudio_sample_format_inspect(VALUE self)
{
const char *s;
s = paddlec_pulseaudio_sample_format_inspect_cstr(self);
return rb_utf8_str_new_cstr(s);
}
|
#little_endian? ⇒ Boolean?
Returns true when the format is little endian, false when big endian. Returns nil when endianness does not apply to the format, or endianess is unknown.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/paddlec/pulseaudio.c', line 334
static VALUE paddlec_pulseaudio_sample_format_is_le(VALUE self)
{
VALUE res;
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (!pa_sample_format_valid(*format)) {
res = Qnil;
}
else {
switch (pa_sample_format_is_le(*format)) {
case 1:
res = Qtrue;
break;
case 0:
res = Qfalse;
break;
default:
res = Qnil;
}
}
return res;
}
|
#size ⇒ Integer?
Returns size in bytes of the format. Returns nil when invalid.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'ext/paddlec/pulseaudio.c', line 396
static VALUE paddlec_pulseaudio_sample_format_size(VALUE self)
{
VALUE res;
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (!pa_sample_format_valid(*format)) {
res = Qnil;
}
else {
res = ULONG2NUM(pa_sample_size_of_format(*format));
}
return res;
}
|
#to_s ⇒ String
Return a descriptive string for the sample format.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'ext/paddlec/pulseaudio.c', line 294
static VALUE paddlec_pulseaudio_sample_format_to_s(VALUE self)
{
VALUE res;
pa_sample_format_t *format;
const char *s;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (!pa_sample_format_valid(*format))
res = rb_sprintf("Invalid sample format");
else {
s = pa_sample_format_to_string(*format);
res = rb_utf8_str_new_cstr(s);
}
return res;
}
|
#to_sym ⇒ Symbol?
Returns a symbol, or nil if the format is invalid.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'ext/paddlec/pulseaudio.c', line 314
static VALUE paddlec_pulseaudio_sample_format_to_sym(VALUE self)
{
VALUE res;
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
if (!pa_sample_format_valid(*format))
res = Qnil;
else {
res = ID2SYM(rb_intern(pa_sample_format_to_string(*format)));
}
return res;
}
|
#valid? ⇒ Boolean
Tell if the format is a valid sample format.
281 282 283 284 285 286 287 288 |
# File 'ext/paddlec/pulseaudio.c', line 281
static VALUE paddlec_pulseaudio_sample_format_is_valid(VALUE self)
{
pa_sample_format_t *format;
format = paddlec_pulseaudio_sample_format_get_struct(self);
return (pa_sample_format_valid(*format) ? Qtrue : Qfalse);
}
|