transition length popup rework
[goodguy/cinelerra.git] / cinelerra-5.1 / soundtest.c
1 /*
2   Broadcast 2.0 multitrack audio editing
3   (c) 1997 Heroine Virtual
4
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 */
10
11 /* Run at startup to permanently allocate your DMA buffers */
12
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>
20
21 int main(int argc, char *argv[])
22 {
23         int dsp;
24         int duplexenable = 1;
25         audio_buf_info playinfo, recinfo;
26         int bufsize = 0x7FFF0000;
27         int fragsize;
28
29         int format = AFMT_S16_LE;
30         int channels = 2;
31         int samplerate = 44100;
32
33         if(argc < 2)
34         {
35                 bufsize += 15;
36         }
37         else
38         {
39                 fragsize = atol(argv[1]);
40                 if(fragsize <= 0) fragsize = 32768;
41                 bufsize += (long)(log(fragsize) / log(2));
42         }
43
44 #ifdef USE_FULLDUPLEX
45
46         printf("*** Full duplex\n");
47
48         if((dsp = open("/dev/dsp", O_RDWR)) < 0){
49         printf("Can't open audio device.\n");
50         close(dsp);
51         return 1;
52         }
53
54         if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
55                 printf("Couldn't set buffer parameters.\n");
56
57         if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
58                 printf("Couldn't enable full duplex audio.\n");
59                 duplexenable = 0;
60         }
61
62         if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
63        printf("playback file format failed\n");
64         if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
65        printf("playback channel allocation failed\n");
66         if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
67        printf("playback sample rate set failed\n");
68
69         ioctl(dsp, SNDCTL_DSP_GETOSPACE, &playinfo);
70
71         printf("          fragments fragstotal fragsize   bytes  TOTAL BYTES AVAILABLE\n");
72         printf("Playback: %9d %10d %8d %7d %12d\n", playinfo.fragments, 
73                 playinfo.fragstotal, playinfo.fragsize, playinfo.bytes, playinfo.bytes);
74
75         if(duplexenable)
76         {
77                 if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
78                  printf("record file format failed\n");
79                 if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
80                  printf("record channel allocation failed\n");
81                 if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
82                  printf("record sample rate set failed\n");
83
84                 ioctl(dsp, SNDCTL_DSP_GETISPACE, &recinfo);
85
86                 printf("Record:   %9d %10d %8d %7d %12d\n", recinfo.fragments, 
87                         recinfo.fragstotal, recinfo.fragsize, recinfo.bytes, recinfo.fragstotal * recinfo.fragsize);
88         }
89         close(dsp);
90
91
92 #endif
93
94
95         printf("\n*** Half duplex\n");
96
97   if((dsp = open("/dev/dsp", O_WRONLY)) < 0){
98     printf("Can't open audio device.\n");
99     close(dsp);
100     return 1;
101   }
102
103   if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
104         printf("Couldn't set buffer parameters.\n");
105   
106         if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
107                 printf("Couldn't enable full duplex audio.\n");
108                 duplexenable = 0;
109         }
110
111   if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
112      printf("playback file format failed\n");
113   if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
114      printf("playback channel allocation failed\n");
115   if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
116      printf("playback sample rate set failed\n");
117
118   ioctl(dsp, SNDCTL_DSP_GETOSPACE, &playinfo);
119
120         printf("          fragments fragstotal fragsize   bytes  TOTAL BYTES AVAILABLE\n");
121         printf("Playback: %9d %10d %8d %7d %12d\n", playinfo.fragments, 
122                 playinfo.fragstotal, playinfo.fragsize, playinfo.bytes, playinfo.bytes);
123         close(dsp);
124
125
126
127   if((dsp = open("/dev/dsp", O_RDONLY)) < 0){
128     printf("Can't open audio device.\n");
129     close(dsp);
130     return 1;
131   }
132
133   if (ioctl(dsp, SNDCTL_DSP_SETFRAGMENT, &bufsize))
134         printf("Couldn't set buffer parameters.\n");
135   
136         if(duplexenable && ioctl(dsp, SNDCTL_DSP_SETDUPLEX, 0) == -1){
137                 printf("Couldn't enable full duplex audio.\n");
138                 duplexenable = 0;
139         }
140
141   if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
142      printf("playback file format failed\n");
143   if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
144      printf("playback channel allocation failed\n");
145   if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
146      printf("playback sample rate set failed\n");
147
148         if(ioctl(dsp, SNDCTL_DSP_SETFMT, &format) < 0)
149          printf("record file format failed\n");
150         if(ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) < 0)
151          printf("record channel allocation failed\n");
152         if(ioctl(dsp, SNDCTL_DSP_SPEED, &samplerate) < 0)
153          printf("record sample rate set failed\n");
154
155
156
157
158         ioctl(dsp, SNDCTL_DSP_GETISPACE, &recinfo);
159
160         printf("Record:   %9d %10d %8d %7d %12d\n", recinfo.fragments, 
161                 recinfo.fragstotal, recinfo.fragsize, recinfo.bytes, recinfo.fragstotal * recinfo.fragsize);
162         
163   ioctl(dsp, SNDCTL_DSP_RESET);
164   close(dsp);
165   return 0;
166 }
167
168
169
170