Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon authored Nov 13, 2023
1 parent 02d94c1 commit da506c3
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,45 +186,13 @@ with WaveReader(sys.argv[1]) as r:
w.write(.8*data)
```

While `read_iter` is simpler and recommended,
you can still use the read function,
which is closer to the C one.

```python
import sys, numpy as np
from wavefile import WaveReader, WaveWriter

with WaveReader(sys.argv[1]) as r:
with WaveWriter(
'output.wav',
channels=r.channels,
samplerate=r.samplerate,
) as w:
w.metadata.title = r.metadata.title + " II"
w.metadata.artist = r.metadata.artist

data = np.zeros((r.channels,512), np.float32, order='F')
nframes = r.read(data)
while nframes:
sys.stdout.write("."); sys.stdout.flush()
w.write(.8*data[:,:nframes])
nframes = r.read(data)
```

Notice that with ```read``` you have to reallocate the data yourself,
the loop structure is somewhat more complex,
and you have to slice to the actual ```nframes``` because
the last block usually does not have the size you asked for.

```read_iter``` simplifies the code by transparently:

- allocating the data block for you,
- reusing it for each block, and
- slicing it when the last incomplete block arrives.




Existing alternatives (what i like and dislike)
-----------------------------------------------

Expand Down

0 comments on commit da506c3

Please sign in to comment.