1 /* 2 __ 3 / _| 4 __ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___ 5 / _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __| 6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \ 7 \__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/ 8 9 Copyright (C) 2018-2019 Aurora Free Open Source Software. 10 11 This file is part of the Aurora Free Open Source Software. This 12 organization promote free and open source software that you can 13 redistribute and/or modify under the terms of the GNU Lesser General 14 Public License Version 3 as published by the Free Software Foundation or 15 (at your option) any later version approved by the Aurora Free Open Source 16 Software Organization. The license is available in the package root path 17 as 'LICENSE' file. Please review the following information to ensure the 18 GNU Lesser General Public License version 3 requirements will be met: 19 https://www.gnu.org/licenses/lgpl.html . 20 21 Alternatively, this file may be used under the terms of the GNU General 22 Public License version 3 or later as published by the Free Software 23 Foundation. Please review the following information to ensure the GNU 24 General Public License requirements will be met: 25 http://www.gnu.org/licenses/gpl-3.0.html. 26 27 NOTE: All products, services or anything associated to trademarks and 28 service marks used or referenced on this file are the property of their 29 respective companies/owners or its subsidiaries. Other names and brands 30 may be claimed as the property of others. 31 32 For more info about intellectual property visit: aurorafoss.org or 33 directly send an email to: contact (at) aurorafoss.org . 34 */ 35 36 module riverd.sndfile.statfun; 37 38 import riverd.sndfile.types; 39 import core.stdc.stdarg; 40 41 extern(C) @nogc nothrow: 42 43 /* Open the specified file for read, write or both. On error, this will 44 ** return a NULL pointer. To find the error number, pass a NULL SNDFILE 45 ** to sf_strerror (). 46 ** All calls to sf_open() should be matched with a call to sf_close(). 47 */ 48 49 SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ; 50 51 52 /* Use the existing file descriptor to create a SNDFILE object. If close_desc 53 ** is TRUE, the file descriptor will be closed when sf_close() is called. If 54 ** it is FALSE, the descritor will not be closed. 55 ** When passed a descriptor like this, the library will assume that the start 56 ** of file header is at the current file offset. This allows sound files within 57 ** larger container files to be read and/or written. 58 ** On error, this will return a NULL pointer. To find the error number, pass a 59 ** NULL SNDFILE to sf_strerror (). 60 ** All calls to sf_open_fd() should be matched with a call to sf_close(). 61 62 */ 63 64 SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ; 65 66 SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ; 67 68 69 /* sf_error () returns a error number which can be translated to a text 70 ** string using sf_error_number(). 71 */ 72 73 int sf_error (SNDFILE *sndfile) ; 74 75 76 /* sf_strerror () returns to the caller a pointer to the current error message for 77 ** the given SNDFILE. 78 */ 79 80 const(char)* sf_strerror (SNDFILE *sndfile) ; 81 82 83 /* sf_error_number () allows the retrieval of the error string for each internal 84 ** error number. 85 ** 86 */ 87 88 const(char)* sf_error_number (int errnum) ; 89 90 91 /* The following two error functions are deprecated but they will remain in the 92 ** library for the forseeable future. The function sf_strerror() should be used 93 ** in their place. 94 */ 95 96 int sf_perror (SNDFILE *sndfile) ; 97 int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ; 98 99 100 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */ 101 102 int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ; 103 104 105 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */ 106 107 int sf_format_check (const SF_INFO *info) ; 108 109 110 /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses 111 ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as 112 ** stdio.h function fseek (). 113 ** An offset of zero with whence set to SEEK_SET will position the 114 ** read / write pointer to the first data sample. 115 ** On success sf_seek returns the current position in (multi-channel) 116 ** samples from the start of the file. 117 ** Please see the libsndfile documentation for moving the read pointer 118 ** separately from the write pointer on files open in mode SFM_RDWR. 119 ** On error all of these functions return -1. 120 */ 121 122 sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ; 123 124 125 /* Functions for retrieving and setting string data within sound files. 126 ** Not all file types support this features; AIFF and WAV do. For both 127 ** functions, the str_type parameter must be one of the SF_STR_* values 128 ** defined above. 129 ** On error, sf_set_string() returns non-zero while sf_get_string() 130 ** returns NULL. 131 */ 132 133 int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ; 134 135 const(char)* sf_get_string (SNDFILE *sndfile, int str_type) ; 136 137 138 /* Return the library version string. */ 139 140 const(char)* sf_version_string () ; 141 142 143 /* Functions for reading/writing the waveform data of a sound file. 144 */ 145 146 sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ; 147 sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ; 148 149 150 /* Functions for reading and writing the data chunk in terms of frames. 151 ** The number of items actually read/written = frames * number of channels. 152 ** sf_xxxx_raw read/writes the raw data bytes from/to the file 153 ** sf_xxxx_short passes data in the native short format 154 ** sf_xxxx_int passes data in the native int format 155 ** sf_xxxx_float passes data in the native float format 156 ** sf_xxxx_double passes data in the native double format 157 ** All of these read/write function return number of frames read/written. 158 */ 159 160 sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ; 161 sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ; 162 163 sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ; 164 sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ; 165 166 sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ; 167 sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ; 168 169 sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ; 170 sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ; 171 172 173 /* Functions for reading and writing the data chunk in terms of items. 174 ** Otherwise similar to above. 175 ** All of these read/write function return number of items read/written. 176 */ 177 178 sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ; 179 sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ; 180 181 sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ; 182 sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ; 183 184 sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ; 185 sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ; 186 187 sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ; 188 sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ; 189 190 191 /* Close the SNDFILE and clean up all memory allocations associated with this 192 ** file. 193 ** Returns 0 on success, or an error number. 194 */ 195 196 int sf_close (SNDFILE *sndfile) ; 197 198 199 /* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file 200 ** to force the writing of data to disk. If the file is opened SFM_READ 201 ** no action is taken. 202 */ 203 204 void sf_write_sync (SNDFILE *sndfile) ; 205 206 207 208 /* The function sf_wchar_open() is Windows Only! 209 ** Open a file passing in a Windows Unicode filename. Otherwise, this is 210 ** the same as sf_open(). 211 ** 212 ** In order for this to work, you need to do the following: 213 ** 214 ** #include <windows.h> 215 ** #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 216 ** #including <sndfile.h> 217 */ 218 219 version (Windows) 220 { 221 SNDFILE* sf_wchar_open (wchar* wpath, int mode, SF_INFO *sfinfo) ; 222 }