1 | #define INCL_DOS
|
---|
2 | #define INCL_KBD
|
---|
3 | #define INCL_DOSERRORS
|
---|
4 | #include <os2.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <io.h>
|
---|
8 | #include <fcntl.h>
|
---|
9 | #include <conio.h>
|
---|
10 | #include <math.h>
|
---|
11 |
|
---|
12 | #include "uniaud.h"
|
---|
13 | #include "unidef.h"
|
---|
14 | #include "errno.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | int pcms_num[MAX_CARDS] = {0}; // number of pcm instances
|
---|
18 | int cards_num = 0; // number of cards
|
---|
19 |
|
---|
20 | POSS32_DEVCAPS pcmcaps[MAX_CARDS] = {0}; // pointer to pcm caps
|
---|
21 |
|
---|
22 | UniaudCardInfo *CardInfo[MAX_CARDS] = {0};
|
---|
23 |
|
---|
24 | snd_pcm_status_t status;
|
---|
25 |
|
---|
26 | int read_key(void)
|
---|
27 | {
|
---|
28 | static ULONG time = 0;
|
---|
29 | KBDKEYINFO Char;
|
---|
30 |
|
---|
31 | KbdCharIn(&Char, IO_NOWAIT, 0);
|
---|
32 |
|
---|
33 | if (time == Char.time)
|
---|
34 | return 0;
|
---|
35 |
|
---|
36 | time = Char.time;
|
---|
37 |
|
---|
38 | return Char.chChar;
|
---|
39 | }
|
---|
40 |
|
---|
41 | int main (int argc, char *argv[])
|
---|
42 | {
|
---|
43 | int ver, err, ret;
|
---|
44 | int bytesread, count;
|
---|
45 | int card_id = 0;
|
---|
46 | uniaud_pcm *pcm = NULL;
|
---|
47 | char *Buffer;
|
---|
48 | int readed, state;
|
---|
49 | FILE *input_handle;
|
---|
50 | int key;
|
---|
51 |
|
---|
52 |
|
---|
53 | printf("PCM read tool for UNIAUD. Version 0.01\n");
|
---|
54 | printf("Copyright 2004 by Vlad Stelmahosky aka Vladest\n");
|
---|
55 |
|
---|
56 | ver = uniaud_get_version();
|
---|
57 |
|
---|
58 | switch (ver)
|
---|
59 | {
|
---|
60 | case -2:
|
---|
61 | printf("Error: uniaud not detected\n");
|
---|
62 | return 1;
|
---|
63 | break;
|
---|
64 | case -1:
|
---|
65 | printf("Error: uniaud error\n");
|
---|
66 | return 1;
|
---|
67 | break;
|
---|
68 | default:
|
---|
69 | if (ver < 111 )
|
---|
70 | {
|
---|
71 | printf("Error: unsupported version of uniaud\n");
|
---|
72 | return 1;
|
---|
73 | } else
|
---|
74 | printf("Detected UNIAUD version %1d.%02d.%02d\n", ver/10000, (ver / 100) % 100, ver % 100 );
|
---|
75 | }
|
---|
76 |
|
---|
77 | cards_num = uniaud_get_cards();
|
---|
78 | if (!cards_num)
|
---|
79 | {
|
---|
80 | printf("No audio cards detected\n");
|
---|
81 | return 1;
|
---|
82 | }
|
---|
83 |
|
---|
84 | printf("Detected %i audio adapter(s)\n", cards_num);
|
---|
85 | #if 0
|
---|
86 | // set capture to ON
|
---|
87 | if (uniaud_mixer_put_value_by_name(card_id,"Capture Switch",1, 0, 0) < 0)
|
---|
88 | {
|
---|
89 | printf("Error in mixer\n");
|
---|
90 | }
|
---|
91 | #endif
|
---|
92 | if (uniaud_mixer_put_value_by_name(card_id,"Capture Volume",10, 0, 0) < 0)
|
---|
93 | {
|
---|
94 | printf("Error in mixer\n");
|
---|
95 | }
|
---|
96 | if (uniaud_mixer_put_value_by_name(card_id,"Capture Volume",10, 1, 0) < 0)
|
---|
97 | {
|
---|
98 | printf("Error in mixer\n");
|
---|
99 | }
|
---|
100 | // set source to LINE IN fo chan 1
|
---|
101 | if (uniaud_mixer_put_value_by_name(card_id,"Capture Source",1, 0, 0) < 0)
|
---|
102 | {
|
---|
103 | printf("Error in mixer\n");
|
---|
104 | }
|
---|
105 | #if 0
|
---|
106 | // set source to LINE IN fo chan 2
|
---|
107 | if (uniaud_mixer_put_value_by_name(card_id,"Capture Source",0, 1, 0) < 0)
|
---|
108 | {
|
---|
109 | printf("Error in mixer\n");
|
---|
110 | }
|
---|
111 | #endif
|
---|
112 | readed = 0;
|
---|
113 | err = uniaud_pcm_open(card_id, PCM_TYPE_READ, 0, 0, 48000, 2,
|
---|
114 | SNDRV_PCM_FORMAT_S16_LE, &pcm);
|
---|
115 | if (pcm && err == 0)
|
---|
116 | {
|
---|
117 | printf("opened. pcm = %x\n", pcm);
|
---|
118 | err = uniaud_pcm_prepare(pcm);
|
---|
119 | printf("prepare err = %i\n", err);
|
---|
120 | err = uniaud_pcm_start(pcm);
|
---|
121 | printf("start err = %i\n", err);
|
---|
122 | if (argc > 1)
|
---|
123 | input_handle = fopen(argv[1], "wb");
|
---|
124 | else
|
---|
125 | input_handle = fopen("in.wav", "wb");
|
---|
126 | if (!input_handle) printf("Error opening file\n");
|
---|
127 |
|
---|
128 | // count = pcm->bufsize;
|
---|
129 | count = pcm->period_size;
|
---|
130 |
|
---|
131 | Buffer = malloc(count);
|
---|
132 | // memset(Buffer,0, count);
|
---|
133 |
|
---|
134 | // DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL,0,0);
|
---|
135 |
|
---|
136 | while (1)
|
---|
137 | {
|
---|
138 | #if 1
|
---|
139 | ret = uniaud_pcm_wait(pcm, 100);
|
---|
140 | if (ret < 0)
|
---|
141 | {
|
---|
142 | printf("error waiting pcm interrupt %i\n", ret);
|
---|
143 | DosSleep(1);
|
---|
144 | }
|
---|
145 | #endif
|
---|
146 | // else
|
---|
147 | {
|
---|
148 | state = uniaud_pcm_state(pcm);
|
---|
149 |
|
---|
150 | err = uniaud_pcm_read(pcm, Buffer, count*2);
|
---|
151 |
|
---|
152 | if (err > 0) // write something
|
---|
153 | {
|
---|
154 | readed=readed+err;
|
---|
155 | bytesread = fwrite (Buffer, 1, err, input_handle);
|
---|
156 | printf("readed=%i with state %i\r",readed, state);
|
---|
157 | }
|
---|
158 |
|
---|
159 | #if 1
|
---|
160 | if (err == -EAGAIN) //
|
---|
161 | {
|
---|
162 | printf("eagain\n");
|
---|
163 | continue;
|
---|
164 | }
|
---|
165 | #endif
|
---|
166 | if (err < 0) {
|
---|
167 | state = uniaud_pcm_state(pcm);
|
---|
168 | printf("state after read: %i, err = %i\n",state, err);
|
---|
169 | if ( (state != SND_PCM_STATE_PREPARED) &&
|
---|
170 | (state != SND_PCM_STATE_RUNNING) &&
|
---|
171 | (state != SND_PCM_STATE_DRAINING) || err == -11) {
|
---|
172 | printf("read:BAD STATE2, state = %d, going to try XRUN\n",state);
|
---|
173 | if ((ret = uniaud_pcm_prepare(pcm))<0) {
|
---|
174 | printf("xrun: prepare error: %i", err);
|
---|
175 | //return 0;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 | // DosSleep(300);
|
---|
181 | key = read_key();
|
---|
182 | // printf("%i\n",key);
|
---|
183 | if (key == 27)
|
---|
184 | break;
|
---|
185 |
|
---|
186 | }
|
---|
187 | free(Buffer);
|
---|
188 | err = uniaud_pcm_close(pcm);
|
---|
189 | fclose(input_handle);
|
---|
190 | DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR,0,0);
|
---|
191 | }
|
---|
192 | else
|
---|
193 | {
|
---|
194 | printf("open err: %i, pcm %x\n", err, pcm);
|
---|
195 | if (err == 5)
|
---|
196 | err = uniaud_pcm_close(pcm);
|
---|
197 | printf("close err: %i\n", err);
|
---|
198 | }
|
---|
199 |
|
---|
200 | return 0;
|
---|
201 | }
|
---|