acoular 24.10__py3-none-any.whl → 25.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
acoular/sdinput.py CHANGED
@@ -9,16 +9,19 @@
9
9
  SoundDeviceSamplesGenerator
10
10
  """
11
11
 
12
- from traits.api import Any, Bool, Float, Int, Long, Property, Trait, cached_property, observe
12
+ from traits.api import Any, Bool, Enum, Float, Int, Property, cached_property, observe
13
13
 
14
+ # acoular imports
14
15
  from .base import SamplesGenerator
15
16
  from .configuration import config
17
+ from .deprecation import deprecated_alias
16
18
  from .internal import digest
17
19
 
18
20
  if config.have_sounddevice:
19
21
  import sounddevice as sd
20
22
 
21
23
 
24
+ @deprecated_alias({'numchannels': 'num_channels', 'numsamples': 'num_samples', 'collectsamples': 'collect_samples'})
22
25
  class SoundDeviceSamplesGenerator(SamplesGenerator):
23
26
  """Controller for sound card hardware using sounddevice library.
24
27
 
@@ -37,14 +40,14 @@ class SoundDeviceSamplesGenerator(SamplesGenerator):
37
40
  device = Int(0, desc='input device index')
38
41
 
39
42
  #: Number of input channels, maximum depends on device
40
- numchannels = Long(1, desc='number of analog input channels that collects data')
43
+ num_channels = Int(1, desc='number of analog input channels that collects data')
41
44
 
42
- #: Number of samples to collect; defaults to -1.
43
- # If is set to -1 device collects till user breaks streaming by setting Trait: collectsamples = False
44
- numsamples = Long(-1, desc='number of samples to collect')
45
+ #: Number of samples to collect; defaults to -1. If is set to -1 device collects until user
46
+ # breaks streaming by setting Trait: collect_samples = False.
47
+ num_samples = Int(-1, desc='number of samples to collect')
45
48
 
46
49
  #: Indicates if samples are collected, helper trait to break result loop
47
- collectsamples = Bool(True, desc='Indicates if samples are collected')
50
+ collect_samples = Bool(True, desc='Indicates if samples are collected')
48
51
 
49
52
  #: Sampling frequency of the signal, changes with sinusdevices
50
53
  sample_freq = Property(desc='sampling frequency')
@@ -52,7 +55,7 @@ class SoundDeviceSamplesGenerator(SamplesGenerator):
52
55
  _sample_freq = Float(default_value=None)
53
56
 
54
57
  #: Datatype (resolution) of the signal, used as `dtype` in a sd `Stream` object
55
- precision = Trait('float32', 'float16', 'int32', 'int16', 'int8', 'uint8', desc='precision (resolution) of signal')
58
+ precision = Enum('float32', 'float16', 'int32', 'int16', 'int8', 'uint8', desc='precision (resolution) of signal')
56
59
 
57
60
  #: Indicates that the sounddevice buffer has overflown
58
61
  overflow = Bool(False, desc='Indicates if sounddevice buffer overflow')
@@ -64,16 +67,16 @@ class SoundDeviceSamplesGenerator(SamplesGenerator):
64
67
  stream = Any
65
68
 
66
69
  # internal identifier
67
- digest = Property(depends_on=['device', 'numchannels', 'numsamples'])
70
+ digest = Property(depends_on=['device', 'num_channels', 'num_samples'])
68
71
 
69
72
  @cached_property
70
73
  def _get_digest(self):
71
74
  return digest(self)
72
75
 
73
- # checks that numchannels are not more than device can provide
74
- @observe('device,numchannels')
75
- def _get_numchannels(self, event): # noqa ARG002
76
- self.numchannels = min(self.numchannels, sd.query_devices(self.device)['max_input_channels'])
76
+ # checks that num_channels are not more than device can provide
77
+ @observe('device, num_channels')
78
+ def _get_num_channels(self, event): # noqa ARG002
79
+ self.num_channels = min(self.num_channels, sd.query_devices(self.device)['max_input_channels'])
77
80
 
78
81
  def _get_sample_freq(self):
79
82
  if self._sample_freq is None:
@@ -102,14 +105,14 @@ class SoundDeviceSamplesGenerator(SamplesGenerator):
102
105
 
103
106
  Returns
104
107
  -------
105
- Samples in blocks of shape (num, :attr:`numchannels`).
108
+ Samples in blocks of shape (num, :attr:`num_channels`).
106
109
  The last block may be shorter than num.
107
110
 
108
111
  """
109
112
  print(self.device_properties(), self.sample_freq)
110
113
  self.stream = stream_obj = sd.InputStream(
111
114
  device=self.device,
112
- channels=self.numchannels,
115
+ channels=self.num_channels,
113
116
  clip_off=True,
114
117
  samplerate=self.sample_freq,
115
118
  dtype=self.precision,
@@ -117,15 +120,15 @@ class SoundDeviceSamplesGenerator(SamplesGenerator):
117
120
 
118
121
  with stream_obj as stream:
119
122
  self.running = True
120
- if self.numsamples == -1:
121
- while self.collectsamples: # yield data as long as collectsamples is True
123
+ if self.num_samples == -1:
124
+ while self.collect_samples: # yield data as long as collect_samples is True
122
125
  data, self.overflow = stream.read(num)
123
126
  yield data[:num]
124
127
 
125
- elif self.numsamples > 0: # amount of samples to collect is specified by user
126
- samples_count = 0 # numsamples counter
127
- while samples_count < self.numsamples:
128
- anz = min(num, self.numsamples - samples_count)
128
+ elif self.num_samples > 0: # amount of samples to collect is specified by user
129
+ samples_count = 0 # num_samples counter
130
+ while samples_count < self.num_samples:
131
+ anz = min(num, self.num_samples - samples_count)
129
132
  data, self.overflow = stream.read(num)
130
133
  yield data[:anz]
131
134
  samples_count += anz