Guest User

Untitled

a guest
Feb 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1.  
  2. #include "ruby.h"
  3.  
  4. #include <stdio.h>
  5.  
  6. # line 65 "../lib/format.rb"
  7. static VALUE read_into(VALUE self, VALUE _file, VALUE _seek, VALUE _samples, VALUE _channels, VALUE _samplesize) {
  8. char * file = STR2CSTR(_file);
  9. int seek = FIX2INT(_seek);
  10. int samples = FIX2INT(_samples);
  11. int channels = FIX2INT(_channels);
  12. int samplesize = FIX2INT(_samplesize);
  13.  
  14. FILE *foo;
  15. int i, j;
  16. char blah[samplesize];
  17. VALUE data;
  18.  
  19. data = rb_ary_new2(channels);
  20. for(j = 0; j < channels; j++){
  21. rb_ary_push(data, rb_ary_new2(samples));
  22. }
  23.  
  24. foo = fopen(file, "r");
  25. fseek(foo, seek, SEEK_SET);
  26. for(i = 0; i < samples; i++){
  27. for(j = 0; j < channels; j++){
  28. fread(blah, samplesize, 1, foo);
  29. if(samplesize == 2){
  30. rb_ary_push(rb_funcall(data, rb_intern("[]"), 1, INT2FIX(j)), INT2FIX((unsigned short)*blah));
  31. }else{
  32. rb_ary_push(rb_funcall(data, rb_intern("[]"), 1, INT2FIX(j)), INT2FIX((unsigned char)*blah));
  33. }
  34. }
  35. }
  36. return (data);
  37. }
  38.  
  39.  
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. void Init_Inline_Wav_b2e0() {
  44. VALUE c = rb_cObject;
  45. c = rb_const_get_at(c,rb_intern("Wav"));
  46. rb_define_method(c, "read_into", (VALUE(*)(ANYARGS))read_into, 5);
  47.  
  48. }
  49. #ifdef __cplusplus
  50. }
  51. #endif
Add Comment
Please, Sign In to add comment