Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to write FLAC files with SoundFile #2

Open
raecke opened this issue Jul 23, 2017 · 8 comments
Open

unable to write FLAC files with SoundFile #2

raecke opened this issue Jul 23, 2017 · 8 comments

Comments

@raecke
Copy link

raecke commented Jul 23, 2017

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.

@mgeier
Copy link
Contributor

mgeier commented Jul 23, 2017

It would be interesting to know if it works with the DLLs from the original installer: http://www.mega-nerd.com/libsndfile/#Download

@raecke
Copy link
Author

raecke commented Jul 23, 2017

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.

@mgeier
Copy link
Contributor

mgeier commented Jul 24, 2017

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?

@raecke
Copy link
Author

raecke commented Jul 24, 2017

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.

@mgeier
Copy link
Contributor

mgeier commented Jul 25, 2017

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?

@raecke
Copy link
Author

raecke commented Jul 30, 2017

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")

@mgeier
Copy link
Contributor

mgeier commented Jul 31, 2017

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants