Stream control.
| 113 | |
| 114 | # Streaming class |
| 115 | class Streaming(PyTTaObj): |
| 116 | """Stream control.""" |
| 117 | |
| 118 | def __init__(self, |
| 119 | IO: str, |
| 120 | samplingRate: int, |
| 121 | device: int, |
| 122 | datatype: str = 'float32', |
| 123 | blocksize: int = 0, |
| 124 | inChannels: Optional[ChannelsList] = None, |
| 125 | outChannels: Optional[ChannelsList] = None, |
| 126 | excitation: Optional[SignalObj] = None, |
| 127 | duration: Optional[float] = None, |
| 128 | numSamples: Optional[int] = None, |
| 129 | monitor: Optional[Monitor] = None, |
| 130 | *args, **kwargs): |
| 131 | """ |
| 132 | Manage input and output of audio. |
| 133 | |
| 134 | Args: |
| 135 | IO (str): DESCRIPTION. |
| 136 | msmnt (Measurement): DESCRIPTION. |
| 137 | datatype (str, optional): DESCRIPTION. Defaults to 'float32'. |
| 138 | blocksize (int, optional): DESCRIPTION. Defaults to 0. |
| 139 | duration (Optional[float], optional): DESCRIPTION. Defaults to 5. |
| 140 | monitor (Optional[Monitor], optional): DESCRIPTION. Defaults to None. |
| 141 | *args (TYPE): DESCRIPTION. |
| 142 | **kwargs (TYPE): DESCRIPTION. |
| 143 | |
| 144 | Returns: |
| 145 | None. |
| 146 | |
| 147 | """ |
| 148 | |
| 149 | super().__init__(*args, **kwargs) |
| 150 | self._IO = IO.upper() |
| 151 | |
| 152 | self._samplingRate = samplingRate # registers samples per second |
| 153 | self._dataType = datatype # registers data type |
| 154 | self._blockSize = blocksize # registers blocksize |
| 155 | self._device = device |
| 156 | |
| 157 | if (type(duration) is float) or (type(duration) is int): |
| 158 | self._durationInSamples = int(np.ceil(duration*self.samplingRate)) |
| 159 | else: |
| 160 | self._durationInSamples = numSamples |
| 161 | self._duration = self.durationInSamples / self.samplingRate |
| 162 | |
| 163 | self.isFinished = Event() # block until finished |
| 164 | self.hasMonitor = Event() # prevent threading if no monitor |
| 165 | self.isRunning = Event() # stream and monitor synchronization |
| 166 | |
| 167 | self.statuses = [] # will register statuses passed by stream |
| 168 | if 'I' in self.IO: |
| 169 | self.inChannels = inChannels |
| 170 | self.recData = np.empty((self.durationInSamples, self.numInChannels), |
| 171 | dtype=self.dataType) |
| 172 | if 'O' in self.IO: |