sffuncs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (c) 1983-2013 Martin Atkins, Richard Dobson and Composers Desktop Project Ltd
  3. * http://people.bath.ac.uk/masrwd
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. /* sffuncs.h : private routines and structures */
  22. /*RWD Dec 2009 changed various fields in sf_direct to int or unsigned int */
  23. #ifndef __CDP_SFFUNCS_INCLUDED__
  24. #define __CDP_SFFUNCS_INCLUDED__
  25. /*
  26. * Various dummy definitions which did things on the Atari, but must be
  27. * removed for other platforms
  28. */
  29. #define STDARGS /**/
  30. #define SFCALLS /**/
  31. /* RWD.5.99: are these now too small for WIN32? */
  32. #define MAXSFNAME (255) /* maximum length of SFfile's name */
  33. #define MAXPREFIX (50) /* maximum length of a filename prefix */
  34. #ifndef WIN32
  35. typedef long long __int64;
  36. #endif
  37. /*
  38. * Structure definitions
  39. */
  40. /*RWD.5.99 alignment problems with targetname[] ? */
  41. struct sf_direct {
  42. int flags; /* flags about the file (see below) */
  43. unsigned int length; /* size of file in bytes */
  44. long index; /* index of header sector on disk */
  45. long seclen; /* number of sectors (inc headers) */
  46. char name[MAXSFNAME+1]; /* the name of the file */
  47. int samptype; /* the type of samples */
  48. int nochans; /* the number of channels */
  49. int samprate; /* the sampling rate */
  50. /* sfsysEx */
  51. int origwordsize; /*recognize 8bit sfiles */
  52. int is_shortcut;
  53. char targetname[256]; /*_MAX_PATH = 255*/
  54. fileformat fmt;
  55. };
  56. /*
  57. * structure for various information about the soundfiling system
  58. */
  59. struct sfdata {
  60. long version;
  61. long base_sf_fd; /* lowest possible sf filedescriptor */
  62. long limit_sf_fd; /* limit of sf filedescriptors */
  63. long base_snd_fd; /* lowest possible snd filedescriptor */
  64. long limit_snd_fd; /* limit of snd filedescriptors */
  65. };
  66. /*
  67. * the format of a raw disk configuration block - mostly a fudge!
  68. */
  69. #define MAXPARTS (64) /* maximum number of SFS partitions */
  70. struct partinfo { /* information about a partition */
  71. short unit_no; /* SCSI unit number (log|ctrl) */
  72. long phys_start; /* phys. address of first sector(ie sf_start) */
  73. long sf_start; /* logical address of first sector */
  74. long sf_end; /* logical address of last valid sec in part. */
  75. };
  76. struct rdskcfg {
  77. long disksize; /* number of sectors available for the sfs */
  78. short npart; /* number of partitions */
  79. struct partinfo pinfo[MAXPARTS]; /* information on the partitions */
  80. };
  81. /*
  82. * First special routines
  83. */
  84. extern char *sfgetbigbuf(int *secsize); /* create a big memory buffer */
  85. extern int sfdata(struct sfdata *, int size); /* get information about sfsys */
  86. /*
  87. * The dummy prefix stuff
  88. */
  89. extern int sfsetprefix(char *path);
  90. extern void sfgetprefix(char *path);
  91. extern int rdiskcfg(struct rdskcfg *);
  92. /*
  93. * The main (DEPRECATED) sf functions
  94. */
  95. extern int sfdir(int SFCALLS (*func)(struct sf_direct *filedetails), int flags);
  96. extern int sfopen(const char *name);
  97. extern int sfcreat(const char *name, int sizein, int *sizeout);
  98. extern int sfclose(int sfd);
  99. extern int sfunlink(int sfd);
  100. //extern long sfrename(int sfd, const char *newname);
  101. //extern long sf_makepath(char path[], const char* sfname);
  102. extern int SFCALLS STDARGS sfread(int sfd, char *buf, int cnt);
  103. extern int SFCALLS STDARGS sfwrite(int sfd, char *buf, int cnt);
  104. extern int sfseek(int sfd, int dist, int whence);
  105. #ifdef FILE64_WIN
  106. extern __int64 sfsize(int sfd);
  107. extern int sfadjust(int sfd, __int64 delta);
  108. #else
  109. extern __int64 sfsize(int sfd);
  110. extern int sfadjust(int sfd, __int64 delta);
  111. #endif
  112. extern int sfgetprop(int sfd, const char *propname, char *dest, int lim);
  113. extern int sfputprop(int sfd, char *propname, char *src, int size);
  114. extern int sfrmprop(int sfd, char *propname);
  115. extern int sfdirprop(int sfd, int (*func)(char *propname, int propsize));
  116. /*RWD OCT97 temp fudge to deal with 8bit sffiles...not to be used in applications! */
  117. extern int sfgetwordsize(int sfd);
  118. /*recognise shortcuts (aliasses) in WIN32*/
  119. /* this ~should~ be portable...*/
  120. /* return -1 for error, 0 for false, 1 for true */
  121. int sf_is_shortcut(int sfd,char *name);
  122. /* this is portable */
  123. /* return -1 for error, 0 otherwise */
  124. int sfformat(int sfd,fileformat *pfmt);
  125. /*support for mixed int formats*/
  126. int sf_getcontainersize(int sfd);
  127. int sf_getvalidbits(int sfd);
  128. /********** SFSYS 98 extended routines to support live streaming, header adjstments *******/
  129. /* creates full header; format cannot be changed later! */
  130. /* return -1 for error, else sfd*/
  131. #ifdef FILE64_WIN
  132. int sfcreat_formatted(const char *name, __int64 size, __int64 *outsize,int channels,
  133. int srate, int stype,cdp_create_mode mode);
  134. #else
  135. int sfcreat_formatted(const char *name, __int64 size, __int64 *outsize,int channels,
  136. int srate, int stype,cdp_create_mode mode);
  137. #endif
  138. /* re-entrant version of above, for GUI apps. Used in GrainMill. */
  139. /* keeps the input sfd; returns 1 for success, 0 for error */
  140. /* NB a snd~ version will be created asap! */
  141. #ifdef FILE64_WIN
  142. int sfrecreat_formatted(int sfd, __int64 size, __int64 *outsize,int channels,int srate, int stype);
  143. #else
  144. int sfrecreat_formatted(int sfd, __int64 size, __int64 *outsize,int channels,int srate, int stype);
  145. #endif
  146. /*return -1 for error, 0 for no peak info, 1 for success*/
  147. /* returns raw ANSI peaktime from header: use ctime() etc to decode */
  148. int sfreadpeaks(int sfd,int channels,CHPEAK peakdata[],int *peaktime);
  149. /* currently, we have to track PEAK data explicitly, and update header at the end.
  150. * eventually, there will be a frame-append function that updates PEAK info automatcally */
  151. /* return -1 for error, 0 for success */
  152. int sfputpeaks(int sfd,int channels,const CHPEAK peakdata[]);
  153. /* new version of sfopen, controlling access */
  154. int sfopenEx(const char *name,unsigned int access);
  155. const char* sf_getfilename(int ifd);
  156. extern int SFCALLS STDARGS sfread_buffered(int sfd, char *buf, int cnt);
  157. extern int SFCALLS STDARGS sfwrite_buffered(int sfd, char *buf, int cnt);
  158. #ifdef FILE64_WIN
  159. extern __int64 sfseek_buffered(int sfd, __int64 dist, int whence);
  160. int sfcreat_ex(const char *name, __int64 size, __int64 *outsize,
  161. SFPROPS *props,int min_header,cdp_create_mode mode);
  162. #else
  163. extern __int64 sfseek_buffered(int sfd, __int64 dist, int whence);
  164. int
  165. sfcreat_ex(const char *name, __int64 size, __int64 *outsize,
  166. SFPROPS *props,int min_header,cdp_create_mode mode);
  167. #endif
  168. int sfgetchanmask(int sfd);
  169. int sf_getchanformat(int sfd, channelformat *chformat);
  170. /* read sfile props into new structure, all in one go */
  171. extern int sf_headread(int fd,SFPROPS *props);
  172. #define SF_MAGIC (0x15927624) /* value of _sfmagic() */
  173. #define SF_CMAGIC (0x27182835) /* magic number for configuration */
  174. #define SF_UNLKMAGIC (0x46689275) /* magic value for rdiskunlck() */
  175. #define MSBFIRST (1)
  176. #define LSBFIRST (1)
  177. /* RWD extended set of symbols ! Now works for Mac universal Binary build */
  178. #if defined(__I86__) || defined(_X86_) || defined(__x86_64) || defined(__i386__) || defined(__i486__) || defined(_IBMR2)
  179. #undef MSBFIRST
  180. #elif defined(M68000) || defined(__sgi) || defined (__POWERPC__)
  181. #undef LSBFIRST
  182. #else
  183. #error "Unknown byte order for this processor"
  184. #endif
  185. #if defined(MSBFIRST) && defined(LSBFIRST)
  186. #error "Internal: can't be both MSB and LSB"
  187. #endif
  188. #define REVDWBYTES(t) ( (((t)&0xff) << 24) | (((t)&0xff00) << 8) | (((t)&0xff0000) >> 8) | (((t)>>24) & 0xff) )
  189. #define REVWBYTES(t) ( (((t)&0xff) << 8) | (((t)>>8) &0xff) )
  190. /*RWD.6.99 REV3BYTES is a function*/
  191. //static char * REV3BYTES(char *samp_24);
  192. extern int sampsize[];
  193. #ifdef MSBFIRST
  194. #define REVDATAINFILE(f) ((f)->filetype == riffwav || (f)->filetype == wave_ex)
  195. #else
  196. #define REVDATAINFILE(f) (((f)->filetype == eaaiff) || ((f)->filetype==aiffc))
  197. #endif
  198. #endif