/* reopen ALSA PCM */ static int alsa_reopen(struct snd_format* f) { /* remember the current position */ output_time_offset += (alsa_hw_written * 1000) / outputf->bps; alsa_hw_written = 0; alsa_close_pcm(); return alsa_setup(f); }
void sound_setup(int rate, int outp) { switch (outp) { case ALSA: alsa_setup(rate); break; case DSP: dsp_setup(rate); break; case STDOUT: stdout_setup(rate); break; default: fprintf(stderr, "Unknown output method\n"); } }
/* open callback */ int alsa_open(int rate, int nch, int width) { inputf = snd_format_alloc(rate, nch); if(alsa_setup(inputf) < 0) { alsa_close(); return 0; } output_time_offset = 0; alsa_total_written = alsa_hw_written = 0; going = true; prebuffer = true; remove_prebuffer = false; thread_buffer_size = (u_int) alsa_cb.thread_buffer_time * inputf->bps / 1000; if(thread_buffer_size < hw_buffer_size) thread_buffer_size = hw_buffer_size * 2; if(thread_buffer_size < width) thread_buffer_size = width; prebuffer_size = thread_buffer_size / 2; if(prebuffer_size < width) prebuffer_size = width; thread_buffer_size += hw_buffer_size; thread_buffer_size -= thread_buffer_size % hw_period_size; thread_buffer = calloc(1, thread_buffer_size); wr_index = rd_index = 0; flush_request = -1; pthread_create(&audio_thread, NULL, alsa_loop, NULL); return 1; }