Class: NoyesC::DCT

Inherits:
Object
  • Object
show all
Defined in:
lib/cext/discrete_cosine_transform.c

Instance Method Summary collapse

Constructor Details

#initializeObject


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cext/discrete_cosine_transform.c', line 11

static VALUE t_init(VALUE self, VALUE args) {
  int len = RARRAY_LEN(args);
  int rows=13,cols=32;
  if (len > 0)
     rows = NUM2INT(rb_ary_entry(args, 0));
  if (len > 1)
     cols = NUM2INT(rb_ary_entry(args, 1));

  DiscreteCosineTransform *dct = dct_new(rows,cols);
  VALUE dctv = Data_Wrap_Struct(cDiscreteCosineTransform, 0, _dct_free, dct);
  rb_iv_set(self, "@dct", dctv);
  return self;
}

Instance Method Details

#<<Object


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cext/discrete_cosine_transform.c', line 25

static VALUE t_left_shift(VALUE self, VALUE obj) {
  Cmat *M = r2cmat(obj);
  DiscreteCosineTransform *dct;
  VALUE dctv = rb_iv_get(self, "@dct");
  Data_Get_Struct(dctv, DiscreteCosineTransform, dct);
  Cmat *N = dct_apply(dct, M);
  VALUE result = cmat2r(N);
  cmat_free(N);
  cmat_free(M);
  return result;
}

#melcosObject


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cext/discrete_cosine_transform.c', line 37

static VALUE t_melcos(VALUE self) {
  DiscreteCosineTransform *dct;
  VALUE dctv = rb_iv_get(self, "@dct");
  Data_Get_Struct(dctv, DiscreteCosineTransform, dct);
  Cmat *N = cmat_new(dct->rows, dct->cols);
  int i;
  for (i=0;i<dct->rows;++i) {
    memcpy(N->data[i],dct->melcos[i], dct->cols * sizeof(double));
  }
  VALUE result = cmat2r(N);
  cmat_free(N);
  return result;
}