Table of callback functions used with BASS_StreamCreateFileUser.
typedef struct { FILECLOSEPROC *close; FILELENPROC *length; FILEREADPROC *read; FILESEEKPROC *seek; } BASS_FILEPROCS;
close | Callback function to close the file. |
length | Callback function to get the file length. |
read | Callback function to read from the file. |
seek | Callback function to seek in the file. Not used by buffered file streams. |
void CALLBACK MyFileCloseProc(void *user) { fclose(user); // close the file } QWORD CALLBACK MyFileLenProc(void *user) { struct stat s; fstat(fileno(user), &s); return s.st_size; // return the file length } DWORD CALLBACK MyFileReadProc(void *buffer, DWORD length, void *user) { return fread(buffer, 1, length, user); // read from file } BOOL CALLBACK MyFileSeekProc(QWORD offset, void *user) { return !fseek(user, offset, SEEK_SET); // seek to offset } ... BASS_FILEPROCS fileprocs = { MyFileCloseProc, MyFileLenProc, MyFileReadProc, MyFileSeekProc }; // callback table FILE *file = fopen("a_file.mp3", "rb"); // open the file stream = BASS_StreamCreateFileUser(STREAMFILE_NOBUFFER, 0, &fileprocs, file); // create the stream
NOTE: This is just an example. It is simpler to use BASS_StreamCreateFile to stream a file from disk.