Skip to content

Commit 0054dfa

Browse files
committed
CSDK-1843 improve virtual audio devices poor performance
We now create one frame per each device instead of one thread every time we call read_frames()/write_frames(). We also take into account time spent between calls since usually those will be done consecutively.
1 parent 47cd9ad commit 0054dfa

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

demos/audio/wav_audio_send.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ def send_wav_file(self, file_name):
9696
while not self.__app_quit and sent_frames < total_frames:
9797
# Read 100ms worth of audio frames.
9898
frames = wav.readframes(1600)
99-
frames_read = len(frames) / 2 # 16-bit linear PCM
100-
if frames_read > 0:
99+
if len(frames) > 0:
101100
self.__mic_device.write_frames(frames)
102-
sent_frames += frames_read
101+
sent_frames += 1600
103102

104103
def main():
105104
parser = argparse.ArgumentParser()

src/media/virtual_microphone_device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pyo3::types::PyBytes;
1010
/// devices are used to send audio to the meeting.
1111
///
1212
/// The audio format used by virtual microphone devices is 16-bit linear PCM.
13-
#[derive(Clone, Debug)]
13+
#[derive(Clone)]
1414
#[pyclass(name = "VirtualMicrophoneDevice", module = "daily")]
1515
pub struct PyVirtualMicrophoneDevice {
1616
device_name: String,
@@ -73,6 +73,12 @@ impl PyVirtualMicrophoneDevice {
7373
/// number of audio frames is not a multiple of 10ms worth of audio frames,
7474
/// silence will be added as padding.
7575
///
76+
/// To get low latency real time performance it is important that
77+
/// consecutive calls to this function don't take more time than the
78+
/// provided audio frames time. For example, if we provide audio frames
79+
/// every 10ms then we shouldn't take longer than 10ms to provide the next
80+
/// ones.
81+
///
7682
/// :param bytestring frames: A bytestring with the audio frames to write
7783
///
7884
/// :return: The number of audio frames written

src/media/virtual_speaker_device.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pyo3::types::PyBytes;
1010
/// used to receive audio from the meeting.
1111
///
1212
/// The audio format used by virtual speaker devices is 16-bit linear PCM.
13-
#[derive(Clone, Debug)]
13+
#[derive(Clone)]
1414
#[pyclass(name = "VirtualSpeakerDevice", module = "daily")]
1515
pub struct PyVirtualSpeakerDevice {
1616
device_name: String,
@@ -72,6 +72,11 @@ impl PyVirtualSpeakerDevice {
7272
/// should be able to read 160 audio frames (10ms), 320 (20ms), 480 (30ms),
7373
/// etc.
7474
///
75+
/// To get low latency real time performance it is important that
76+
/// consecutive calls to this function don't take more time than the
77+
/// requested audio frames time. For example, if we request audio frames
78+
/// every 10ms then we shouldn't take longer than 10ms to process them.
79+
///
7580
/// :param int num_frames: The number of audio frames to read
7681
///
7782
/// :return: The read audio frames as a bytestring. If no audio frames could be read, it returns an empty bytestring

0 commit comments

Comments
 (0)