sndfile2k
1.2.0
|
API for opening, closing and flushing sound files. More...
Modules | |
Virtual I/O | |
SndFile2K calls the callbacks provided by the SF_VIRTUAL_IO structure when opening, reading and writing to the virtual file context. | |
Typedefs | |
typedef struct sf_private_tag | SNDFILE |
Represents opened sound file. More... | |
typedef sf_count_t(* | sf_vio_tell) (void *user_data) |
Type of user defined function that returns current position in file. More... | |
Enumerations | |
enum | SF_FILEMODE { SFM_READ = 0x10, SFM_WRITE = 0x20, SFM_RDWR = 0x30 } |
Defines the kind of file access. More... | |
enum | SF_SEEK_MODE { SF_SEEK_SET = SEEK_SET, SF_SEEK_CUR = SEEK_CUR, SF_SEEK_END = SEEK_END } |
Defines file seek mode constants. More... | |
Functions | |
SNDFILE2K_EXPORT SNDFILE * | sf_open (const char *path, int mode, SF_INFO *sfinfo) |
Opens the specified sound file using path. More... | |
SNDFILE2K_EXPORT SNDFILE * | sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) |
Opens sound file using POSIX file descriptor. More... | |
SNDFILE2K_EXPORT sf_count_t | sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) |
Changes position of sound file. More... | |
SNDFILE2K_EXPORT void | sf_write_sync (SNDFILE *sndfile) |
Forces writing of data to disk. More... | |
API for opening, closing and flushing sound files.
typedef sf_count_t(* sf_vio_tell) (void *user_data) |
Type of user defined function that returns current position in file.
[in] | user_data | User defined value. |
-1
otherwise. typedef struct sf_private_tag SNDFILE |
Represents opened sound file.
Pointer to SNDFILE
is returned by set of file open finctions, including sf_open(), sf_open_fd() and sf_open_virtual(). Most of API functions take SNDFILE
pointer as required parameter.
Make no assumptions about SNDFILE
internal structure, it is subject to change in future releases.
Any created SNDFILE
should be destroyed by sf_close() function to avoid memory leaks.
enum SF_FILEMODE |
enum SF_SEEK_MODE |
Opens the specified sound file using path.
[in] | path | Path to the file |
[in] | mode | File open mode |
[in,out] | sfinfo | Format information |
The path
is byte encoded, but may be utf-8 on Linux, while on Mac OS X it will use the filesystem character set. On Windows, there is also a Windows specific sf_wchar_open() that takes a UTF16_BE
encoded filename.
The emode
specifies the kind of access that is requested for the file, one of SF_FILEMODE values.
When opening a file for read, the SF_INFO::format field should be set to zero before passing to sf_open(). The only exception to this is the case of RAW
files where the caller has to set the samplerate
, channels
and format
fields to valid values. All other fields of the structure are filled in by the library.
When opening a file for write, the caller must fill in structure members SF_INFO::samplerate, SF_INFO::channels, and SF_INFO::format.
All calls to sf_open() should be matched with a call to sf_close().
NULL
otherwise.Opens sound file using POSIX
file descriptor.
[in] | fd | File descriptor |
[in] | mode | File open mode |
[in,out] | sfinfo | Format information |
[in] | close_desc | File descriptor close mode |
sf_open_fd() is similar to sf_open(), but takes POSIX
file descriptor of already opened file instead of path.
Care should be taken to ensure that the mode of the file represented by the descriptor matches the mode
argument.
This function is useful in the following circumstances:
tmpfile()
to return a FILE*
pointer and then using fileno()
to retrieve the file descriptor which is then passed to sndfile2k.When sf_close() is called, the file descriptor is only closed if the close_desc
parameter was SF_TRUE when the sf_open_fd() function was called.
NULL
otherwise.SNDFILE2K_EXPORT sf_count_t sf_seek | ( | SNDFILE * | sndfile, |
sf_count_t | frames, | ||
int | whence | ||
) |
Changes position of sound file.
[in] | sndfile | Pointer to a sound file state |
[in] | frames | Count of frames |
[in] | whence | Seek origin |
The file seek functions work much like lseek in unistd.h
with the exception that the non-audio data is ignored and the seek only moves within the audio data section of the file. In addition, seeks are defined in number of (multichannel) frames. Therefore, a seek in a stereo file from the current position forward with an offset of 1 would skip forward by one sample of both channels.
Internally, library keeps track of the read and write locations using separate read and write pointers. If a file has been opened with a mode of SFM_RDWR, bitwise OR-ing the standard whence values above with either SFM_READ or SFM_WRITE allows the read and write pointers to be modified separately. If the SEEK_*
values are used on their own, the read and write pointers are both modified.
whence
parameter.-1
if an error occured (ie an attempt is made to seek beyond the start or end of the file).