diff options
author | biocrasher <biocrasher@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-07-13 00:08:45 +0000 |
---|---|---|
committer | biocrasher <biocrasher@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-07-13 00:08:45 +0000 |
commit | dad971c4a423e39a6cc6886585d25150e0d12c8f (patch) | |
tree | 2cce86963b3fb5de48768395f9a071bb52e3bba6 /recordmydesktop/src/opendev.c | |
parent | f635ae4bbdb7397764fbc4b1b1cfd6cde2d2ecce (diff) |
This commit was generated by cvs2svn to compensate for changes in r3,
which included commits to RCS files with non-trunk default branches.
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@4 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'recordmydesktop/src/opendev.c')
-rw-r--r-- | recordmydesktop/src/opendev.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/recordmydesktop/src/opendev.c b/recordmydesktop/src/opendev.c new file mode 100644 index 0000000..d8a4179 --- /dev/null +++ b/recordmydesktop/src/opendev.c @@ -0,0 +1,98 @@ +/********************************************************************************* +* recordMyDesktop * +********************************************************************************** +* * +* Copyright (C) 2006 John Varouhakis * +* * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * +* * +* * +* * +* For further information contact me at biocrasher@gmail.com * +**********************************************************************************/ + + + + +#include <recordmydesktop.h> + + +snd_pcm_t *OpenDev(const char *pcm_dev,unsigned int channels,unsigned int *frequency,snd_pcm_uframes_t *periodsize,unsigned int *periodtime,int *hard_pause){ + + snd_pcm_t *mhandle; + snd_pcm_hw_params_t *hwparams; + unsigned int periods=2; + unsigned int exactrate = *frequency; + + snd_pcm_hw_params_alloca(&hwparams); + snd_pcm_uframes_t buffsize=4096; + + if (snd_pcm_open(&mhandle, pcm_dev, SND_PCM_STREAM_CAPTURE, 0)<0){ + fprintf(stderr, "Couldn't open PCM device %s\n", pcm_dev); + return NULL; + } + if (snd_pcm_hw_params_any(mhandle, hwparams)<0){ + fprintf(stderr, "Couldn't configure PCM device.\n"); + return NULL; + } + if (snd_pcm_hw_params_set_access(mhandle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)<0) { + fprintf(stderr, "Couldn't set access.\n"); + return NULL; + } + if (snd_pcm_hw_params_set_format(mhandle, hwparams, SND_PCM_FORMAT_S16_LE)<0){ + fprintf(stderr, "Couldn't set format.\n"); + return NULL; + } + if (snd_pcm_hw_params_set_rate_near(mhandle, hwparams, &exactrate, 0)<0){ + fprintf(stderr, "Couldn't set frequency.\n"); + return NULL; + } + if (*frequency != exactrate){ + fprintf(stderr, "Playback frequency %dHz is not available...\nUsing %dHz instead.\n",*frequency,exactrate); + *frequency=exactrate; + } + if (snd_pcm_hw_params_set_channels_near(mhandle, hwparams, &channels)<0){ + fprintf(stderr, "Couldn't set channels number.\n"); + return NULL; + } + if (snd_pcm_hw_params_set_periods_near(mhandle, hwparams, &periods,0)<0) { + fprintf(stderr, "Couldn't set periods.\n"); + return NULL; + } + buffsize=(((exactrate*channels)))>>channels; + if (snd_pcm_hw_params_set_buffer_size_near(mhandle, hwparams,&buffsize)<0){ + fprintf(stderr, "Couldn't set buffer size.\n"); + return NULL; + } + if (snd_pcm_hw_params(mhandle, hwparams)<0){ + fprintf(stderr, "Couldn't set hardware parameters.\n"); + return NULL; + } + if(hard_pause!=NULL) + if(!snd_pcm_hw_params_can_pause(hwparams)){ +// fprintf(stderr, "Current sound device doesn't seem to support pausing!\nI will attempt to close/reopen device in case you opt to pause during recording.\n"); + *hard_pause=1; + } + if(periodsize!=NULL) + snd_pcm_hw_params_get_period_size(hwparams,periodsize,0); + if(periodtime!=NULL) + snd_pcm_hw_params_get_period_time(hwparams,periodtime,0); + snd_pcm_prepare(mhandle); + + return mhandle; +} + + |