24 #include <lal/LALStdlib.h>
25 #include <lal/LALStdio.h>
26 #include <lal/Audio.h>
28 #define LAL_SOUND_MAX 32760
34 char fname[FILENAME_MAX];
35 snprintf( fname,
sizeof( fname ),
"%s.%s",
name, extn );
43 UINT4 totalsize = datasize + 36;
44 INT4 byterate = samplerate *
sizeof(
UINT2 );
56 fputc( (totalsize & 0x000000ff) ,
fp );
57 fputc( (totalsize & 0x0000ff00) >> 8 ,
fp );
58 fputc( (totalsize & 0x00ff0000) >> 16 ,
fp );
59 fputc( (totalsize & 0xff000000) >> 24 ,
fp );
90 fputc( (samplerate & 0x000000ff) ,
fp );
91 fputc( (samplerate & 0x0000ff00) >> 8 ,
fp );
92 fputc( (samplerate & 0x00ff0000) >> 16,
fp );
93 fputc( (samplerate & 0xff000000) >> 24,
fp );
96 fputc( (byterate & 0x000000ff) ,
fp );
97 fputc( (byterate & 0x0000ff00) >> 8 ,
fp );
98 fputc( (byterate & 0x00ff0000) >> 16,
fp );
99 fputc( (byterate & 0xff000000) >> 24,
fp );
122 fputc( (datasize & 0x000000ff),
fp );
123 fputc( (datasize & 0x0000ff00) >> 8,
fp );
124 fputc( (datasize & 0x00ff0000) >> 16,
fp );
125 fputc( (datasize & 0xff000000) >> 24,
fp );
148 fputc( (datasize & 0xff000000) >> 24,
fp );
149 fputc( (datasize & 0x00ff0000) >> 16,
fp );
150 fputc( (datasize & 0x0000ff00) >> 8,
fp );
151 fputc( (datasize & 0x000000ff),
fp );
160 fputc( (samplerate & 0xff000000) >> 24,
fp );
161 fputc( (samplerate & 0x00ff0000) >> 16,
fp );
162 fputc( (samplerate & 0x0000ff00) >> 8,
fp );
163 fputc( (samplerate & 0x000000ff),
fp );
176 REAL4 maxval, minval, midval, scale;
180 maxval = minval = data->
data[0];
181 for ( i = 1; i < data->
length; ++i ) {
182 if ( data->
data[i] > maxval )
183 maxval = data->
data[i];
184 if ( data->
data[i] < minval )
185 minval = data->
data[i];
187 midval = 0.5*(maxval + minval);
190 if ( fabs( minval ) > fabs( maxval ) )
191 maxval = fabs( minval );
196 for ( i = 0; i < data->
length; ++i ) {
198 val = (
UINT2)( scale * (data->
data[i] - midval) );
199 fputc( (val & 0x00ff),
fp );
200 fputc( (val & 0xff00) >> 8,
fp );
203 for ( i = 0; i < data->
length; ++i ) {
206 fputc( (val & 0xff00) >> 8,
fp );
207 fputc( (val & 0x00ff),
fp );
215 REAL4 maxval, minval, midval, scale;
219 maxval = minval = data->
data[0];
220 for ( i = 1; i < data->
length; ++i ) {
221 if ( data->
data[i] > maxval )
222 maxval = data->
data[i];
223 if ( data->
data[i] < minval )
224 minval = data->
data[i];
226 midval = 0.5*(maxval + minval);
229 if ( fabs( minval ) > fabs( maxval ) )
230 maxval = fabs( minval );
235 for ( i = 0; i < data->
length; ++i ) {
237 val = (
UINT2)( scale * (data->
data[i] - midval) );
238 fputc( (val & 0x00ff),
fp );
239 fputc( (val & 0xff00) >> 8,
fp );
242 for ( i = 0; i < data->
length; ++i ) {
245 fputc( (val & 0xff00) >> 8,
fp );
246 fputc( (val & 0x00ff),
fp );
262 if ( ! series->
data )
269 if ( samplerate < 1 )
297 if ( ! series->
data )
304 if ( samplerate < 1 )
333 if ( ! series->
data )
340 if ( samplerate < 1 )
368 if ( ! series->
data )
375 if ( samplerate < 1 )
static int output_au_hdr(FILE *fp, INT4 samplerate, UINT4 datasize)
static FILE * fopen_if_null(FILE *fp, const char *name, const char *extn)
static int output_wav_hdr(FILE *fp, INT4 samplerate, UINT4 datasize)
static int output_REAL4Vector(FILE *fp, REAL4Vector *data, int wavfmt)
static int output_REAL8Vector(FILE *fp, REAL8Vector *data, int wavfmt)
int XLALAudioAURecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
Records a time series as a .au audio file.
int XLALAudioWAVRecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
Records a time series as a .wav audio file.
int XLALAudioWAVRecordREAL4TimeSeries(FILE *fp, REAL4TimeSeries *series)
Records a time series as a .wav audio file.
int XLALAudioAURecordREAL4TimeSeries(FILE *fp, REAL4TimeSeries *series)
Records a time series as a .au audio file.
uint16_t UINT2
Two-byte unsigned integer.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EINVAL
Invalid argument.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
CHAR name[LALNameLength]
The name of the time series.
REAL4Sequence * data
The sequence of sampled data.
REAL8 deltaT
The time step between samples of the time series in seconds.
Vector of type REAL4, see DATATYPE-Vector types for more details.
REAL4 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
REAL8Sequence * data
The sequence of sampled data.
REAL8 deltaT
The time step between samples of the time series in seconds.
CHAR name[LALNameLength]
The name of the time series.
Vector of type REAL8, see DATATYPE-Vector types for more details.
REAL8 * data
Pointer to the data array.
UINT4 length
Number of elements in array.