1
/* $Header: /cvsroot/qgo/qgo/src/wavplay.h,v 1.3 2004/10/30 23:35:00 yfh2 Exp $
2
* Warren W. Gay VE3WWG Sun Feb 16 18:17:17 1997
4
* WAVPLAY OPTION SETTINGS:
8
* Copyright (C) 1997 Warren W. Gay VE3WWG
10
* This program is free software; you can redistribute it and/or modify it
11
* under the terms of the GNU General Public License as published by the
12
* Free Software Foundation version 2 of the License.
14
* This program is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17
* Public License for more details (see enclosed file COPYING).
19
* You should have received a copy of the GNU General Public License along
20
* with this program; if not, write to the Free Software Foundation, Inc.,
21
* 675 Mass Ave, Cambridge, MA 02139, USA.
23
* Send correspondance to:
25
* Warren W. Gay VE3WWG
29
* wgay@mackenziefinancial.com
32
* Revision 1.1 2003/04/07 10:28:54 frosla
33
* 0.0.16b3: added real sound support for Unix!!!!
35
* Revision 1.3 1999/12/04 00:05:34 wwg
36
* Fixed release number
38
* Revision 1.2 1999/12/04 00:01:20 wwg
39
* Implement wavplay-1.4 release changes
41
* Revision 1.1.1.1 1999/11/21 19:50:56 wwg
42
* Import wavplay-1.3 into CVS
44
* Revision 1.4 1997/04/17 23:39:26 wwg
45
* Now at 1.0pl2 : attempting to fix Linux 2.0.29 compile problems
46
* with the way errno and sys_errlist[] are handled for thread
47
* safety.. here we removed our incompatible extern sys_errlist[]
49
* Revision 1.3 1997/04/17 01:59:37 wwg
50
* Added version change to reflect patch level "1.0pl1"
52
* Revision 1.2 1997/04/17 00:27:36 wwg
53
* Fixed references to the name errno. For thread safety
54
* this name has been macro-ized, which I should have
55
* anticipated, since I knew it was coming.
57
* Revision 1.1 1997/04/14 00:56:48 wwg
65
#define _wavplay_h_ "$Id: wavplay.h,v 1.3 2004/10/30 23:35:00 yfh2 Exp $"
67
#define WAVPLAY_VERSION "1.4"
71
#include <sys/types.h>
78
* From the man page semctl(2) :
80
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
81
/* union semun is defined by including <sys/sem.h> */
83
/* according to X/OPEN we have to define it ourselves */
85
int val; /* value for SETVAL */
86
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
87
unsigned short *array; /* array for GETALL, SETALL */
88
struct seminfo *__buf; /* buffer for IPC_INFO */
92
typedef void (*ErrFunc)(const char *format,va_list ap);
97
* Default location of the wavplay server program if not overrided by the Makefile
100
#define WAVPLAYPATH "/usr/local/bin/wavplay" /* Default location of wavplay server */
104
* Default pathname for recordings if not overriden by the Makefile:
107
#define RECORD_PATH "recorded.wav"
111
* Default lowest sampling rate unless overriden by the Makefile:
114
#define DSP_MIN 4000 /* Lowest acceptable sample rate */
118
* Default maximum sampling rate unless overrided by the Makefile:
121
#define DSP_MAX 48000 /* Highest acceptable sample rate */
125
* Default pathname of the audio device, unless overrided by the Makefile:
128
#define AUDIODEV "/dev/dsp" /* Default pathname for audio device */
132
* Default locking semaphore IPC Key, unless overrided by the Makefile:
135
#define AUDIOLCK 0x33333333 /* Default IPC Key for semaphores */
139
* Short option flag characters:
141
#define OPF_DEVICE 'd' /* -d device ; Override /dev/dsp default */
142
#define OPF_INFO 'i' /* -i ; info mode option */
143
#define OPF_HELP 'h' /* -h ; help optino */
144
#define OPF_QUIET 'q' /* -q ; quiet mode */
145
#define OPF_SAMPRATE 's' /* -s rate ; Sampling rate */
146
#define OPF_STEREO 'S' /* -S ; Stereo */
147
#define OPF_MONO 'M' /* -M ; Mono */
148
#define OPF_TIME 't' /* -t seconds ; Time option */
149
#define OPF_DATABITS 'b' /* -b data_bits; sample bits */
150
#define OPF_IPCKEY 'k' /* -k key ; IPC Key */
151
#define OPF_RESET 'R' /* -r ; reset semaphores option */
152
#define OPF_PLAY_LOCK 'l' /* -l ; lock for play option */
153
#define OPF_PLAY_UNLOCK 'u' /* -u ; unlock play option */
154
#define OPF_RECD_LOCK 'L' /* -L ; lock for record option */
155
#define OPF_RECD_UNLOCK 'U' /* -U ; unlock record option */
156
#define OPF_DEBUG 'x' /* -x ; debug option */
157
#define OPF_VERSION 'V' /* -V ; version and copyright */
160
* Types internal to wavplay, in an attempt to isolate ourselves from
161
* a dependance on a particular platform.
163
typedef unsigned char Byte;
166
typedef unsigned long UInt32;
167
typedef unsigned short UInt16;
170
* This value sets buffer sizes for temporary buffers that sprintf()
171
* uses, and for copying pathnames around in. You probably don't want
174
#define MAXTXTLEN 2048 /* Must allow for long pathnames */
177
* These are the wavplay command operation modes.
180
OprNoMode=0, /* No mode given (not determined yet) */
181
OprRecord=1, /* wavplay command is in "Record Mode" */
182
OprPlay=2, /* wavplay command is in "Play Mode" */
183
OprServer=3 /* wavplay is accting in "Server Mode" */
187
* This enumerated type, selects between monophonic sound and
188
* stereo sound (1 or 2 channels).
191
Mono, /* Monophonic sound (1 channel) */
192
Stereo /* Stereo sound (2 channels) */
196
* This type is used for those options that can be one or another
197
* option flags (represented as the ASCII character), or no option
198
* flags at all (zero value, ie. 0x00).
201
char optChar; /* Option character */
205
* This type represents any unsigned 32 bit option value, if the member
206
* optChar is non-zero (usually holds the ASCII flag option character).
207
* If optChar is zero, then no value is present (or specified).
210
char optChar; /* Zero if not valid, else non-zero if active */
211
UInt32 optValue; /* The unsigned 32 bit value if optChar is true */
215
char optChar; /* Zero if not valid, else non-zero if active */
216
UInt16 optValue; /* The unsigned 16 bit value if optChar is true */
220
char optChar; /* Zero if not valid, else non-zero if active */
221
Chan optValue; /* The enumerated value for Stereo/Mono */
225
* This structure holds the command line options for the wavplay command.
226
* It is also used to pass option values around (in server mode etc.)
229
key_t IPCKey; /* Default IPC Key for lock */
230
OprMode Mode; /* Operation Mode: OprRecord or OprPlay */
231
FlgOpt PlayLock; /* -l or -u option flag */
232
FlgOpt RecdLock; /* -L or -U option flag */
233
char bResetLocks; /* True if semaphores are to be reset */
234
char bQuietMode; /* True if quiet mode is requested */
235
char bInfoMode; /* True if only wav header info is to be printed */
236
U32Opt SamplingRate; /* -s rate ; sampling rate in Hz */
237
ChnOpt Channels; /* -S ; or no -S option (stereo/mono respectively) */
238
U16Opt DataBits; /* -b bits ; number of bits per sample */
239
UInt32 Seconds; /* Time limited to this many seconds, else zero */
240
UInt32 StartSample; /* Sample to start playback with */
241
int ipc; /* Semaphore IPC ID */
245
* These values represent values found in/or destined for a
249
UInt32 SamplingRate; /* Sampling rate in Hz */
250
Chan Channels; /* Mono or Stereo */
251
UInt32 Samples; /* Sample count */
252
UInt16 DataBits; /* Sample bit size (8/12/16) */
253
UInt32 DataStart; /* Offset to wav data */
254
UInt32 DataBytes; /* Data bytes in current chunk */
255
char bOvrSampling; /* True if sampling_rate overrided */
256
char bOvrMode; /* True if chan_mode overrided */
257
char bOvrBits; /* True if data_bits is overrided */
261
* This structure manages an open WAV file.
264
char rw; /* 'R' for read, 'W' for write */
265
char *Pathname; /* Pathname of wav file */
266
int fd; /* Open file descriptor or -1 */
267
WAVINF wavinfo; /* WAV file hdr info */
268
UInt32 num_samples; /* Total number of samples */
269
UInt32 StartSample; /* First sample to play */
273
* This macro is used to return the system file descriptor
274
* associated with the open WAV file, given a (WAVFILE *).
276
#define WAV_FD(wfile) (wfile->fd) /* Return file descriptor */
279
* This structure manages an opened DSP device.
282
int fd; /* Open fd of /dev/dsp */
283
int dspblksiz; /* Size of the DSP buffer */
284
char *dspbuf; /* The buffer */
288
* This structure manages server information and state:
291
UInt32 SamplingRate; /* Sampling rate in Hz */
292
Chan Channels; /* Mono or Stereo */
293
UInt32 Samples; /* Sample count */
294
UInt16 DataBits; /* Sample bit size (8/12/16) */
295
char WavType[16]; /* "PCM" */
296
char bOvrSampling; /* True if sampling is overrided */
297
char bOvrMode; /* True if mode is overrided */
298
char bOvrBits; /* True if bits is overrided */
302
* This is the function type that is called between blocks
303
* of I/O with the DSP.
305
typedef int (*DSPPROC)(DSPFILE *dfile); /* DSP work procedure */
308
* Client/Server Message Types. These definitions must be coordinated with
309
* source module msg.c, function msg_name(), for their corresponding
313
ToClnt_Fatal=0, /* Fatal server error */
314
ToClnt_Ready=1, /* Tell client that server is ready */
315
ToSvr_Bye=2, /* Client tells server to exit */
316
ToSvr_Path=3, /* Client tells server a pathname */
317
ToClnt_Path=4, /* Client tells server a pathname */
318
ToClnt_Stat=5, /* Response: Svr->Clnt to ToSvr_Path */
319
ToClnt_WavInfo=6, /* Server tells client wav info */
320
ToSvr_Play=7, /* Client tells server to play */
321
ToSvr_Pause=8, /* Tell server to pause */
322
ToSvr_Stop=9, /* Tell server to stop */
323
ToSvr_Bits=10, /* Tell server to use 8 bits */
324
ToClnt_Bits=11, /* Server tells what bit setting is in effect */
325
ToClnt_Settings=12, /* Current server settings */
326
ToSvr_SamplingRate=13, /* Tell server new sampling rate */
327
ToSvr_Restore=14, /* Clear overrides: restore original settings */
328
ToSvr_Chan=15, /* Change Stereo/Mono mode */
329
ToSvr_Record=16, /* Tell server to start recording */
330
ToSvr_Debug=17, /* Tell server debug mode setting */
331
ToClnt_ErrMsg=18, /* Pass back to client, an error message string */
332
ToSvr_SemReset=19, /* Reset locking semaphores */
333
ToSvr_StartSample=20, /* Start playback at requested sample */
334
ToClnt_PlayState=21, /* Playback status */
335
ToClnt_RecState=22, /* Record status */
336
MSGTYP_Last=23 /* This is not really a message type */
340
* Client/Server Message Structure: This consists of a common header
341
* component, and then a union of specific format variations according
342
* to the message type.
345
long type; /* Message Type: 1=server, 0=client */
346
MSGTYP msg_type; /* Client/Server message type */
347
UInt16 bytes; /* Byte length of the union */
351
* Message from server to client, to convey a fatal error that
352
* has occured in the server.
355
int Errno; /* Error code */
356
char msg[128]; /* Error message text */
360
* Message from the X client, to the server, to indicate that
361
* a new pathname is to be referenced.
364
char path[1024]; /* Pathname */
365
} tosvr_path; /* Tell server a pathname */
368
* Message from the server to the X client, to indicate
369
* that the indicated pathname has been accepted and
370
* ready (the pathname may be canonicalized at some future
371
* revision of the server)
374
char path[1024]; /* Pathname */
375
} toclnt_path; /* ..from server as confirmation */
378
* Message to X client, from the server, indicating a
379
* stat() error when Errno != 0, or stat() information
383
int Errno; /* Zero if OK, else errno from stat() */
384
struct stat sbuf; /* Path's stat info */
388
* Message to X client, from server, indicating an
389
* error if errno != 0, or successfully obtained
390
* WAV file info if errno == 0.
393
int Errno; /* Zero if OK, else errno value */
394
WAVINF wavinfo; /* WAV file info */
395
char errmsg[256]; /* Error message */
399
* Message from X client, to server, indicating how
400
* many bits per sample to use (request).
403
int DataBits; /* 8/12/16 bit override requested */
407
* Message to X client, from server, indicating
408
* the accepted number of bits per sample (response
412
int DataBits; /* Server says this # of bits in effect */
416
* Message to X client, from server, indicating the
417
* current server settings.
419
SVRINF toclnt_settings; /* Current server settings */
422
* Message from X client, to server, indicating the
423
* requested sampling rate to use (request).
425
struct S_SvrSampRate {
426
UInt32 SamplingRate; /* In Hz */
427
} tosvr_sampling_rate;
430
* Message from X client, to server, indicating the
431
* number of channels to use (request).
434
Chan Channels; /* New channel mode: Stereo/Mono */
438
* Message from X client, to server, indicating the sample to
439
* start playback at (request).
442
UInt32 StartSample; /* New origin */
443
} tosvr_start_sample;
446
* Message from X client, to server, indicating the
447
* channels to use, the sampling rate to use, and
448
* the data bits per channel to use (request).
451
Chan Channels; /* Stereo or Mono */
452
UInt32 SamplingRate; /* Start recording at this rate */
453
UInt16 DataBits; /* 8/12/16 data bits */
457
* Message from X client to server, to set the server's
458
* debug mode global (cmdopt_x).
461
char bDebugMode; /* True if debug mode set, else not debug mode */
465
* Message from server to client, to convey a NON-fatal error that
466
* has occured in the server.
469
int Errno; /* Error code */
470
char msg[512]; /* Error message text */
474
* Message from server to client with playback status.
477
int CurrentSample; /* Currently playing sample */
478
int SamplesLeft; /* Samples left */
482
* Message from server to client with record status.
485
int bytes_written; /* Number of bytes sampled */
486
int num_samples; /* Samples taken */
488
} u; /* The message union of all message types */
491
extern char *ProcTerm(int procstat);
493
extern int MsgCreate(void);
494
extern int MsgSend(int ipcid,SVRMSG *msg,int flags,long msgtype);
495
extern int MsgRecv(int ipcid,SVRMSG *msg,int flags,long msgtype);
496
extern int MsgClose(int ipcid);
497
extern char *msg_name(MSGTYP mtyp);
498
extern void msg_dump(const char *desc,MSGTYP mtyp);
500
#define MSGNO_CLNT 3L
501
#define MSGNO_SRVR 2L
502
#define MsgToClient(ipcid,msg,flags) MsgSend(ipcid,msg,flags,MSGNO_CLNT)
503
#define MsgToServer(ipcid,msg,flags) MsgSend(ipcid,msg,flags,MSGNO_SRVR)
504
#define MsgFromClient(ipcid,msg,flags) MsgRecv(ipcid,msg,flags,MSGNO_SRVR)
505
#define MsgFromServer(ipcid,msg,flags) MsgRecv(ipcid,msg,flags,MSGNO_CLNT)
507
extern int OpenDSPLocks(key_t LockIPCKey,int SemUndoFlag,ErrFunc erf);
508
extern int LockDSP(int ipc,int playrecx,ErrFunc erf,unsigned timeout_secs);
509
extern int UnlockDSP(int ipc,int playrecx,ErrFunc erf);
511
extern WAVFILE *WavOpenForRead(const char *Pathname,ErrFunc erf);
512
extern WAVFILE *WavOpenForWrite(const char *Pathname,OprMode m,UInt32 sample_rate,UInt16 bits,UInt32 samples,ErrFunc erf);
513
extern void WavReadOverrides(WAVFILE *wfile,WavPlayOpts *wavopts);
514
extern int WavClose(WAVFILE *wfile,ErrFunc erf);
516
extern DSPFILE *OpenDSP(WAVFILE *wfile,int omode,ErrFunc erf);
517
extern int PlayDSP(DSPFILE *dfile,WAVFILE *wfile,DSPPROC work_proc,ErrFunc erf);
518
extern int RecordDSP(DSPFILE *dfile,WAVFILE *wfile,UInt32 samples,DSPPROC work_proc,ErrFunc erf);
519
extern int CloseDSP(DSPFILE *dfile,ErrFunc erf);
521
extern int recplay(WavPlayOpts *wavopts,char **argv,ErrFunc erf);
522
/*/extern int wavplay(WavPlayOpts *wavopts,char *argv,ErrFunc erf);*/
523
extern int wavplay(char *argv,ErrFunc erf);
524
extern int wavrecd(WavPlayOpts *wavopts,char *Pathname,ErrFunc erf);
526
extern void RegisterSigHandlers(void);
528
/*/extern void play(char *Pathname);*/
530
#endif /* _wavplay_h_ */
535
/* $Source: /cvsroot/qgo/qgo/src/wavplay.h,v $ */