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
11 /* Run at startup to permanently allocate your DMA buffers */
13 #include <sys/soundcard.h>
18 #include <sys/ioctl.h>
21 int main(int argc
, char *argv
[]){
24 audio_buf_info playinfo
, recinfo
;
25 int bufsize
= 0x7FFF0000;
28 int format
= AFMT_S16_LE
;
30 int samplerate
= 44100;
38 fragsize
= atol(argv
[1]);
39 if(fragsize
<= 0) fragsize
= 32768;
40 bufsize
+= (long)(log(fragsize
) / log(2));
45 printf("*** Full duplex\n");
47 if((dsp
= open("/dev/dsp", O_RDWR
)) < 0){
48 printf("Can't open audio device.\n");
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");
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
);
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
);
94 printf("\n*** Half duplex\n");
96 if((dsp
= open("/dev/dsp", O_WRONLY
)) < 0){
97 printf("Can't open audio device.\n");
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");
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
);
126 if((dsp
= open("/dev/dsp", O_RDONLY
)) < 0){
127 printf("Can't open audio device.\n");
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");
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
);