rename libimagedata to libcinelerradata
[cinelerra_cv/ct.git] / soundtest.c
blobc6fe46f9a151968f1c32c537157986b1a02b08ab
1 /*
2 Broadcast 2.0 multitrack audio editing
3 (c) 1997 Heroine Virtual
5 This program is distributed with the intent that it will be useful, without
6 any warranty. The code is being updated and has many bugs which are
7 constantly being elucidated so changes should not be made without notifying
8 the author.
9 */
11 /* Run at startup to permanently allocate your DMA buffers */
13 #include <sys/soundcard.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <sys/ioctl.h>
19 #include <math.h>
21 int main(int argc, char *argv[]){
22 int dsp;
23 int duplexenable = 1;
24 audio_buf_info playinfo, recinfo;
25 int bufsize = 0x7FFF0000;
26 int fragsize;
28 int format = AFMT_S16_LE;
29 int channels = 2;
30 int samplerate = 44100;
32 if(argc < 2)
34 bufsize += 15;
36 else
38 fragsize = atol(argv[1]);
39 if(fragsize <= 0) fragsize = 32768;
40 bufsize += (long)(log(fragsize) / log(2));
43 #ifdef USE_FULLDUPLEX
45 printf("*** Full duplex\n");
47 if((dsp = open("/dev/dsp", O_RDWR)) < 0){
48 printf("Can't open audio device.\n");
49 close(dsp);
50 return 1;
53 if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
54 printf("Couldn't set buffer parameters.\n");
56 if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
57 printf("Couldn't enable full duplex audio.\n");
58 duplexenable = 0;
61 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
62 printf("playback file format failed\n");
63 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
64 printf("playback channel allocation failed\n");
65 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
66 printf("playback sample rate set failed\n");
68 ioctl(dsp, SNDCTL_DSP_GETOSPACE, &playinfo);
70 printf(" fragments fragstotal fragsize bytes TOTAL BYTES AVAILABLE\n");
71 printf("Playback: %9d %10d %8d %7d %12d\n", playinfo.fragments,
72 playinfo.fragstotal, playinfo.fragsize, playinfo.bytes, playinfo.bytes);
74 if(duplexenable)
76 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
77 printf("record file format failed\n");
78 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
79 printf("record channel allocation failed\n");
80 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
81 printf("record sample rate set failed\n");
83 ioctl(dsp, SNDCTL_DSP_GETISPACE, &recinfo);
85 printf("Record: %9d %10d %8d %7d %12d\n", recinfo.fragments,
86 recinfo.fragstotal, recinfo.fragsize, recinfo.bytes, recinfo.fragstotal * recinfo.fragsize);
88 close(dsp);
91 #endif
94 printf("\n*** Half duplex\n");
96 if((dsp = open("/dev/dsp", O_WRONLY)) < 0){
97 printf("Can't open audio device.\n");
98 close(dsp);
99 return 1;
102 if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
103 printf("Couldn't set buffer parameters.\n");
105 if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
106 printf("Couldn't enable full duplex audio.\n");
107 duplexenable = 0;
110 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
111 printf("playback file format failed\n");
112 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
113 printf("playback channel allocation failed\n");
114 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
115 printf("playback sample rate set failed\n");
117 ioctl(dsp, SNDCTL_DSP_GETOSPACE, &playinfo);
119 printf(" fragments fragstotal fragsize bytes TOTAL BYTES AVAILABLE\n");
120 printf("Playback: %9d %10d %8d %7d %12d\n", playinfo.fragments,
121 playinfo.fragstotal, playinfo.fragsize, playinfo.bytes, playinfo.bytes);
122 close(dsp);
126 if((dsp = open("/dev/dsp", O_RDONLY)) < 0){
127 printf("Can't open audio device.\n");
128 close(dsp);
129 return 1;
132 if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
133 printf("Couldn't set buffer parameters.\n");
135 if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
136 printf("Couldn't enable full duplex audio.\n");
137 duplexenable = 0;
140 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
141 printf("playback file format failed\n");
142 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
143 printf("playback channel allocation failed\n");
144 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
145 printf("playback sample rate set failed\n");
147 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
148 printf("record file format failed\n");
149 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
150 printf("record channel allocation failed\n");
151 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
152 printf("record sample rate set failed\n");
157 ioctl(dsp, SNDCTL_DSP_GETISPACE, &recinfo);
159 printf("Record: %9d %10d %8d %7d %12d\n", recinfo.fragments,
160 recinfo.fragstotal, recinfo.fragsize, recinfo.bytes, recinfo.fragstotal * recinfo.fragsize);
162 ioctl(dsp, SNDCTL_DSP_RESET);
163 close(dsp);