Class: Phidgets::SoundSensor

Inherits:
Common
  • Object
show all
Defined in:
lib/phidgets/sound_sensor.rb,
ext/phidgets/phidgets_sound_sensor.c

Constant Summary collapse

SPL_RANGE_102dB =
INT2NUM(SPL_RANGE_102dB)
SPL_RANGE_82dB =
INT2NUM(SPL_RANGE_82dB)

Instance Method Summary collapse

Methods inherited from Common

#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel

Constructor Details

#newObject

Creates a Phidget SoundSensor object.



7
8
9
10
11
# File 'ext/phidgets/phidgets_sound_sensor.c', line 7

VALUE ph_sound_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetSoundSensor_create((PhidgetSoundSensorHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#getDataIntervalObject Also known as: data_interval

The DataInterval is the time that must elapse before the channel will fire another SPLChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between SPLChange events can also affected by the SPLChangeTrigger.



13
14
15
# File 'ext/phidgets/phidgets_sound_sensor.c', line 13

VALUE ph_sound_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getDataInterval);
}

#getdBObject Also known as: db

The most recent dB SPL value that has been calculated. This value is bounded by MaxdB.



30
31
32
# File 'ext/phidgets/phidgets_sound_sensor.c', line 30

VALUE ph_sound_get_db(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdB);
}

#getdBAObject Also known as: dba

The most recent dBA SPL value that has been calculated. The dBA SPL value is calculated by applying a A-weighted filter to the Octaves data.



38
39
40
# File 'ext/phidgets/phidgets_sound_sensor.c', line 38

VALUE ph_sound_get_dba(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdBA);
}

#getdBCObject Also known as: dbc

The most recent dBC SPL value that has been calculated. The dBC SPL value is calculated by applying a C-weighted filter to the Octaves data.



42
43
44
# File 'ext/phidgets/phidgets_sound_sensor.c', line 42

VALUE ph_sound_get_dbc(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdBC);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



26
27
28
# File 'ext/phidgets/phidgets_sound_sensor.c', line 26

VALUE ph_sound_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getMaxDataInterval);
}

#getMaxdBObject Also known as: max_db

The maximum value the SPLChange event will report.



34
35
36
# File 'ext/phidgets/phidgets_sound_sensor.c', line 34

VALUE ph_sound_get_max_db(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMaxdB);
}

#getMaxSPLChangeTriggerObject Also known as: max_spl_change_trigger

The maximum value that SPLChangeTrigger can be set to.



69
70
71
# File 'ext/phidgets/phidgets_sound_sensor.c', line 69

VALUE ph_sound_get_max_spl_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMaxSPLChangeTrigger);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



22
23
24
# File 'ext/phidgets/phidgets_sound_sensor.c', line 22

VALUE ph_sound_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getMinDataInterval);
}

#getMinSPLChangeTriggerObject Also known as: min_spl_change_trigger

The minimum value that SPLChangeTrigger can be set to.



65
66
67
# File 'ext/phidgets/phidgets_sound_sensor.c', line 65

VALUE ph_sound_get_min_spl_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMinSPLChangeTrigger);
}

#getNoiseFloorObject Also known as: noise_floor

The minimum SPL value that the channel can accurately measure. Input SPLs below this level will not produce an output from the microphone.



46
47
48
# File 'ext/phidgets/phidgets_sound_sensor.c', line 46

VALUE ph_sound_get_noise_floor(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getNoiseFloor);
}

#getOctavesObject Also known as: octaves

The unweighted value of each frequency band. The following frequency bands are represented:

octaves[0] = 31.5 Hz
octaves[1] = 63 Hz
octaves[2] = 125 Hz
octaves[3] = 250 Hz
octaves[4] = 500 Hz
octaves[5] = 1 kHz
octaves[6] = 2 kHz
octaves[7] = 4 kHz
octaves[8] = 8 kHz
octaves[9] = 16 kHz


50
51
52
53
54
# File 'ext/phidgets/phidgets_sound_sensor.c', line 50

VALUE ph_sound_get_octaves(VALUE self) {
  double octaves[10];
  ph_raise(PhidgetSoundSensor_getOctaves((PhidgetSoundSensorHandle)get_ph_handle(self), &octaves));
  return rb_ary_new3(10, DBL2NUM(octaves[0]), DBL2NUM(octaves[1]), DBL2NUM(octaves[2]), DBL2NUM(octaves[3]), DBL2NUM(octaves[4]), DBL2NUM(octaves[5]), DBL2NUM(octaves[6]), DBL2NUM(octaves[7]), DBL2NUM(octaves[8]), DBL2NUM(octaves[9]));
}

#getSPLChangeTriggerObject Also known as: spl_change_trigger

The channel will not issue a SPLChange event until the dB value has changed by the amount specified by the SPLChangeTrigger. Setting the SPLChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.



56
57
58
# File 'ext/phidgets/phidgets_sound_sensor.c', line 56

VALUE ph_sound_get_spl_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getSPLChangeTrigger);
}

#getSPLRangeObject Also known as: spl_range

When selecting a range, first decide how sensitive you want the microphone to be. Select a smaller range when you want more sensitivity from the microphone. If a Saturation event occurrs, increase the range.



73
74
75
# File 'ext/phidgets/phidgets_sound_sensor.c', line 73

VALUE ph_sound_get_spl_range(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetSoundSensor_getSPLRange);
}

#setDataInterval(interval) ⇒ Object Also known as: data_interval=

The DataInterval is the time that must elapse before the channel will fire another SPLChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between SPLChange events can also affected by the SPLChangeTrigger.



17
18
19
20
# File 'ext/phidgets/phidgets_sound_sensor.c', line 17

VALUE ph_sound_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetSoundSensor_setDataInterval((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
  return Qnil;
}

#setOnSPLChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_spl_change

call-seq:

setOnSPLChangeHandler(proc=nil, &block)

Assigns a handler that will be called when the SPLChange event occurs.



11
12
13
14
15
# File 'lib/phidgets/sound_sensor.rb', line 11

def setOnSPLChangeHandler(cb_proc = nil, &cb_block)
  @on_spl_change_thread.kill if defined? @on_spl_change_thread and @on_spl_change_thread.alive?
  callback = cb_proc || cb_block
  @on_spl_change_thread = Thread.new {ext_setOnSPLChangeHandler(callback)}
end

#setSPLChangeTrigger(change_trigger) ⇒ Object Also known as: spl_change_trigger=

The channel will not issue a SPLChange event until the dB value has changed by the amount specified by the SPLChangeTrigger. Setting the SPLChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.



60
61
62
63
# File 'ext/phidgets/phidgets_sound_sensor.c', line 60

VALUE ph_sound_set_spl_change_trigger(VALUE self, VALUE change_trigger) {
  ph_raise(PhidgetSoundSensor_setSPLChangeTrigger((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
  return Qnil;
}

#setSPLRange(spl_range) ⇒ Object Also known as: spl_range=

When selecting a range, first decide how sensitive you want the microphone to be. Select a smaller range when you want more sensitivity from the microphone. If a Saturation event occurrs, increase the range.



77
78
79
80
# File 'ext/phidgets/phidgets_sound_sensor.c', line 77

VALUE ph_sound_set_spl_range(VALUE self, VALUE spl_range) {
  ph_raise(PhidgetSoundSensor_setSPLRange((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2INT(spl_range)));
  return Qnil;
}