genode/repos/os/src/drivers/audio/spec/linux/alsa.c
Stefan Kalkowski ed52d5a211 Introduce 'spec' subdirectories to outline aspects
Instead of holding SPEC-variable dependent files and directories inline
within the repository structure, move them into 'spec' subdirectories
at the corresponding levels, e.g.:

  repos/base/include/spec
  repos/base/mk/spec
  repos/base/lib/mk/spec
  repos/base/src/core/spec
  ...

Moreover, this commit removes the 'platform' directories. That term was
used in an overloaded sense. All SPEC-relative 'platform' directories are
now named 'spec'. Other files, like for instance those related to the
kernel/architecture specific startup library, where moved from 'platform'
directories to explicit, more meaningful places like e.g.: 'src/lib/startup'.

Fix #1673
2015-09-16 13:58:50 +02:00

89 lines
1.8 KiB
C

/*
* \brief ALSA-based audio for Linux
* \author Sebastian Sumpf
* \author Christian Helmuth
* \date 2009-12-04
*/
/*
* Copyright (C) 2009-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <alsa/asoundlib.h>
#include "alsa.h"
static snd_pcm_t *playback_handle;
int audio_drv_init(void)
{
unsigned int rate = 44100;
int err;
snd_pcm_hw_params_t *hw_params;
if ((err = snd_pcm_open(&playback_handle, "hw", SND_PCM_STREAM_PLAYBACK, 0)) < 0)
return -1;
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)
return -2;
if ((err = snd_pcm_hw_params_any(playback_handle, hw_params)) < 0)
return -3;
if ((err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
return -4;
if ((err = snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
return -5;
if ((err = snd_pcm_hw_params_set_rate(playback_handle, hw_params, rate, 0)) < 0)
return -6;
if ((err = snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2)) < 0)
return -7;
if ((err = snd_pcm_hw_params_set_period_size(playback_handle, hw_params, 2048, 0)) < 0)
return -8;
if ((err = snd_pcm_hw_params_set_periods(playback_handle, hw_params, 4, 0)) < 0)
return -9;
if ((err = snd_pcm_hw_params(playback_handle, hw_params)) < 0)
return -10;
snd_pcm_hw_params_free(hw_params);
if ((err = snd_pcm_prepare(playback_handle)) < 0)
return -11;
return 0;
}
void audio_drv_adopt_myself() { }
int audio_drv_play(void *data, int frame_cnt)
{
int err;
if ((err = snd_pcm_writei(playback_handle, data, frame_cnt)) != frame_cnt)
return err;
return 0;
}
void audio_drv_stop(void)
{
snd_pcm_drop(playback_handle);
}
void audio_drv_start(void)
{
snd_pcm_prepare(playback_handle);
}