Skip to content

Commit aa3f673

Browse files
committed
DOC: update regarding the blocking read()/write() methods
1 parent b7116d6 commit aa3f673

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,8 @@ Same thing with `sounddevice.RawStream`:
250250
Blocking Read/Write Streams
251251
^^^^^^^^^^^^^^^^^^^^^^^^^^^
252252

253-
Coming soon!
253+
Instead of using a callback function, you can also use the blocking methods
254+
`sounddevice.Stream.read()` and `sounddevice.Stream.write()` (and of course the
255+
corresponding methods in `sounddevice.InputStream`, `sounddevice.OutputStream`,
256+
`sounddevice.RawStream`, `sounddevice.RawInputStream` and
257+
`sounddevice.RawOutputStream`).

sounddevice.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,11 +1075,7 @@ def read_available(self):
10751075
return _check(_lib.Pa_GetStreamReadAvailable(self._ptr))
10761076

10771077
def read(self, frames):
1078-
"""Read samples from the stream.
1079-
1080-
The function doesn't return until all requested `frames` have
1081-
been read -- this may involve waiting for the operating system
1082-
to supply the data.
1078+
"""Read samples from the stream into a buffer.
10831079
10841080
This is the same as :meth:`Stream.read`, except that it returns
10851081
a plain Python buffer object instead of a NumPy array.
@@ -1088,11 +1084,7 @@ def read(self, frames):
10881084
Parameters
10891085
----------
10901086
frames : int
1091-
The number of frames to be read into `data`. This
1092-
parameter is not constrained to a specific range, however
1093-
high performance applications will want to match this
1094-
parameter to the `blocksize` parameter used when opening the
1095-
stream.
1087+
The number of frames to be read. See :meth:`Stream.read`.
10961088
10971089
Returns
10981090
-------
@@ -1103,8 +1095,7 @@ def read(self, frames):
11031095
specified by `channels`.
11041096
See also :attr:`Stream.samplesize`.
11051097
overflowed : bool
1106-
``True`` if input data was discarded by PortAudio after the
1107-
previous call and before this call.
1098+
See :meth:`Stream.read`.
11081099
11091100
"""
11101101
channels, _ = _split(self._channels)
@@ -1178,10 +1169,6 @@ def write_available(self):
11781169
def write(self, data):
11791170
"""Write samples to the stream.
11801171
1181-
This function doesn't return until the entire buffer has been
1182-
consumed -- this may involve waiting for the operating system to
1183-
consume the data.
1184-
11851172
This is the same as :meth:`Stream.write`, except that it expects
11861173
a plain Python buffer object instead of a NumPy array.
11871174
NumPy is not necessary to use this.
@@ -1201,8 +1188,7 @@ def write(self, data):
12011188
Returns
12021189
-------
12031190
underflowed : bool
1204-
``True`` if additional output data was inserted after the
1205-
previous call and before this call.
1191+
See :meth:`Stream.write`.
12061192
12071193
"""
12081194
try:
@@ -1339,23 +1325,23 @@ def callback_wrapper(iptr, optr, frames, time, status, _):
13391325
prime_output_buffers_using_stream_callback)
13401326

13411327
def read(self, frames):
1342-
"""Read samples from the stream.
1328+
"""Read samples from the stream into a NumPy array.
13431329
13441330
The function doesn't return until all requested `frames` have
13451331
been read -- this may involve waiting for the operating system
1346-
to supply the data.
1332+
to supply the data (except if no more than
1333+
:attr:`read_available` frames were requested).
13471334
13481335
This is the same as :meth:`RawStream.read`, except that it
13491336
returns a NumPy array instead of a plain Python buffer object.
13501337
13511338
Parameters
13521339
----------
13531340
frames : int
1354-
The number of frames to be read into `data`. This
1355-
parameter is not constrained to a specific range, however
1356-
high performance applications will want to match this
1357-
parameter to the `blocksize` parameter used when opening the
1358-
stream.
1341+
The number of frames to be read. This parameter is not
1342+
constrained to a specific range, however high performance
1343+
applications will want to match this parameter to the
1344+
`blocksize` parameter used when opening the stream.
13591345
13601346
Returns
13611347
-------
@@ -1425,7 +1411,8 @@ def write(self, data):
14251411
14261412
This function doesn't return until the entire buffer has been
14271413
consumed -- this may involve waiting for the operating system to
1428-
consume the data.
1414+
consume the data (except if `data` contains no more than
1415+
:attr:`write_available` frames).
14291416
14301417
This is the same as :meth:`RawStream.write`, except that it
14311418
expects a NumPy array instead of a plain Python buffer object.

0 commit comments

Comments
 (0)