What is `blocksize` and callback's `frames` param?
See original GitHub issueI need a little help to understand what is blocksize
and callback’s frames
param.
At first I thought len(outdata) equals frames, and so it is with play-a-sine-signal example (on my machine), but no with play-a-very-long-sound-file
I read the api section in doc:https://python-sounddevice.readthedocs.io/en/0.3.15/api/streams.html, but I still don’t understand what is the relationship between blocksize, frames, and len(outdata). could you please explain more? Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
python - In InputStream, what does blocksize do? (sounddevice)
The callback function is called at a rate determined by blocksize . If you make blocksize larger, the callback will be called less...
Read more >API Documentation — python-sounddevice, version 0.3.12
blocksize (int, optional) – The number of frames passed to the stream callback function, or the preferred block granularity for a blocking read/write...
Read more >Issue changing the callback "frames" #351 - GitHub
Hello, I am using a sounddevice.Stream with a callback function and want to change the "frames". I can't seem to find a way...
Read more >Common Block Properties - MATLAB & Simulink - MathWorks
Property Description Values
BackgroundColor Block background color.
BlockType Block type (read‑only). character array
CloseFcn Function called when close_system is run on block. function | character v......
Read more >39.3. cd — CD-ROM access on SGI systems — Python 2.7.9 ...
Data from the CD is passed to the parser, which parses the frames, and calls any callback functions that have previously been added....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you, that answers my question
I was surprised for a moment, but then I saw the reason for the confusion:
The
play_long_file.py
example uses aRawOutputStream
. This means that theoutdata
argument in the callback function is not a NumPy array but a Python buffer object. When you uselen()
on such an object, you get the size of the data in bytes.In this case, you should look at
stream.samplesize
, which is the number of bytes per sample. Since the example usesdtype='float32'
, you’ll see that the sample size is 4. You’ll also have to check the number of channels (which in your filealert.wav
seems to be 1).The length in bytes of the output buffer is the number of frames times the number of channels times the sample size. This is why in your case
len(outdata)
is 4 times the number offrames
, because the sample size is 4 and the number of channels is 1.So I was wrong to say that above:
This is only true when you use NumPy, i.e. when you use
Stream
andOutputStream
.When you use
RawOutputStream
, this is more accurate:When you use
RawStream
, there are pairs of values forsamplesize
andchannels
, the second one is the value corresponding to the output:Does that make sense?