libsndfile-binaries
libsndfile-binaries copied to clipboard
unable to write FLAC files with SoundFile
The script
import soundfile as sf
sf.write('test.flac', [0.1, 0.2, 0.3, 0.4], 48000)
crashes with the current master branch of SoundFile, and python 2.7.6 (32-bit) under Windows 7 64bit.
Also affected is tag 1.0.27. Tag 1.0.25 works.
It would be interesting to know if it works with the DLLs from the original installer: http://www.mega-nerd.com/libsndfile/#Download
It also fails.
It is quite weird, that it works if I type the commands in the python command interpreter, but it fails when I execute it in a script.
That's indeed weird. Did you make sure that you are using the same Python version in both cases?
There might be a problem when closing the interpreter, you could try to add time.sleep(3)
at the end of your script or something like input()
. You could also try to start it with python3 -i myscript.py
.
How does the crash look like? Is there an error message? Is the output sound file written correctly or not?
There might be a problem when closing the interpreter, you could try to add time.sleep(3) at the end of your script or something like input(). You could also try to start it with python3 -i myscript.py.
This did not help. If I change the script into:
import soundfile as sf
sf.write('test.flac', [x/10.0 for x in range(4097)], 48000)
it also fails when I type the commands in the python interpreter (It does not fail if the length is 4096 samples).
I get no error message from python. The Windows operating system says that python.exe does not work anymore. The output file is only an empty FLAC file.
OK, can you please summarize in which exact combinations it works and in which it doesn't? Can you please also try the update-to-1.0.26 branch? Can you try on a 64-bit Python?
I think in the end we should try to reproduce the problem with a little example program written in C and then report it to the libsndfile issue tracker (if it still occurs). Do you have the possibility to compile a C program and link it to a given libsndfile DLL?
OK, can you please summarize in which exact combinations it works and in which it doesn't?
The 32-bit version fails, if the buffer is big enough. The exact buffer size needed for failure is unclear.
I made a simple test program in C, and compiled it using Visual Studio 2013.
32-bit: fails with libsndfile DLL > 1.0.25. The debugger says: Unhandled exception at 0x56B71112 (libsndfile-1.dll) in testlibsndfile.exe: 0xC0000005: Access violation reading location 0x00000000.
64-bit: works
If I change the output format to: sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS;
, then it fails
with 32-bit and 64-bit (every DLL version 1.0.25--1.0.28). The debugger says: Unhandled exception at 0x000000006480E9D6 (libsndfile-1.dll) in testlibsndfile.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000000000223980).
#include <string.h>
#include <stdlib.h>
#include "sndfile.h"
#define NUMBER_OF_SAMPLES 480000
double buffer[NUMBER_OF_SAMPLES];
const char* outfilename = "test";
int main(int argc, char* argv[])
{
SNDFILE *outfile;
SF_INFO sfinfo;
unsigned int i;
memset(&sfinfo, 0, sizeof(sfinfo));
sfinfo.format = SF_FORMAT_FLAC | SF_FORMAT_PCM_16;
sfinfo.channels = 1;
sfinfo.samplerate = 48000;
if (!sf_format_check(&sfinfo)) {
printf("Invalid encoding\n");
return 2;
}
if (!(outfile = sf_open(outfilename, SFM_WRITE, &sfinfo))) {
printf("Error : could not open file : %s\n", outfilename);
puts(sf_strerror(NULL));
return 1;
}
for (i = 0; i < NUMBER_OF_SAMPLES; ++i)
buffer[i] = i *1.0 / NUMBER_OF_SAMPLES;
sf_write_double(outfile, buffer, NUMBER_OF_SAMPLES);
sf_close(outfile);
printf("ok\n");
return 0;
}
#pragma comment(lib, "libsndfile-1.lib")
@raecke So this error also happens with the library files from the original libsndfile installer, right?
I think you should raise an issue at libsndfile project: https://github.com/erikd/libsndfile/issues
See also:
- https://github.com/bastibe/SoundFile/issues/265
- https://github.com/bastibe/SoundFile/issues/274
- https://github.com/erikd/libsndfile/issues/504