audio¶
audio is the module responsible for controlling the audio interface settings and audio stream.
Real-time audio processing is done by splitting into two processes: one main process and one process handling the audio
stream using a callback function.
Information is shared by multiprocessing.
The audio interface is controlled by sounddevice.
- class backlooper.audio.AudioStream(channels: int = 2, block_size: int = 1000, sample_rate: int | None = 44100, log_level: int = 10)¶
Bases:
objectAudioStreamcontrols the audio interface settings and audio stream. Thecallbackfunction is the real-time audio processing function, running in a separate process.- block_size: int = 1000¶
Number of samples that are handled at one time by the
callbackfunction.
- callback(indata, outdata, frames, callback_time, status)¶
The
callbackfunction is the real-time audio processing function, running in a separate process. This function must be able to return before the following buffer is handled to prevent audio clicks. There are three main parts:Saving the latest recorded audio
indata,Mixing in the tracks that are currently playing into
outdata,And mixing in the clicktrack into
outdata.
- channels: int = 2¶
Number of channels per track (stereo).
- property clicktrack_bpm¶
Wrapper around the
multiprocessing.Valueobject containing the tempo.
- property clicktrack_origin¶
Wrapper around the
multiprocessing.Valueobject containing the start time of the clicktrack.
- property clicktrack_volume: float¶
Wrapper around the
multiprocessing.Valueobject containing the clicktrack volume.
- property latency_seconds¶
Wrapper around the
multiprocessing.Valueobject containing the latency in seconds.
- log_level: int = 10¶
Log level
- property origin¶
Wrapper around the
multiprocessing.Valueobject containing the first execution time of the callback function.
- play()¶
Starts the audio stream in a separate process.
- read(start_timestamp: float, end_timestamp: float) array¶
Reads a
np.arraywith recorded audio between time intervalstart_timestampandend_timestamp.
- reset_loop(track_id: int)¶
Stops the loop for track
track_id.
- run()¶
Starts the audio stream and waits indefinitely.
- sample_rate: int | None = 44100¶
Sample rate of the audio interface.
- set_start_end_loop(start_time_value: float, end_time_value: float, track_id: int, offset: float = 0)¶
Configures the audio stream to start looping an interval between
start_time_valueandend_time_valuefor a tracktrack_id. The offset allows the start of the track to be adjusted: otherwise the track could start in the middle, because the callback function “wraps around” the track automatically (irrespectively of whether the track was playing or not).
- write(start_timestamp: float, array_to_store: array, overwrite: bool = True)¶
Writes a
np.arraywith recorded audio starting at timestart_timestamp.