Class: Vdsp::DoubleFFT

Inherits:
Object
  • Object
show all
Includes:
FFT
Defined in:
ext/vdsp/vdsp.c

Constant Summary

Constants included from FFT

FFT::Radix2, FFT::Radix3, FFT::Radix5

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Vdsp::DoubleFFT



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File 'ext/vdsp/vdsp.c', line 1110

VALUE rb_double_fft_initialize(int argc, const VALUE *argv, VALUE self)
{
  rb_check_arity(argc, 1, 2);
  long length = NUM2LONG(argv[0]);
  FFTRadix radix = kFFTRadix2;
  if (argc==2) {
    radix = (FFTRadix)NUM2LONG(argv[1]);
  }

  VdspFFTNativeResource *p = ALLOC(VdspFFTNativeResource);
  p->type = 'd';
  p->length = 0;
  p->log2n = 0;
  p->radix = 0;
  p->setup.value = NULL;

  VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, vdsp_fft_native_resource_delete, p);
  rb_iv_set(self, "native_resource", resource);

  p->length = length;
  p->halflength = length / 2;
  p->log2n = log2(length);
  p->radix = radix;
  p->setup.d = vDSP_create_fftsetupD(p->log2n, radix);

  return self;
}

Instance Method Details

#forward(*args) ⇒ Object Also known as: forward_rect



1195
1196
1197
1198
1199
1200
1201
1202
# File 'ext/vdsp/vdsp.c', line 1195

VALUE rb_double_fft_forward(int argc, const VALUE *argv, VALUE self)
{
  rb_check_arity(argc, 1, 2);
  if (argc==2 && argv[1]!=Qnil) {
    return double_fft_forward_z(self, argv[0], argv[1]);
  }
  return double_fft_forward_r(self, argv[0]);
}

#forward_polar(*args) ⇒ Object



1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
# File 'ext/vdsp/vdsp.c', line 1263

VALUE rb_double_fft_forward_polar(int argc, const VALUE *argv, VALUE self)
{
  VALUE ri = rb_double_fft_forward(argc, argv, self);
  VALUE real = RARRAY_AREF(ri, 0);
  VALUE imag = RARRAY_AREF(ri, 1);

  VdspArrayNativeResource *_real = get_vdsp_array_native_resource(real);
  VdspArrayNativeResource *_imag = get_vdsp_array_native_resource(imag);

  DSPDoubleSplitComplex z;
  z.realp = _real->v.d;
  z.imagp = _imag->v.d;

  VALUE lenv = LONG2NUM(_real->length*2);
  VALUE tmp = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
  VdspArrayNativeResource *_tmp = get_vdsp_array_native_resource(tmp);

  vDSP_ztocD(&z, 1, (DSPDoubleComplex *)_tmp->v.d, 2, _real->length);
  vDSP_polarD(_tmp->v.d, 2, _tmp->v.d, 2, _real->length);
  vDSP_ctozD((DSPDoubleComplex *)_tmp->v.d, 2, &z, 1, _real->length);

  return rb_assoc_new(real, imag);
}

#inverse(real, imag) ⇒ Object Also known as: inverse_rect



1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
# File 'ext/vdsp/vdsp.c', line 1246

VALUE rb_double_fft_inverse(VALUE self, VALUE real, VALUE imag)
{
  VdspFFTNativeResource *_vf = get_vdsp_fft_native_resource(self);
  VdspArrayNativeResource *_real = get_vdsp_array_native_resource(real);
  VdspArrayNativeResource *_imag = get_vdsp_array_native_resource(imag);

  if (_vf->length==_real->length) {
    return double_fft_inverse_z(self, real, imag);

  } else if (_vf->halflength==_real->length) {
    return double_fft_inverse_r(self, real, imag);

  } else {
    rb_raise(rb_eArgError, "wrong length: Vdsp::FFT=%ld Vdsp::Array(real)=%ld Vdsp::Array(imag)=%ld", _vf->length, _real->length, _imag->length);
  }
}

#inverse_polar(mag, pha) ⇒ Object



1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
# File 'ext/vdsp/vdsp.c', line 1287

VALUE rb_double_fft_inverse_polar(VALUE self, VALUE mag, VALUE pha)
{
  VdspArrayNativeResource *_mag = get_vdsp_array_native_resource(mag);
  VdspArrayNativeResource *_pha = get_vdsp_array_native_resource(pha);

  DSPDoubleSplitComplex z;
  z.realp = _mag->v.d;
  z.imagp = _pha->v.d;

  VALUE lenv = LONG2NUM(_mag->length*2);
  VALUE tmp = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
  VdspArrayNativeResource *_tmp = get_vdsp_array_native_resource(tmp);

  vDSP_ztocD(&z, 1, (DSPDoubleComplex *)_tmp->v.d, 2, _mag->length);
  vDSP_rectD(_tmp->v.d, 2, _tmp->v.d, 2, _mag->length);
  vDSP_ctozD((DSPDoubleComplex *)_tmp->v.d, 2, &z, 1, _mag->length);

  return rb_double_fft_inverse(self, mag, pha);
}