1 /*
2     soundio.h:
3 
4     Copyright (C) 1991, 2000 Barry Vercoe, Richard Dobson
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23                                 /*                      SOUNDIO.H       */
24 #ifndef CSOUND_SOUNDIO_H
25 #define CSOUND_SOUNDIO_H
26 
27 #include <sndfile.h>
28 
29 #ifdef WIN32
30 #define IOBUFSAMPS   4096   /* default sampframes in audio iobuf, -b settable */
31 #define IODACSAMPS   16384  /* default samps in hardware buffer,  -B settable */
32 #elif defined(NeXT) || defined(__MACH__)
33 #define IOBUFSAMPS   1024   /* default sampframes in audio iobuf, -b settable */
34 #define IODACSAMPS   4096   /* default samps in hardware buffer,  -B settable */
35 #elif defined(ANDROID)
36 #define IOBUFSAMPS   2048   /* default sampframes in audio iobuf, -b settable */
37 #define IODACSAMPS   4096   /* default samps in hardware buffer,  -B settable */
38 #else
39 #define IOBUFSAMPS   256    /* default sampframes in audio iobuf, -b settable */
40 #define IODACSAMPS   1024   /* default samps in hardware buffer,  -B settable */
41 #endif
42 
43 #define SNDINBUFSIZ  4096   /* soundin bufsize;   must be > sizeof(SFHEADER), */
44                             /*                 but small is kind to net rexec */
45 #define MAXSNDNAME   1024
46 /* standard audio encoding types */
47 
48 #define AE_CHAR         SF_FORMAT_PCM_S8
49 #define AE_SHORT        SF_FORMAT_PCM_16
50 #define AE_24INT        SF_FORMAT_PCM_24
51 #define AE_LONG         SF_FORMAT_PCM_32
52 #define AE_UNCH         SF_FORMAT_PCM_U8
53 #define AE_FLOAT        SF_FORMAT_FLOAT
54 #define AE_DOUBLE       SF_FORMAT_DOUBLE
55 #define AE_ULAW         SF_FORMAT_ULAW
56 #define AE_ALAW         SF_FORMAT_ALAW
57 #define AE_IMA_ADPCM    SF_FORMAT_IMA_ADPCM
58 #define AE_MS_ADPCM     SF_FORMAT_MS_ADPCM
59 #define AE_GSM610       SF_FORMAT_GSM610
60 #define AE_VOX          SF_FORMAT_VOX_ADPCM
61 #define AE_G721_32      SF_FORMAT_G721_32
62 #define AE_G723_24      SF_FORMAT_G723_24
63 #define AE_G723_40      SF_FORMAT_G723_40
64 #define AE_DWVW_12      SF_FORMAT_DWVW_12
65 #define AE_DWVW_16      SF_FORMAT_DWVW_16
66 #define AE_DWVW_24      SF_FORMAT_DWVW_24
67 #define AE_DWVW_N       SF_FORMAT_DWVW_N
68 #define AE_DPCM_8       SF_FORMAT_DPCM_8
69 #define AE_DPCM_16      SF_FORMAT_DPCM_16
70 #define AE_VORBIS       SF_FORMAT_VORBIS
71 
72 #define AE_LAST   SF_FORMAT_DPCM_16     /* current last audio encoding value */
73 
74 /* file types */
75 
76 #define TYP_WAV   (SF_FORMAT_WAV >> 16)
77 #define TYP_AIFF  (SF_FORMAT_AIFF >> 16)
78 #define TYP_AU    (SF_FORMAT_AU >> 16)
79 #define TYP_RAW   (SF_FORMAT_RAW >> 16)
80 #define TYP_PAF   (SF_FORMAT_PAF >> 16)
81 #define TYP_SVX   (SF_FORMAT_SVX >> 16)
82 #define TYP_NIST  (SF_FORMAT_NIST >> 16)
83 #define TYP_VOC   (SF_FORMAT_VOC >> 16)
84 #define TYP_IRCAM (SF_FORMAT_IRCAM >> 16)
85 #define TYP_W64   (SF_FORMAT_W64 >> 16)
86 #define TYP_MAT4  (SF_FORMAT_MAT4 >> 16)
87 #define TYP_MAT5  (SF_FORMAT_MAT5 >> 16)
88 #define TYP_PVF   (SF_FORMAT_PVF >> 16)
89 #define TYP_XI    (SF_FORMAT_XI >> 16)
90 #define TYP_HTK   (SF_FORMAT_HTK >> 16)
91 #define TYP_SDS   (SF_FORMAT_SDS >> 16)
92 #define TYP_AVR   (SF_FORMAT_AVR >> 16)
93 #define TYP_WAVEX (SF_FORMAT_WAVEX >> 16)
94 #define TYP_SD2   (SF_FORMAT_SD2 >> 16)
95 #define TYP_FLAC  (SF_FORMAT_FLAC >> 16)
96 #define TYP_CAF   (SF_FORMAT_CAF >> 16)
97 #define TYP_WVE   (SF_FORMAT_WVE >> 16)
98 #define TYP_OGG   (SF_FORMAT_OGG >> 16)
99 #define TYP_MPC2K (SF_FORMAT_MPC2K >> 16)
100 #define TYP_RF64  (SF_FORMAT_RF64 >> 16)
101 
102 #define FORMAT2SF(x) ((int) (x))
103 #define SF2FORMAT(x) ((int) (x) & 0xFFFF)
104 #define TYPE2SF(x)   ((int) (x) << 16)
105 #define SF2TYPE(x)   ((int) (x& SF_FORMAT_TYPEMASK) >> 16)
106 
107 #ifdef  USE_DOUBLE
108 #define sf_write_MYFLT  sf_write_double
109 #define sf_writef_MYFLT  sf_writef_double
110 #define sf_read_MYFLT   sf_read_double
111 #else
112 #define sf_write_MYFLT  sf_write_float
113 #define sf_writef_MYFLT  sf_writef_float
114 #define sf_read_MYFLT   sf_read_float
115 #endif
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 
121 /* generic sound input structure */
122 
123 typedef struct {
124         SNDFILE *sinfd;             /* sound file handle                    */
125         MYFLT   *inbufp, *bufend;   /* current buffer position, end of buf  */
126         void    *fd;                /* handle returned by csoundFileOpen()  */
127         int     bufsmps;            /* number of mono samples in buffer     */
128         int     format;             /* sample format (AE_SHORT, etc.)       */
129         int     channel;            /* requested channel (ALLCHNLS: all)    */
130         int     nchanls;            /* number of channels in file           */
131         int     sampframsiz;        /* sample frame size in bytes           */
132         int     filetyp;            /* file format (TYP_WAV, etc.)          */
133         int     analonly;           /* non-zero for analysis utilities      */
134         int     endfile;            /* end of file reached ? non-zero: yes  */
135         int     sr;                 /* sample rate in Hz                    */
136         int     do_floatscaling;    /* scale floats by fscalefac ? 0: no    */
137         int64_t audrem, framesrem, getframes;   /* samples, frames, frames */
138         MYFLT   fscalefac;
139         MYFLT   skiptime;
140         char    sfname[MAXSNDNAME];
141         MYFLT   inbuf[SNDINBUFSIZ];
142 } SOUNDIN;
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif      /* CSOUND_SOUNDIO_H */
149 
150