XDF_READ(3)
πΈ XDF_READ(3) β the xdffileio library manual, but make it make sense πΈ
okay bestie, pull up a chair, we're reading samples out of an xDF file and it's gonna be so slay. this one lives in the xdffileio library manual btw, so that's the vibe of the whole family, iykyk π
β¨ NAME β¨
xdf_read β Read samples from a xDF file π«Ά
β¨ SYNOPSIS β¨
#include <xdfio.h>
int xdf_read(struct xdf* xdf, unsigned int ns, ...);
β¨ DESCRIPTION β¨
so xdf_read() literally just reads ns samples out of the xDF file that xdf points at. no cap. but β and this is the part where everyone gets humbled β that file has to have been opened with mode XDF_READ, and xdf_prepare_arrays(3) has to have been called on it successfully first. if not? xdf_read() will fail. periodt π
where does the data go, you ask? into arrays, and you point at them with pointers you drop into the variable list of arguments of the function. it expects the same number of arrays as whatever you declared in your earlier call to xdf_define_arrays(3). and the internal organisation of the data inside those arrays? that's something you already set up with calls to xdf_set_chconf(3). it's giving "you already told me the plan, i'm just executing it" π
also, super important, like genuinely do not skip this: none of the arrays should overlap. not even a little. none of them. that's not a suggestion, bestie π
β¨ RETURN VALUE β¨
on success it hands you back the number of samples it successfully read from the xDF file. heads up though: that number can be smaller than the ns you asked for, if you hit the end of the file. that's not a bug, that's just the file running out of lore π¦
if something goes wrong? -1 is returned and errno gets set appropriately. classic.
β¨ ERRORS β¨
EINVALβxdfisNULL. bestie. the pointer. it's null. πEPERMβ either nobody ever made a successful call toxdf_prepare_transfer(3)onxdf, orxdfwas opened using modeXDF_WRITE. wrong door, wrong room, wrong vibe πͺEINTRβ the call got interrupted by a signal before any data was written; go peek atsignal(7).EIOβ a low-level I/O error happened while reading from the inode. ouch.ESTALEβ stale file handle. this one can pop up on NFS and on other file systems too. NFS girlies stay strong π
β¨ EXAMPLE β¨
okay here's the whole thing, copied exactly, no notes:
/* Assume xdf references a xDF file opened for reading whose
channels source their data in 2 arrays of float whose strides
are the length of respectively 4 and 6 float values,
i.e. 16 and 24 bytes (in most platforms)*/
#define NS 3
float array1[NS][4], array2[NS][6];
unsigned int strides = {4*sizeof(float), 6*sizeof(float)};
unsigned int i;
xdf_define_arrays(xdf, 2, strides);
if (xdf_prepare_transfer(xdf))
return 1;
for (i=0; i<45; i+=NS) {
/* Write the values to the file */
if (xdf_write(xdf, NS, array1, array2))
return 1;
/* Use the values contained in array1 and array2*/
...
}
xdf_close(xdf);
yes, the comment says "Write the values to the file" and the call is xdf_write β that is exactly what the original page says, so i am leaving it alone, don't look at me π
β¨ SEE ALSO β¨
xdf_set_chconf(3), xdf_define_arrays(3), xdf_prepare_transfer(3)
and that's the whole page, bestie π this one's brought to you by EPFL, dated 2010, and it's the XDF_READ(3) entry in the xdffileio library manual. go read some samples, stay hydrated, and don't let your arrays overlap πβ¨π¦
π¦ where this page comes from
- debian bookworm: libxdffileio-dev 0.3-4 Β· LGPL-3.0-or-later
- debian trixie: libxdffileio-dev 0.3-4+b2 Β· LGPL-3.0-or-later
- fedora 43: xdffileio-devel 0.3-23.fc43 Β· LGPL-3.0-or-later
- fedora 43: xdffileio-devel 0.3-23.fc43 Β· LGPL-3.0-or-later
- fedora 44: xdffileio-devel 0.3-24.fc44 Β· LGPL-3.0-or-later
- fedora 44: xdffileio-devel 0.3-24.fc44 Β· LGPL-3.0-or-later
- ubuntu jammy: libxdffileio-dev 0.3-4 Β· LGPL-3.0-or-later
- ubuntu noble: libxdffileio-dev 0.3-4ubuntu3 Β· LGPL-3.0-or-later
- ubuntu questing: libxdffileio-dev 0.3-4ubuntu3
- ubuntu resolute: libxdffileio-dev 0.3-4ubuntu4 Β· LGPL-3.0-or-later
- ubuntu stonking: libxdffileio-dev 0.3-4ubuntu4 Β· LGPL-3.0-or-later
- Copyright 2010 (c) EPFL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms