Skip to content

Commit 747030a

Browse files
committed
DOC: A few documentation changes
1 parent 21df69e commit 747030a

File tree

3 files changed

+59
-38
lines changed

3 files changed

+59
-38
lines changed

CONTRIBUTING.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ If you prefer, you can also replace the last command with::
2525
... where ``-e`` stands for ``--editable``.
2626

2727
If you used the ``--recursive`` option when cloning, the dynamic libraries for
28-
Mac OS X and Windows should be available.
28+
*macOS* and *Windows* should already be available.
2929
If not, you can get the submodule with::
3030

3131
git submodule update --init
3232

33-
If you make changes to the documentation, you can re-create the HTML pages
34-
using Sphinx_.
33+
If you make changes to the documentation, you can locally re-create the HTML
34+
pages using Sphinx_.
3535
You can install it and a few other necessary packages with::
3636

3737
python3 -m pip install -r doc/requirements.txt --user

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ To record audio data from your sound device into a NumPy array, use
140140

141141
.. code:: python
142142
143-
duration = 10 # seconds
144-
myrecording = sd.rec(duration * fs, samplerate=fs, channels=2)
143+
duration = 10.5 # seconds
144+
myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=2)
145145
146146
Again, for repeated use you can set defaults using `sounddevice.default`:
147147

@@ -237,30 +237,30 @@ Callback "wire" with `sounddevice.Stream`:
237237
.. code:: python
238238
239239
import sounddevice as sd
240-
duration = 5 # seconds
240+
duration = 5.5 # seconds
241241
242242
def callback(indata, outdata, frames, time, status):
243243
if status:
244-
print(status, flush=True)
244+
print(status)
245245
outdata[:] = indata
246246
247247
with sd.Stream(channels=2, callback=callback):
248-
sd.sleep(duration * 1000)
248+
sd.sleep(int(duration * 1000))
249249
250250
Same thing with `sounddevice.RawStream`:
251251

252252
.. code:: python
253253
254254
import sounddevice as sd
255-
duration = 5 # seconds
255+
duration = 5.5 # seconds
256256
257257
def callback(indata, outdata, frames, time, status):
258258
if status:
259-
print(status, flush=True)
259+
print(status)
260260
outdata[:] = indata
261261
262262
with sd.RawStream(channels=2, dtype='int24', callback=callback):
263-
sd.sleep(duration * 1000)
263+
sd.sleep(int(duration * 1000))
264264
265265
.. note:: We are using 24-bit samples here for no particular reason
266266
(just because we can).

