コード例 #1
0
ファイル: alsa.hpp プロジェクト: Themaister/SLIMPlayer
            ALSA(unsigned channels, unsigned samplerate, const std::string& device = "default") : runnable(true), pcm(nullptr), params(nullptr), fps(samplerate)
            {
               int rc = snd_pcm_open(&pcm, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
               if (rc < 0)
               {
                  runnable = false;
                  throw DeviceException(General::join("Unable to open PCM device ", snd_strerror(rc)));
               }

               snd_pcm_format_t fmt = type_to_format(T());

               if (snd_pcm_hw_params_malloc(&params) < 0)
               {
                  runnable = false;
                  throw DeviceException("Failed to allocate memory.");
               }

               runnable = false;
               if (
                     (snd_pcm_hw_params_any(pcm, params) < 0) ||
                     (snd_pcm_hw_params_set_access(pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) ||
                     (snd_pcm_hw_params_set_channels(pcm, params, channels) < 0) ||
                     (snd_pcm_hw_params_set_format(pcm, params, fmt) < 0) ||
                     (snd_pcm_hw_params_set_rate(pcm, params, samplerate, 0) < 0) ||
                     ((rc = snd_pcm_hw_params(pcm, params)) < 0)
                  )
                  throw DeviceException(General::join("Unable to install HW params: ", snd_strerror(rc)));

               runnable = true;
            }
コード例 #2
0
ファイル: pulse_audio.cpp プロジェクト: fpelliccioni/hamigaki
    impl(const char* app, const char* name, const pcm_format& fmt) : fmt_(fmt)
    {
        pa_sample_spec ss = {};
        ss.format = type_to_format(fmt.type);
        ss.rate = fmt.rate;
        ss.channels = fmt.channels;

        int error;
        handle_ = ::pa_simple_new(
            0, app, PA_STREAM_PLAYBACK, 0, name, &ss, 0, 0, &error);
        if (handle_ == 0)
            throw BOOST_IOSTREAMS_FAILURE("pa_simple_new() failed");
    }