Skip to content

autoconvert to/from floats #23

@ssfrr

Description

@ssfrr

Currently LibSndFile.jl avoids making assumptions about type conversions when loading and saving audio files. However, I find almost invariably I end up doing float(load(fname)). Saving is also often inconvenient because saving to wav ends up creating Float64-formatted wav files, which many other tools don't know how to handle, so I end up needing to do save("audio.wav", Fixed{Int16, 15}.(x)), which seems like a ridiculous thing to ask users to do. I'm wondering if we should auto-convert by default (more like WAV.jl). Also some formats (like FLAC) don't every support floating-point samples, so saving to FLAC requires manual conversion to fixed-point, which is annoying.

One way to handle the element type would be to have an eltype=Float64 keyword argument to load, so by default it would auto-convert to Float64, but it would be overridable. eltype=:native or eltype=nothing could be given to get the current behavior of keeping the native element type. Loading integer-typed files as FixedPoint is cute but in practice I've found that floats are much more useful for most processing.

For saving I think I'd default to 24-bit integer types. The API for specifying the type seems a little unclear - I'm not sure whether it's better to use Julia types (e.g. eltype=Fixed{Int16,15} for 16-bit ints) or something like eltype=:int, nbits=16 or something. The latter seems less finicky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions