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

WAV as input format and output format #1

Open
dennisguse opened this issue Apr 3, 2017 · 0 comments
Open

WAV as input format and output format #1

dennisguse opened this issue Apr 3, 2017 · 0 comments

Comments

@dennisguse
Copy link
Member

Almost all programs use a headerless binary format aka raw as input format and output format.
This is an issue due to endianess, sample rate, and word width (ie, files must be in the correct format, but are not self-describing).

This can be easily overcome by using WAVE instead of raw.

Libsndfile is a LGPL2 library for reading and writing wave files.
API is straight forward.

NOTE: This task requires to also adjust all concerned software tests.

Non-working demo code taken from https://github.com/TheTelephone/TheTelephone/blob/master/src/support/readsfnow_tilde.c:

//Read file completely.
SNDFILE *infile = NULL;
SF_INFO sfinfo;
memset (&sfinfo, 0, sizeof (sfinfo));

if ((infile = sf_open (x->filename, SFM_READ, &sfinfo)) == NULL) {
  char pwd[512];
  getcwd (pwd, 512);

  error (" Not able to open input file %s/%s: %s.", x->filename, pwd, x->filename, sf_strerror (NULL));
  return NULL;
}

if (fabsf (sys_getsr () - sfinfo.samplerate) > 0.0001) {
  error ("Sampling rate of input file (%d Hz) does not match Puredatas (%f Hz).", x->filename, sfinfo.samplerate, sys_getsr ());
  return NULL;
}

x->channel_count = sfinfo.channels;
x->wave_data = (float *) malloc (MAX_BUFFER * sizeof (float));
x->wave_length = sf_read_float (infile, x->wave_data, MAX_BUFFER);
x->frame_count = sfinfo.frames;

sf_close (infile);
dennisguse pushed a commit to dennisguse/STL that referenced this issue Nov 8, 2018
reviewed references, included bibliography
ludomal pushed a commit that referenced this issue May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant