Skip to content

Conversation

@bastibe
Copy link
Owner

@bastibe bastibe commented Oct 16, 2015

There are surprisingly many bugs (even when not counting PEP-8 violations) in this (this is before #132):

import soundfile as sf

format = {'format':'RAW', 'subtype':'FLOAT', 'endian':'FILE'}
data = sf.read('myfile.raw', dtype='float32', **format)
sf.write(data, 'otherfile.raw', **format)

This would be a variation that actually works (after merging #132):

import soundfile as sf

format = dict(format='RAW', subtype='FLOAT', endian='FILE', samplerate=44100)
data, samplerate = sf.read('myfile.raw', channels=1, dtype='float32', **format)
assert samplerate == format['samplerate']
sf.write('otherfile.raw', data, **format)

Given this complexity, this is probably not such a "useful idiom" after all?

I hereby suggest to remove this example and replace it with an example for just reading a RAW file, which will show that all those arguments have to be given even for reading.

Reading RAW files is much more important than writing them, anyway.

@mgeier mgeier added this to the 0.8.0 milestone Oct 1, 2015
@bastibe
Copy link
Owner

bastibe commented Oct 1, 2015

Yes, I agree!

@mgeier
Copy link
Contributor Author

mgeier commented Oct 2, 2015

@bastibe do you want to do that?

@bastibe
Copy link
Owner

bastibe commented Oct 2, 2015

Sure

@mgeier mgeier added the docs label Oct 4, 2015
@bastibe bastibe self-assigned this Oct 4, 2015
@bastibe
Copy link
Owner

bastibe commented Oct 16, 2015

I still think that the RAW example is useful, even with the "dict trick". RAW files are inherently complex to deal with, so a bit of inelegance is not a big problem I'd say.

@mgeier
Copy link
Contributor Author

mgeier commented Oct 17, 2015

I agree that having an example for RAW is useful, but the current one is much too complicated and more confusing than helpful.

To a beginner should not be suggested that writing a RAW file is generally a good idea, so it would be best if we don't show this in an example. OTOH, a beginner might well be confronted with a RAW file from somebody else, and it would be extremely helpful to see an example how to read a RAW file.

import soundfile as sf

data, samplerate = sf.read('myfile.raw', channels=1, samplerate=44100,
                           subtype='FLOAT')

To be honest, I have no clue what endian='FILE' is supposed to mean for RAW files, do you?
When I tried it, the default seemed to be endian='LITTLE', but I have no idea if this is platform-dependent.
To make this clear, we should probably show an explicit endian-ness like endian='LITTLE' ...?

import soundfile as sf

data, samplerate = sf.read('myfile.raw', channels=1, samplerate=44100,
                           subtype='FLOAT', endian='LITTLE')

And then we could even mention, that the user should find out by trial and error if endian='LITTLE' or endian='BIG' is the right thing for the file at hand.

@bastibe
Copy link
Owner

bastibe commented Oct 19, 2015

x86 is little-endian, so the default argument makes perfect sense, and should be correct in most cases.

I agree that writing RAW should be discouraged, and added a note to that effect to the README.

remove write example
add note about endianness
add note about RAW file usage
@mgeier
Copy link
Contributor Author

mgeier commented Oct 19, 2015

Cool.

You could even explicitly state the alternative with "... have to use ``endian='BIG'``."

bastibe added a commit that referenced this pull request Oct 20, 2015
RAW example in README is severely broken
@bastibe bastibe merged commit 70f396c into master Oct 20, 2015
@bastibe bastibe deleted the issue-144 branch April 25, 2016 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants