Giter VIP home page Giter VIP logo

Comments (3)

mgeier avatar mgeier commented on July 19, 2024

The logic will have to consider all three methods: sf_open(), sf_open_virtual() (as introduced in #1) and sf_open_fd().

from python-soundfile.

bastibe avatar bastibe commented on July 19, 2024

Are Python file descriptors convertible to C file descriptors? Otherwise, this would have to be handled with sf_open_virtual.

I don't quite see the utility of having this. Can you give an example where this might be useful?

from python-soundfile.

mgeier avatar mgeier commented on July 19, 2024

Are Python file descriptors convertible to C file descriptors?

It looks like they are. You can get a file descriptor from a Python file object with the method fileno().
I'm not quite sure what happens if the file object implements some kind of buffering ... this might break things.
You can also get file descriptors directly, e.g. with os.open().

Otherwise, this would have to be handled with sf_open_virtual.

As discussed in #1, this can only be used if seek() is supported. With sf_open_fd(), however, this should work without seek(), so the streaming feature discussed in #1 should be possible.

I don't quite see the utility of having this. Can you give an example where this might be useful?

To be honest, I don't actually have a use for this, I just think it's good to implement as many libsndfile features as possible, it might be useful to someone sometime.
But to give an example anyway, if someone wants to read from a pipe, this should be only possible with sf_open_fd(), at least according to http://stackoverflow.com/questions/8370499/audio-file-format-that-can-be-written-without-seeking (though I didn't actually try it myself).

I implemented this prototypically in #18, commit f0c7735, and it doesn't add a lot of code.
It just needs a new argument closefd and these two lines (and one line in the cdef):

elif isinstance(file, int):
    self._file = _snd.sf_open_fd(file, self.mode, info, closefd)

BTW, I removed the argument virtual_io because it's redundant, we can automatically check if a file-like object was provided (and the check was even already implemented).

And also BTW, the virtual_io feature is broken, because it checks for a read attribute but then uses the readinto() method. The latter seems not to be available for all types of file objects, maybe this should be checked and read() should be used as a fallback?

from python-soundfile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.