git ssb

0+

cel / foostudio



Commit 033d2aa1890af2ff80fde819e83b034484c47cbc

Improve input handling

cel committed on 11/4/2016, 6:40:40 PM
Parent: bb4c57ab9509dfe407fa6359c04c79270e64bd18

Files changed

foostudio.cchanged
foostudio.cView
@@ -18,9 +18,9 @@
1818 static unsigned int channels_out = 1;
1919 static unsigned int channels_in = 1;
2020 static unsigned int latency = 10000; // us
2121 static int resample = 1; // allow resampling
22-static int maxval = 0x7fff;
22 +static int16_t maxval = 0x7fff;
2323
2424 static snd_pcm_format_t format = SND_PCM_FORMAT_S16;
2525
2626 int main(int argc, char *argv[])
@@ -125,10 +125,21 @@
125125 }
126126 int16_t buffer[frames];
127127
128128 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 + }
129134 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 + }
131142 }
132143
133144 if (midi_reopen_timer > 0) {
134145 if (--midi_reopen_timer == 0) {
@@ -163,9 +174,10 @@
163174 if (play) {
164175 for (size_t i = 0; i < (size_t)frames; i++) {
165176 time += step;
166177 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);
168180 if (midi_bufp) {
169181 if (midi_bytes <= 3) {
170182 midi_bufp = NULL;
171183 } else {

Built with git-ssb-web