sounddevice.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,14 @@ def play(data, samplerate=None, mapping=None, blocking=False, loop=False,
352352
treated as mono data.
353353
The data types *float64*, *float32*, *int32*, *int16*, *int8*
354354
and *uint8* can be used.
355-
*float64* data is converted to *float32* before passing it to
356-
PortAudio, because it's not supported natively.
355+
*float64* data is simply converted to *float32* before passing
356+
it to PortAudio, because it's not supported natively.
357357
mapping : array_like, optional
358358
List of channel numbers (starting with 1) where the columns of
359359
*data* shall be played back on. Must have the same length as
360-
number of channels in *data* (except if *data* is mono).
361-
Each channel may only appear once in *mapping*.
360+
number of channels in *data* (except if *data* is mono, in which
361+
case the signal is played back on all given output channels).
362+
Each channel number may only appear once in *mapping*.
362363
blocking : bool, optional
363364
If ``False`` (the default), return immediately (but playback
364365
continues in the background), if ``True``, wait until playback
@@ -428,7 +429,7 @@ def rec(frames=None, samplerate=None, channels=None, dtype=None,
428429
The recorded data.
429430
430431
.. note:: By default (``blocking=False``), an array of data is
431-
returned which is still being written to while recording.
432+
returned which is still being written to while recording!
432433
The returned data is only valid once recording has stopped.
433434
Use `wait()` to make sure the recording is finished.
434435
@@ -590,14 +591,14 @@ def get_status():
590591
def get_stream():
591592
"""Get a reference to the current stream.
592593
593-
This applies only to streams created by calls to `play()`, `rec()`,
594+
This applies only to streams created by calls to `play()`, `rec()`
594595
or `playrec()`.
595596
596597
Returns
597598
-------
598599
Stream
599-
An `OutputStream`, `InputStream`, or `Stream` associated with
600-
the last invocation of `play()`, `rec()` or `playrec()`
600+
An `OutputStream`, `InputStream` or `Stream` associated with
601+
the last invocation of `play()`, `rec()` or `playrec()`,
601602
respectively.
602603
603604
"""
@@ -630,7 +631,7 @@ def query_devices(device=None, kind=None):
630631
-------
631632
dict or DeviceList
632633
A dictionary with information about the given *device* or -- if
633-
no *device* was specified -- a `DeviceList` containing one
634+
no arguments were specified -- a `DeviceList` containing one
634635
dictionary for each available device.
635636
The dictionaries have the following keys:
636637
@@ -703,7 +704,7 @@ def query_devices(device=None, kind=None):
703704
devices. The latter sometimes have a ridiculously high number of
704705
(virtual) inputs and outputs.
705706
706-
On Mac OS X, you might get something similar to this:
707+
On macOS, you might get something similar to this:
707708
708709
>>> sd.query_devices()
709710
0 Built-in Line Input, Core Audio (2 in, 0 out)
@@ -819,7 +820,7 @@ def check_input_settings(device=None, channels=None, dtype=None,
819820
Parameters
820821
----------
821822
device : int or str, optional
822-
Device ID or device name substring, see `default.device`.
823+
Device ID or device name substring(s), see `default.device`.
823824
channels : int, optional
824825
Number of input channels, see `default.channels`.
825826
dtype : str or numpy.dtype, optional
@@ -1272,7 +1273,7 @@ def __init__(self, samplerate=None, blocksize=None,
12721273
This is the same as `InputStream`, except that the *callback*
12731274
function and :meth:`~RawStream.read` work on plain Python buffer
12741275
objects instead of on NumPy arrays.
1275-
NumPy is not necessary to use this.
1276+
NumPy is not necessary for using this.
12761277
12771278
Parameters
12781279
----------
@@ -1312,7 +1313,7 @@ def read(self, frames):
13121313
13131314
This is the same as `Stream.read()`, except that it returns
13141315
a plain Python buffer object instead of a NumPy array.
1315-
NumPy is not necessary to use this.
1316+
NumPy is not necessary for using this.
13161317
13171318
Parameters
13181319
----------
@@ -1356,7 +1357,7 @@ def __init__(self, samplerate=None, blocksize=None,
13561357
This is the same as `OutputStream`, except that the *callback*
13571358
function and :meth:`~RawStream.write` work on plain Python
13581359
buffer objects instead of on NumPy arrays.
1359-
NumPy is not necessary to use this.
1360+
NumPy is not necessary for using this.
13601361
13611362
Parameters
13621363
----------
@@ -1396,7 +1397,7 @@ def write(self, data):
13961397
13971398
This is the same as `Stream.write()`, except that it expects
13981399
a plain Python buffer object instead of a NumPy array.
1399-
NumPy is not necessary to use this.
1400+
NumPy is not necessary for using this.
14001401
14011402
Parameters
14021403
----------
@@ -1451,9 +1452,9 @@ def __init__(self, samplerate=None, blocksize=None,
14511452
This is the same as `Stream`, except that the *callback*
14521453
function and `read()`/`write()` work on plain Python buffer
14531454
objects instead of on NumPy arrays.
1454-
NumPy is not necessary to use this.
1455+
NumPy is not necessary for using this.
14551456
1456-
To open "raw" input-only or output-only stream use
1457+
To open a "raw" input-only or output-only stream use
14571458
`RawInputStream` or `RawOutputStream`, respectively.
14581459
If you want to handle audio data as NumPy arrays instead of
14591460
buffer objects, use `Stream`, `InputStream` or `OutputStream`.
@@ -1653,17 +1654,17 @@ def __init__(self, samplerate=None, blocksize=None,
16531654
extra_settings=None, callback=None, finished_callback=None,
16541655
clip_off=None, dither_off=None, never_drop_input=None,
16551656
prime_output_buffers_using_stream_callback=None):
1656-
"""Open a stream for input and output.
1657+
"""Open a stream for simultaneous input and output.
16571658
16581659
To open an input-only or output-only stream use `InputStream` or
16591660
`OutputStream`, respectively. If you want to handle audio data
1660-
as buffer objects instead of NumPy arrays, use `RawStream`,
1661-
`RawInputStream` or `RawOutputStream`.
1661+
as plain buffer objects instead of NumPy arrays, use
1662+
`RawStream`, `RawInputStream` or `RawOutputStream`.
16621663
16631664
A single stream can provide multiple channels of real-time
16641665
streaming audio input and output to a client application. A
16651666
stream provides access to audio hardware represented by one or
1666-
more devices. Depending on the underlying Host API, it may be
1667+
more devices. Depending on the underlying host API, it may be
16671668
possible to open multiple streams using the same device, however
16681669
this behavior is implementation defined. Portable applications
16691670
should assume that a device may be simultaneously used by at
@@ -1984,6 +1985,9 @@ def input_underflow(self):
19841985
that one or more zero samples have been inserted into the input
19851986
buffer to compensate for an input underflow.
19861987
1988+
This can only happen in full-duplex streams (including
1989+
`playrec()`).
1990+
19871991
"""
19881992
return self._hasflag(_lib.paInputUnderflow)
19891993

@@ -1997,6 +2001,9 @@ def input_overflow(self):
19972001
too much CPU time. Otherwise indicates that data prior to one
19982002
or more samples in the input buffer was discarded.
19992003
2004+
This can happen in full-duplex and input-only streams (including
2005+
`playrec()` and `rec()`).
2006+
20002007
"""
20012008
return self._hasflag(_lib.paInputOverflow)
20022009

@@ -2007,6 +2014,9 @@ def output_underflow(self):
20072014
Indicates that output data (or a gap) was inserted, possibly
20082015
because the stream callback is using too much CPU time.
20092016
2017+
This can happen in full-duplex and output-only streams
2018+
(including `playrec()` and `play()`).
2019+
20102020
"""
20112021
return self._hasflag(_lib.paOutputUnderflow)
20122022

@@ -2017,6 +2027,10 @@ def output_overflow(self):
20172027
Indicates that output data will be discarded because no room is
20182028
available.
20192029
2030+
This can only happen in full-duplex streams (including
2031+
`playrec()`), but only when ``never_drop_input=True`` was
2032+
specified. See `default.never_drop_input`.
2033+
20202034
"""
20212035
return self._hasflag(_lib.paOutputOverflow)
20222036

@@ -2027,6 +2041,11 @@ def priming_output(self):
20272041
Some of all of the output data will be used to prime the stream,
20282042
input data may be zero.
20292043
2044+
This will only take place with some of the host APIs, and only
2045+
if ``prime_output_buffers_using_stream_callback=True`` was
2046+
specified.
2047+
See `default.prime_output_buffers_using_stream_callback`.
2048+
20302049
"""
20312050
return self._hasflag(_lib.paPrimingOutput)
20322051

@@ -2196,8 +2215,9 @@ class default(object):
21962215
callback. This flag is only valid for full-duplex callback streams
21972216
(i.e. only `Stream` and `RawStream` and only if *callback* was
21982217
specified; this includes `playrec()`) and only when used in
2199-
combination with ``blocksize=0`` (the default).
2200-
Using this flag incorrectly results in an error being raised.
2218+
combination with ``blocksize=0`` (the default). Using this flag
2219+
incorrectly results in an error being raised. See also
2220+
http://www.portaudio.com/docs/proposals/001-UnderflowOverflowHandling.html.
22012221
22022222
"""
22032223
prime_output_buffers_using_stream_callback = False
@@ -2207,7 +2227,8 @@ class default(object):
22072227
buffers, rather than the default behavior of priming the buffers
22082228
with zeros (silence). This flag has no effect for input-only
22092229
(`InputStream` and `RawInputStream`) and blocking read/write streams
2210-
(i.e. if *callback* wasn't specified).
2230+
(i.e. if *callback* wasn't specified). See also
2231+
http://www.portaudio.com/docs/proposals/020-AllowCallbackToPrimeStream.html.
22112232
22122233
"""
22132234

@@ -2293,8 +2314,8 @@ def __init__(self, channel_selectors):
22932314
The length of *channel_selectors* must match the
22942315
corresponding *channels* parameter of `Stream()` (or
22952316
variants), otherwise a crash may result.
2296-
The values in the selectors array must specify channels
2297-
within the range of supported channels.
2317+
The values in the *channel_selectors* array must specify
2318+
channels within the range of supported channels.
22982319
22992320
Examples
23002321
--------
@@ -2745,7 +2766,7 @@ def _ignore_stderr():
27452766
FILE* fopen(const char* path, const char* mode);
27462767
int fclose(FILE* fp);
27472768
FILE* stderr; /* GNU C library */
2748-
FILE* __stderrp; /* Mac OS X */
2769+
FILE* __stderrp; /* macOS */
27492770
""")
27502771
try:
27512772
stdio = ffi.dlopen(None)

0 commit comments

Comments
 (0)