Remove unused cctools code paths for old libusb and cp2103 ioctls.
[fw/altos] / aoview / aoview_flite.c
index 2673824..e1b7589 100644 (file)
@@ -37,6 +37,8 @@ aoview_flite_task(gpointer data)
        int             rate;
        int             channels;
        int             err;
+       char            *samples;
+       int             num_samples;
 
        err = snd_pcm_open(&alsa_handle, "default",
                           SND_PCM_STREAM_PLAYBACK, 0);
@@ -58,21 +60,34 @@ aoview_flite_task(gpointer data)
                {
                        rate = wave->sample_rate;
                        channels = wave->num_channels;
-                       snd_pcm_set_params(alsa_handle,
-                                          SND_PCM_FORMAT_S16,
-                                          SND_PCM_ACCESS_RW_INTERLEAVED,
-                                          channels,
-                                          rate,
-                                          1,
-                                          100000);
+                       err = snd_pcm_set_params(alsa_handle,
+                                                SND_PCM_FORMAT_S16,
+                                                SND_PCM_ACCESS_RW_INTERLEAVED,
+                                                channels,
+                                                rate,
+                                                1,
+                                                100000);
+                       if (err < 0)
+                               fprintf(stderr, "alsa set_params error %s\n",
+                                       strerror(-err));
                }
-               snd_pcm_prepare(alsa_handle);
-               err = snd_pcm_writei(alsa_handle,
-                                    wave->samples,
-                                    wave->num_samples);
+               err = snd_pcm_prepare(alsa_handle);
                if (err < 0)
-                       fprintf(stderr, "alsa write error %s\n",
+                       fprintf(stderr, "alsa pcm_prepare error %s\n",
                                strerror(-err));
+               samples = (char *) wave->samples;
+               num_samples = wave->num_samples;
+               while (num_samples > 0) {
+                       err = snd_pcm_writei(alsa_handle,
+                                            samples, num_samples);
+                       if (err <= 0) {
+                               fprintf(stderr, "alsa write error %s\n",
+                                       strerror(-err));
+                               break;
+                       }
+                       num_samples -= err;
+                       samples += err * 2 * channels;
+               }
                snd_pcm_drain(alsa_handle);
                delete_wave(wave);
        }