static void as_setup_format_combo(GawSndData *snd) { GtkWidget *combo = snd->w_format; snd_pcm_format_t format = snd->sparams->format; snd_pcm_t *pcm; snd_pcm_hw_params_t *hwparams; snd_pcm_format_mask_t *formatMask; AsFormatList *p; int i ; int err; for ( i = snd->n_format ; i > 0; i-- ){ gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (combo), i - 1 ); } snd->n_format = 0; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_format_mask_alloca(&formatMask); err = snd_pcm_open(&pcm, snd->sparams->device_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); if ( err < 0 ) { return; } err = snd_pcm_hw_params_any(pcm, hwparams); if ( err < 0 ) { snd_pcm_close(pcm); return; } snd_pcm_hw_params_get_format_mask(hwparams, formatMask); for( p = as_format_list, i = 0 ; p->name ; p++, i++ ){ if ( snd_pcm_format_mask_test ( formatMask, p->format ) < 0 ){ continue; } gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), p->name ); // msg_dbg("as_format %d '%s'", snd->n_format, p->name ); snd->n_format++; if ( p->format == format ) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i); } } snd_pcm_close(pcm); }
int VPOutPluginAlsa::init(VPlayer *v, VPBuffer *in) { DBG("Alsa:init"); owner = v; bin = in; if (snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NO_AUTO_RESAMPLE) < 0){ DBG("Alsa:init: failed to open pcm"); exit(0); return -1; } snd_pcm_sw_params_t *swparams; snd_pcm_sw_params_malloc(&swparams); snd_pcm_sw_params_current (handle, swparams); snd_pcm_sw_params_set_start_threshold (handle, swparams, VPBUFFER_FRAMES - PERIOD_SIZE); snd_pcm_sw_params (handle, swparams); snd_pcm_sw_params_free(swparams); snd_pcm_hw_params_alloca(¶ms); snd_pcm_hw_params_any(handle, params); snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_format_mask_t *mask; snd_pcm_format_mask_alloca(&mask); snd_pcm_hw_params_get_format_mask(params, mask); if (snd_pcm_format_mask_test(mask, SND_PCM_FORMAT_S32)) { DBG("bit depth is 32"); snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S32); multiplier = (1<<31) -1 ; DBG(multiplier); } else if (snd_pcm_format_mask_test(mask, SND_PCM_FORMAT_S24)) { DBG("bit depth is 24"); snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S24); multiplier = (1<<23) -1; } else if (snd_pcm_format_mask_test(mask, SND_PCM_FORMAT_S16)) { DBG("bit depth is 16"); snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16); multiplier = (1<<15) -1; } else if (snd_pcm_format_mask_test(mask, SND_PCM_FORMAT_S8)) { DBG("bit depth is 8"); snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S8); multiplier = (1<<7) -1;; } snd_pcm_hw_params_set_channels(handle, params, bin->chans); snd_pcm_hw_params_set_period_size(handle, params, PERIOD_SIZE, 0); if (snd_pcm_hw_params(handle, params) < 0) { DBG("Alsa:init: failed to set pcm params"); return -1; } snd_pcm_hw_params_current(handle, params); int dir; snd_pcm_hw_params_get_rate(params, &out_srate, &dir); in_srate = bin->srate; int rerr; rs = src_new(SRC_SINC_FASTEST, bin->chans, &rerr); if (!rs){ DBG("SRC error"<<rerr); return -1; } rd.src_ratio = (out_srate*1.0)/(in_srate*1.0); out_frames = (VPBUFFER_FRAMES*rd.src_ratio)*2; out_buf = (float *)ALIGNED_ALLOC(sizeof(float)*out_frames*bin->chans); out_buf_i = (int *)ALIGNED_ALLOC(sizeof(int)*out_frames*bin->chans); DBG("target rate "<<out_srate); work = true; paused = false; pause_check = false; FULL_MEMORY_BARRIER; in_fd = inotify_init(); if ( in_fd < 0 ) { DBG("error initializing inotify, auto pause won't work"); } else { in_wd[0]=inotify_add_watch( in_fd, "/dev/snd/pcmC0D0p", IN_OPEN | IN_CLOSE ); } fcntl(in_fd, F_SETFL, O_NONBLOCK); worker = new std::thread((void(*)(void*))worker_run, this); worker->high_priority(); DBG("alsa thread made"); DBG((void *)VPOutPluginAlsa::check_contention); VPEvents::getSingleton()->schedulerAddJob((VPEvents::VPJob) VPOutPluginAlsa::check_contention, this,0); return 0; }