From a9256048bf2d9ec3ff6004a6dd6bf9e3a3f88294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Meki=C4=87?= Date: Sun, 30 Apr 2017 11:48:36 +0200 Subject: Get OSS buffer size --- drumgizmo/output/oss.cc | 12 +++++++++++- drumgizmo/output/oss.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'drumgizmo/output') diff --git a/drumgizmo/output/oss.cc b/drumgizmo/output/oss.cc index ee13a84..9815460 100644 --- a/drumgizmo/output/oss.cc +++ b/drumgizmo/output/oss.cc @@ -40,6 +40,7 @@ OSSOutputEngine::OSSOutputEngine() , data{} , max_fragments{4} , fragment_size{8} + , buffer_size{1024} { data.clear(); data.resize(1024 * num_channels); @@ -64,6 +65,15 @@ bool OSSOutputEngine::init(const Channels& channels) exit(-1); } + audio_buf_info info; + if(ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == -1) + { + std::cerr << "Can not get buffer info: "; + std::cerr << std::strerror(errno) << std::endl; + return false; + } + buffer_size = info.bytes / 4; + tmp = format; if(ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) == -1 || tmp != format) { @@ -195,7 +205,7 @@ void OSSOutputEngine::post(size_t nsamples) std::size_t OSSOutputEngine::getBufferSize() const { - return data.size() / num_channels; + return buffer_size; } std::size_t OSSOutputEngine::getSamplerate() const diff --git a/drumgizmo/output/oss.h b/drumgizmo/output/oss.h index 889021f..1233ec1 100644 --- a/drumgizmo/output/oss.h +++ b/drumgizmo/output/oss.h @@ -54,5 +54,6 @@ private: unsigned int format; unsigned int max_fragments; unsigned int fragment_size; + unsigned int buffer_size; std::vector data; }; -- cgit v1.2.3