BASS

BASS_FILEPROCS structure


Table of callback functions used with BASS_StreamCreateFileUser.

typedef struct {
    FILECLOSEPROC *close;
    FILELENPROC *length;
    FILEREADPROC *read;
    FILESEEKPROC *seek;
} BASS_FILEPROCS;

Members

closeCallback function to close the file.
lengthCallback function to get the file length.
readCallback function to read from the file.
seekCallback function to seek in the file. Not used by buffered file streams.

Example

Stream a file from disk via an "unbuffered" user file stream.
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.

See also

BASS_StreamCreateFileUser, FILECLOSEPROC callback, FILELENPROC callback, FILEREADPROC callback, FILESEEKPROC callback