@@ -1165,45 +1165,8 @@ def close(self, ignore_errors=True):
1165
1165
_check (err , 'Error closing stream' )
1166
1166
1167
1167
1168
- class RawInputStream (_StreamBase ):
1169
- """Raw stream for recording only. See __init__() and RawStream."""
1170
-
1171
- def __init__ (self , samplerate = None , blocksize = None ,
1172
- device = None , channels = None , dtype = None , latency = None ,
1173
- extra_settings = None , callback = None , finished_callback = None ,
1174
- clip_off = None , dither_off = None , never_drop_input = None ,
1175
- prime_output_buffers_using_stream_callback = None ):
1176
- """PortAudio input stream (using buffer objects).
1177
-
1178
- This is the same as `InputStream`, except that the *callback*
1179
- function and `~RawStream.read()` work on plain Python buffer
1180
- objects instead of on NumPy arrays.
1181
- NumPy is not necessary for using this.
1182
-
1183
- Parameters
1184
- ----------
1185
- dtype : str
1186
- See `RawStream`.
1187
- callback : callable
1188
- User-supplied function to consume audio data in response to
1189
- requests from an active stream.
1190
- The callback must have this signature:
1191
-
1192
- .. code-block:: text
1193
-
1194
- callback(indata: buffer, frames: int,
1195
- time: CData, status: CallbackFlags) -> None
1196
-
1197
- The arguments are the same as in the *callback* parameter of
1198
- `RawStream`, except that *outdata* is missing.
1199
-
1200
- See Also
1201
- --------
1202
- RawStream, Stream
1203
-
1204
- """
1205
- _StreamBase .__init__ (self , kind = 'input' , wrap_callback = 'buffer' ,
1206
- ** _remove_self (locals ()))
1168
+ class _InputStreamBase (_StreamBase ):
1169
+ """Base class for input stream classes."""
1207
1170
1208
1171
@property
1209
1172
def read_available (self ):
@@ -1215,7 +1178,7 @@ def read_available(self):
1215
1178
"""
1216
1179
return _check (_lib .Pa_GetStreamReadAvailable (self ._ptr ))
1217
1180
1218
- def read (self , frames ):
1181
+ def _raw_read (self , frames ):
1219
1182
"""Read samples from the stream into a buffer.
1220
1183
1221
1184
This is the same as `Stream.read()`, except that it returns
@@ -1251,46 +1214,52 @@ def read(self, frames):
1251
1214
return _ffi .buffer (data ), overflowed
1252
1215
1253
1216
1254
- class RawOutputStream ( _StreamBase ):
1255
- """Raw stream for playback only. See __init__() and RawStream."""
1217
+ class RawInputStream ( _InputStreamBase ):
1218
+ """Raw stream for recording only. See __init__() and RawStream."""
1256
1219
1257
1220
def __init__ (self , samplerate = None , blocksize = None ,
1258
1221
device = None , channels = None , dtype = None , latency = None ,
1259
1222
extra_settings = None , callback = None , finished_callback = None ,
1260
1223
clip_off = None , dither_off = None , never_drop_input = None ,
1261
1224
prime_output_buffers_using_stream_callback = None ):
1262
- """PortAudio output stream (using buffer objects).
1225
+ """PortAudio input stream (using buffer objects).
1263
1226
1264
- This is the same as `OutputStream `, except that the *callback*
1265
- function and `~RawStream.write ()` work on plain Python
1266
- buffer objects instead of on NumPy arrays.
1227
+ This is the same as `InputStream `, except that the *callback*
1228
+ function and `~RawStream.read ()` work on plain Python buffer
1229
+ objects instead of on NumPy arrays.
1267
1230
NumPy is not necessary for using this.
1268
1231
1269
1232
Parameters
1270
1233
----------
1271
1234
dtype : str
1272
1235
See `RawStream`.
1273
1236
callback : callable
1274
- User-supplied function to generate audio data in response to
1237
+ User-supplied function to consume audio data in response to
1275
1238
requests from an active stream.
1276
1239
The callback must have this signature:
1277
1240
1278
1241
.. code-block:: text
1279
1242
1280
- callback(outdata : buffer, frames: int,
1243
+ callback(indata : buffer, frames: int,
1281
1244
time: CData, status: CallbackFlags) -> None
1282
1245
1283
1246
The arguments are the same as in the *callback* parameter of
1284
- `RawStream`, except that *indata * is missing.
1247
+ `RawStream`, except that *outdata * is missing.
1285
1248
1286
1249
See Also
1287
1250
--------
1288
1251
RawStream, Stream
1289
1252
1290
1253
"""
1291
- _StreamBase .__init__ (self , kind = 'output ' , wrap_callback = 'buffer' ,
1254
+ _StreamBase .__init__ (self , kind = 'input ' , wrap_callback = 'buffer' ,
1292
1255
** _remove_self (locals ()))
1293
1256
1257
+ read = _InputStreamBase ._raw_read
1258
+
1259
+
1260
+ class _OutputStreamBase (_StreamBase ):
1261
+ """Base class for output stream classes."""
1262
+
1294
1263
@property
1295
1264
def write_available (self ):
1296
1265
"""The number of frames that can be written without waiting.
@@ -1301,7 +1270,7 @@ def write_available(self):
1301
1270
"""
1302
1271
return _check (_lib .Pa_GetStreamWriteAvailable (self ._ptr ))
1303
1272
1304
- def write (self , data ):
1273
+ def _raw_write (self , data ):
1305
1274
"""Write samples to the stream.
1306
1275
1307
1276
This is the same as `Stream.write()`, except that it expects
@@ -1348,6 +1317,49 @@ def write(self, data):
1348
1317
return underflowed
1349
1318
1350
1319
1320
+ class RawOutputStream (_OutputStreamBase ):
1321
+ """Raw stream for playback only. See __init__() and RawStream."""
1322
+
1323
+ def __init__ (self , samplerate = None , blocksize = None ,
1324
+ device = None , channels = None , dtype = None , latency = None ,
1325
+ extra_settings = None , callback = None , finished_callback = None ,
1326
+ clip_off = None , dither_off = None , never_drop_input = None ,
1327
+ prime_output_buffers_using_stream_callback = None ):
1328
+ """PortAudio output stream (using buffer objects).
1329
+
1330
+ This is the same as `OutputStream`, except that the *callback*
1331
+ function and `~RawStream.write()` work on plain Python
1332
+ buffer objects instead of on NumPy arrays.
1333
+ NumPy is not necessary for using this.
1334
+
1335
+ Parameters
1336
+ ----------
1337
+ dtype : str
1338
+ See `RawStream`.
1339
+ callback : callable
1340
+ User-supplied function to generate audio data in response to
1341
+ requests from an active stream.
1342
+ The callback must have this signature:
1343
+
1344
+ .. code-block:: text
1345
+
1346
+ callback(outdata: buffer, frames: int,
1347
+ time: CData, status: CallbackFlags) -> None
1348
+
1349
+ The arguments are the same as in the *callback* parameter of
1350
+ `RawStream`, except that *indata* is missing.
1351
+
1352
+ See Also
1353
+ --------
1354
+ RawStream, Stream
1355
+
1356
+ """
1357
+ _StreamBase .__init__ (self , kind = 'output' , wrap_callback = 'buffer' ,
1358
+ ** _remove_self (locals ()))
1359
+
1360
+ write = _OutputStreamBase ._raw_write
1361
+
1362
+
1351
1363
class RawStream (RawInputStream , RawOutputStream ):
1352
1364
"""Raw stream for playback and recording. See __init__()."""
1353
1365
@@ -1402,7 +1414,7 @@ def __init__(self, samplerate=None, blocksize=None,
1402
1414
** _remove_self (locals ()))
1403
1415
1404
1416
1405
- class InputStream (RawInputStream ):
1417
+ class InputStream (_InputStreamBase ):
1406
1418
"""Stream for input only. See __init__() and Stream."""
1407
1419
1408
1420
def __init__ (self , samplerate = None , blocksize = None ,
@@ -1472,12 +1484,12 @@ def read(self, frames):
1472
1484
"""
1473
1485
dtype , _ = _split (self ._dtype )
1474
1486
channels , _ = _split (self ._channels )
1475
- data , overflowed = RawInputStream . read (self , frames )
1487
+ data , overflowed = _InputStreamBase . _raw_read (self , frames )
1476
1488
data = _array (data , channels , dtype )
1477
1489
return data , overflowed
1478
1490
1479
1491
1480
- class OutputStream (RawOutputStream ):
1492
+ class OutputStream (_OutputStreamBase ):
1481
1493
"""Stream for output only. See __init__() and Stream."""
1482
1494
1483
1495
def __init__ (self , samplerate = None , blocksize = None ,
@@ -1562,7 +1574,7 @@ def write(self, data):
1562
1574
data .dtype .name , dtype ))
1563
1575
if not data .flags .c_contiguous :
1564
1576
raise TypeError ('data must be C-contiguous' )
1565
- return RawOutputStream . write (self , data )
1577
+ return _OutputStreamBase . _raw_write (self , data )
1566
1578
1567
1579
1568
1580
class Stream (InputStream , OutputStream ):
0 commit comments