Class: Mpg123
- Inherits:
-
Object
- Object
- Mpg123
- Defined in:
- ext/mpg123/mpg123.c
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #length ⇒ Object
- #read(_size) ⇒ Object
- #seek(offset) ⇒ Object
- #seek_frame(offset) ⇒ Object
- #spf ⇒ Object
- #tell ⇒ Object
- #tellframe ⇒ Object
- #timeframe(seconds) ⇒ Object
- #tpf ⇒ Object
Class Method Details
.new(filename) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'ext/mpg123/mpg123.c', line 15
VALUE rb_mpg123_new(VALUE klass, VALUE filename) {
int err = MPG123_OK;
mpg123_handle *mh;
VALUE mpg123;
long rate;
int channels, encoding;
Check_Type(filename, T_STRING);
if ((mh = mpg123_new(NULL, &err)) == NULL) {
rb_raise(rb_eStandardError, "%s", mpg123_plain_strerror(err));
}
mpg123_param(mh, MPG123_ADD_FLAGS, MPG123_FORCE_FLOAT, 0.);
if (mpg123_open(mh, (char*) RSTRING_PTR(filename)) != MPG123_OK ||
mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK) {
rb_raise(rb_eStandardError, "%s", mpg123_strerror(mh));
}
if (encoding != MPG123_ENC_FLOAT_32) {
rb_raise(rb_eStandardError, "bad encoding");
}
mpg123_format_none(mh);
mpg123_format(mh, rate, channels, encoding);
return Data_Wrap_Struct(rb_cMpg123, 0, cleanup, mh);
}
|
Instance Method Details
#close ⇒ Object
45 46 47 48 49 |
# File 'ext/mpg123/mpg123.c', line 45
VALUE rb_mpg123_close(VALUE self)
{
mpg123_close(DATA_PTR(self));
return self;
}
|
#length ⇒ Object
78 79 80 81 |
# File 'ext/mpg123/mpg123.c', line 78
VALUE rb_mpg123_length(VALUE self)
{
return INT2FIX(mpg123_length(DATA_PTR(self)));
}
|
#read(_size) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'ext/mpg123/mpg123.c', line 52
VALUE rb_mpg123_read(VALUE self, VALUE _size)
{
int size = FIX2INT(_size);
float *buffer = malloc(size * sizeof(float));
VALUE result = rb_ary_new2(size);
mpg123_handle *mh = NULL;
size_t done = 0;
int i;
int err = MPG123_OK;
Data_Get_Struct(self, mpg123_handle, mh);
err = mpg123_read(mh, (unsigned char *) buffer, size * sizeof(float), &done);
if (err == MPG123_OK || err == MPG123_DONE) {
for (i = 0; i < size; i++) {
rb_ary_store(result, i, rb_float_new(buffer[i]));
}
free(buffer);
return result;
}
else {
free(buffer);
rb_raise(rb_eStandardError, "%s", mpg123_plain_strerror(err));
}
}
|
#seek(offset) ⇒ Object
103 104 105 106 |
# File 'ext/mpg123/mpg123.c', line 103
VALUE rb_mpg123_seek(VALUE self, VALUE offset)
{
return INT2FIX(mpg123_seek(DATA_PTR(self), FIX2INT(offset), SEEK_SET));
}
|
#seek_frame(offset) ⇒ Object
108 109 110 111 |
# File 'ext/mpg123/mpg123.c', line 108
VALUE rb_mpg123_seek_frame(VALUE self, VALUE offset)
{
return INT2FIX(mpg123_seek_frame(DATA_PTR(self), FIX2INT(offset), SEEK_SET));
}
|
#spf ⇒ Object
83 84 85 86 |
# File 'ext/mpg123/mpg123.c', line 83
VALUE rb_mpg123_spf(VALUE self)
{
return rb_float_new(mpg123_spf(DATA_PTR(self)));
}
|
#tell ⇒ Object
93 94 95 96 |
# File 'ext/mpg123/mpg123.c', line 93
VALUE rb_mpg123_tell(VALUE self)
{
return INT2FIX(mpg123_tell(DATA_PTR(self)));
}
|
#tellframe ⇒ Object
98 99 100 101 |
# File 'ext/mpg123/mpg123.c', line 98
VALUE rb_mpg123_tellframe(VALUE self)
{
return INT2FIX(mpg123_tellframe(DATA_PTR(self)));
}
|
#timeframe(seconds) ⇒ Object
113 114 115 116 |
# File 'ext/mpg123/mpg123.c', line 113
VALUE rb_mpg123_timeframe(VALUE self, VALUE seconds)
{
return INT2FIX(mpg123_timeframe(DATA_PTR(self), NUM2DBL(seconds)));
}
|
#tpf ⇒ Object
88 89 90 91 |
# File 'ext/mpg123/mpg123.c', line 88
VALUE rb_mpg123_tpf(VALUE self)
{
return rb_float_new(mpg123_tpf(DATA_PTR(self)));
}
|