Skip to content

Commit a289f82

Browse files
vokimonDavid García Garzón
authored and
David García Garzón
committed
Updated examples to column-order
1 parent 5a8e21c commit a289f82

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ Examples
4444

4545
### Writting example
4646
```python
47-
with WaveWriter('lala.ogg', channels=2, format=Format.OGG|Format.VORBIS) as w :
47+
with WaveWriter('synth.ogg', channels=2, format=Format.OGG|Format.VORBIS) as w :
4848
w.metadata.title = "Some Noise"
4949
w.metadata.artist = "The Artists"
50-
data = np.zeros((512,2), np.float32)
50+
data = np.zeros((2,512), np.float32)
5151
for x in xrange(100) :
52-
data[:,0] = (x*np.arange(512, dtype=np.float32)%512/512)
53-
data[512-x:,1] = 1
54-
data[:512-x,1] = -1
52+
data[0,:] = (x*np.arange(512, dtype=np.float32)%512/512)
53+
data[1,512-x:] = 1
54+
data[1,:512-x] = -1
5555
w.write(data)
5656
```
5757

@@ -79,7 +79,7 @@ with WaveReader(sys.argv[1]) as r :
7979
# iterator interface (reuses one array)
8080
# beware of the frame size, not always 512, but 512 at least
8181
for frame in r.read_iter(size=512) :
82-
stream.write(frame, frame.shape[0])
82+
stream.write(frame, frame.shape[1])
8383
sys.stdout.write("."); sys.stdout.flush()
8484

8585
stream.close()
@@ -116,11 +116,11 @@ with WaveReader(sys.argv[1]) as r :
116116
w.metadata.title = r.metadata.title + " II"
117117
w.metadata.artist = r.metadata.artist
118118

119-
data = np.zeros((512,r.channels), np.float32)
119+
data = np.zeros((r.channels,512), np.float32, order='F')
120120
nframes = r.read(data)
121121
while nframes :
122122
sys.stdout.write("."); sys.stdout.flush()
123-
w.write(.8*data[:nframes])
123+
w.write(.8*data[:,:nframes])
124124
nframes = r.read(data)
125125
```
126126

wavefile/wavefile.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ def saveWave(filename, data, samplerate, verbose=False) :
303303
with WaveWriter('synth.ogg', channels=2, format=Format.OGG|Format.VORBIS) as w :
304304
w.metadata.title = "Some Noise"
305305
w.metadata.artist = "The Artists"
306-
data = np.zeros((512,2), np.float32)
306+
data = np.zeros((2,512), np.float32)
307307
for x in xrange(100) :
308-
data[:,0] = (x*np.arange(512, dtype=np.float32)%512/512)
309-
data[512-x:,1] = 1
310-
data[:512-x,1] = -1
308+
data[0,:] = (x*np.arange(512, dtype=np.float32)%512/512)
309+
data[1,512-x:] = 1
310+
data[1,:512-x] = -1
311311
w.write(data)
312312

313313
import sys
@@ -336,7 +336,7 @@ def saveWave(filename, data, samplerate, verbose=False) :
336336
# iterator interface (reuses one array)
337337
# beware of the frame size, not always 512, but 512 at least
338338
for frame in r.read_iter(size=512) :
339-
stream.write(frame, frame.shape[0])
339+
stream.write(frame, frame.shape[1])
340340
sys.stdout.write("."); sys.stdout.flush()
341341

342342
stream.close()
@@ -351,11 +351,11 @@ def saveWave(filename, data, samplerate, verbose=False) :
351351
w.metadata.title = r.metadata.title + " II"
352352
w.metadata.artist = r.metadata.artist
353353

354-
data = np.zeros((512,r.channels), np.float32)
354+
data = np.zeros((r.channels,512), np.float32, order='F')
355355
nframes = r.read(data)
356356
while nframes :
357357
sys.stdout.write("."); sys.stdout.flush()
358-
w.write(.8*data[:nframes])
358+
w.write(.8*data[:,:nframes])
359359
nframes = r.read(data)
360360

361361

0 commit comments

Comments
 (0)