Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ruby.h"
- #include <stdio.h>
- # line 65 "../lib/format.rb"
- static VALUE read_into(VALUE self, VALUE _file, VALUE _seek, VALUE _samples, VALUE _channels, VALUE _samplesize) {
- char * file = STR2CSTR(_file);
- int seek = FIX2INT(_seek);
- int samples = FIX2INT(_samples);
- int channels = FIX2INT(_channels);
- int samplesize = FIX2INT(_samplesize);
- FILE *foo;
- int i, j;
- char blah[samplesize];
- VALUE data;
- data = rb_ary_new2(channels);
- for(j = 0; j < channels; j++){
- rb_ary_push(data, rb_ary_new2(samples));
- }
- foo = fopen(file, "r");
- fseek(foo, seek, SEEK_SET);
- for(i = 0; i < samples; i++){
- for(j = 0; j < channels; j++){
- fread(blah, samplesize, 1, foo);
- if(samplesize == 2){
- rb_ary_push(rb_funcall(data, rb_intern("[]"), 1, INT2FIX(j)), INT2FIX((unsigned short)*blah));
- }else{
- rb_ary_push(rb_funcall(data, rb_intern("[]"), 1, INT2FIX(j)), INT2FIX((unsigned char)*blah));
- }
- }
- }
- return (data);
- }
- #ifdef __cplusplus
- extern "C" {
- #endif
- void Init_Inline_Wav_b2e0() {
- VALUE c = rb_cObject;
- c = rb_const_get_at(c,rb_intern("Wav"));
- rb_define_method(c, "read_into", (VALUE(*)(ANYARGS))read_into, 5);
- }
- #ifdef __cplusplus
- }
- #endif
Add Comment
Please, Sign In to add comment