Commit 033d2aa1890af2ff80fde819e83b034484c47cbc
Improve input handling
cel committed on 11/4/2016, 6:40:40 PMParent: bb4c57ab9509dfe407fa6359c04c79270e64bd18
Files changed
foostudio.c | changed |
foostudio.c | |||
---|---|---|---|
@@ -18,9 +18,9 @@ | |||
18 | 18 … | static unsigned int channels_out = 1; | |
19 | 19 … | static unsigned int channels_in = 1; | |
20 | 20 … | static unsigned int latency = 10000; // us | |
21 | 21 … | static int resample = 1; // allow resampling | |
22 | -static int maxval = 0x7fff; | ||
22 … | +static int16_t maxval = 0x7fff; | ||
23 | 23 … | ||
24 | 24 … | static snd_pcm_format_t format = SND_PCM_FORMAT_S16; | |
25 | 25 … | ||
26 | 26 … | int main(int argc, char *argv[]) | |
@@ -125,10 +125,21 @@ | |||
125 | 125 … | } | |
126 | 126 … | int16_t buffer[frames]; | |
127 | 127 … | ||
128 | 128 … | if (pcm_in) { | |
129 … | + if (snd_pcm_state(pcm_in) == SND_PCM_STATE_PREPARED) { | ||
130 … | + if ((err = snd_pcm_start(pcm_in)) < 0) { | ||
131 … | + warnx("snd_pcm_start: %s", snd_strerror(err)); | ||
132 … | + } | ||
133 … | + } | ||
129 | 134 … | frames_in = snd_pcm_readi(pcm_in, buffer, frames); | |
130 | - if (frames_in < 0) snd_pcm_recover(pcm_in, frames_in, 0); | ||
135 … | + if (frames_in < 0) { | ||
136 … | + err = snd_pcm_recover(pcm_in, frames_in, 0); | ||
137 … | + if (err == -EAGAIN) { | ||
138 … | + } else if (err < 0) { | ||
139 … | + warnx("snd_pcm_readi: %s\n", snd_strerror(err)); | ||
140 … | + } | ||
141 … | + } | ||
131 | 142 … | } | |
132 | 143 … | ||
133 | 144 … | if (midi_reopen_timer > 0) { | |
134 | 145 … | if (--midi_reopen_timer == 0) { | |
@@ -163,9 +174,10 @@ | |||
163 | 174 … | if (play) { | |
164 | 175 … | for (size_t i = 0; i < (size_t)frames; i++) { | |
165 | 176 … | time += step; | |
166 | 177 … | int16_t frame_in = (ssize_t)i < frames_in ? buffer[i] : 0; | |
167 | - float val = play(&tune_obj, time, frame_in/maxval, midi_bufp); | ||
178 … | + float in = (float)frame_in / maxval; | ||
179 … | + float val = play(&tune_obj, time, in, midi_bufp); | ||
168 | 180 … | if (midi_bufp) { | |
169 | 181 … | if (midi_bytes <= 3) { | |
170 | 182 … | midi_bufp = NULL; | |
171 | 183 … | } else { |
Built with git-ssb-web