Recorder Parent¶
This module contains the abstract class to implement a proper Recorder Class. To do so, subclass RecorderParent when creating a new Recorder class.
- Example:
from RecorderParent import RecorderParent
- class newRecorder(RecorderParent):
If you have PyQt, it will import RecEmitter for emitting Signals.
Attributes¶
QT_EMITTER : Indicates whether you can use qt Signals
-
class
cued_datalogger.acquisition.RecorderParent.
RecorderParent
(channels=1, rate=44100, chunk_size=1024, num_chunk=4)¶ Bases:
object
Recorder abstract class. Sets up the buffer and skeleton for audio streaming
Attributes
channels: int Number of Channels rate: int Sampling rate chunk_size: int Number of samples to get from each channel in one chunk num_chunk: int Number of chunks to store in circular buffer recording: bool Indicate whether to record Methods
-
allocate_buffer
()¶ Set up the circular buffer
-
audiodata_to_array
(data)¶ Convert audio data obtained into a proper array
Parameters: data: Numpy Array
Audio data
-
available_devices
()¶ Displays all available device for streaming
-
chunk_size
¶ - int
- Number of samples to get from each channel in one chunk The setter method will calculate the maximum possible size based on an arbitrary number of sample limit (2^25 in here)
-
close
()¶ Close the audio object, to be called if streaming is no longer needed
-
current_device_info
()¶ Displays information about available the current device set
-
flush_record_data
()¶ Add in any partial posttrigger data Slice the recorded data into the requested amount of samples Add in any pretrigger data
Returns: flushed_data: numpy array
2D numpy array (similar to get_buffer)
-
get_buffer
()¶ Convert the buffer data as a 2D array by stitching the chunks together
Returns: Buffer data: Numpy Array
with dimension of(chunk_size * num_chunk) x channels The newest data on the most right
-
num_chunk
¶ - int
- Number of chunks to store in circular buffer The setter method will calculate the maximum possible number of chunks based on an arbitrary number of sample limit (2^25 in here)
-
open_recorder
()¶ Initialise the variables for recording.
-
record_cancel
()¶ Cancel a recording and clear any recorder data
-
record_data
(data)¶ Append recorded chunk to recorder_data and stop doing so if neccessary amount of chunks is recorded
-
record_init
(samples=None, duration=3)¶ Remove any pretrigger and postrigger data Calculate the number of chunk to record It will record more samples than necessary, then slice down to the amount of samples required + putting in pretrigger data
Parameters: samples: int
Number of samples to record
duration: int
The recording duration
-
record_start
()¶ Start recording if it is possible
Returns: bool
True if possible, False otherwise
-
set_device_by_name
(name)¶ Set the device to be used for audio streaming
-
show_stream_settings
()¶ Show the settings of the recorder
-
stream_close
()¶ Callback function for closing the audio streaming.
-
stream_init
(playback=False)¶ Callback function for initialising audio streaming.
Parameters: playback: bool
Whether to output the stream to a device
Returns: bool
True if successful, False otherwise
-
stream_start
()¶ Callback function for starting the audio streaming.
-
stream_stop
()¶ Callback function for stopping the audio streaming.
-
trigger_init
()¶ Initialise the variable for the trigger recording
-
trigger_start
(duration=3, threshold=0.09, channel=0, pretrig=200, posttrig=5000)¶ Start the trigger if possible
Returns: bool
True if successful, False otherwise
-
write_buffer
(data)¶ Write the data obtained into buffer and move to the next chunk
Parameters: data: Numpy Array
Audio data
-