summaryrefslogtreecommitdiff
path: root/drumgizmo
diff options
context:
space:
mode:
authorGoran Mekić <meka@tilda.center>2017-04-15 18:45:30 +0200
committerGoran Mekić <meka@tilda.center>2017-04-16 21:35:13 +0200
commit43b179778a7845d64c0ce99a507af38ca8295f96 (patch)
tree1fd5a91bebf1feb1178fd1414061b0a0286788bc /drumgizmo
parent14c76e247f982b153adba005283826a2b722f89f (diff)
Add OSS buffer parameters
Diffstat (limited to 'drumgizmo')
-rw-r--r--drumgizmo/drumgizmoc.cc4
-rw-r--r--drumgizmo/output/oss.cc55
-rw-r--r--drumgizmo/output/oss.h4
3 files changed, 60 insertions, 3 deletions
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc
index 01025e7..4ad2550 100644
--- a/drumgizmo/drumgizmoc.cc
+++ b/drumgizmo/drumgizmoc.cc
@@ -88,7 +88,9 @@ static const char usage_str[] =
" alsa: dev=<device> (default 'default'), frames=<frames> (default "
"32)\n"
" srate=<samplerate> (default 441000)\n"
- " oss: dev=<device> (default '/dev/dsp'), srate=<samplerate>\n"
+ " oss: dev=<device> (default '/dev/dsp'), srate=<samplerate>,\n"
+ " max_fragments=<number> (default 4, see man page for more info),\n"
+ " fragment_size=<selector> (default 8, see man page for more info)\n"
" wavfile: file=<filename> (default 'output'), srate=<samplerate> "
"(default 44100)\n"
" jackaudio:\n"
diff --git a/drumgizmo/output/oss.cc b/drumgizmo/output/oss.cc
index 4e02e97..ee13a84 100644
--- a/drumgizmo/output/oss.cc
+++ b/drumgizmo/output/oss.cc
@@ -38,6 +38,8 @@ OSSOutputEngine::OSSOutputEngine()
, srate{44100}
, format{AFMT_S32_NE}
, data{}
+ , max_fragments{4}
+ , fragment_size{8}
{
data.clear();
data.resize(1024 * num_channels);
@@ -45,7 +47,7 @@ OSSOutputEngine::OSSOutputEngine()
bool OSSOutputEngine::init(const Channels& channels)
{
- int tmp, mode = O_WRONLY;
+ int tmp, mode = O_WRONLY, fragments;
num_channels = channels.size();
if((fd = open(dev.data(), mode, 0)) == -1)
@@ -54,6 +56,14 @@ bool OSSOutputEngine::init(const Channels& channels)
return false;
}
+ fragments = max_fragments << 16 | fragment_size;
+ tmp = fragments;
+ if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1 || tmp != fragments)
+ {
+ perror("SNDCTL_DSP_SETFRAGMENT");
+ exit(-1);
+ }
+
tmp = format;
if(ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) == -1 || tmp != format)
{
@@ -99,6 +109,44 @@ void OSSOutputEngine::setParm(const std::string& parm, const std::string& value)
std::cerr << value << std::endl;
}
}
+ else if(parm == "max_fragments")
+ {
+ try
+ {
+ max_fragments = std::stoi(value);
+ }
+ catch(...)
+ {
+ std::cerr << "[OSSOutputEngine] Invalid max_fragments ";
+ std::cerr << value << std::endl;
+ }
+ if(max_fragments < 2)
+ {
+ std::cerr << "[OSSoutputEngine] max_fragments must be at least 2\n";
+ std::cerr << "Setting max_fragments to 2" << std::endl;
+ max_fragments = 2;
+ }
+ }
+ else if(parm == "fragment_size")
+ {
+ try
+ {
+ fragment_size = std::stoi(value);
+ }
+ catch(...)
+ {
+ std::cerr << "[OSSOutputEngine] Invalid fragment_size ";
+ std::cerr << value << std::endl;
+ }
+ if(fragment_size < 4)
+ {
+ std::cerr << "[OSSoutputEngine] fragment_size must be at least 4\n";
+ std::cerr << "Setting fragment_size to 4 (";
+ fragment_size = 4;
+ auto fragment_byte_size = 1 << fragment_size;
+ std::cerr << fragment_byte_size << "Bytes)" << std::endl;
+ }
+ }
else
{
std::cerr << "[OSSOutputEngine] Unsupported parameter '";
@@ -106,6 +154,11 @@ void OSSOutputEngine::setParm(const std::string& parm, const std::string& value)
}
}
+void OSSOutputEngine::pre(size_t nsamples)
+{
+ data.resize(nsamples * num_channels);
+}
+
void OSSOutputEngine::run(int ch, sample_t* samples, size_t nsamples)
{
// Convert to int format and
diff --git a/drumgizmo/output/oss.h b/drumgizmo/output/oss.h
index d44cd1c..889021f 100644
--- a/drumgizmo/output/oss.h
+++ b/drumgizmo/output/oss.h
@@ -39,7 +39,7 @@ public:
void setParm(const std::string& parm, const std::string& value) override;
bool start() override { return true; };
void stop() override {};
- void pre(size_t nsamples) override { data.resize(nsamples * num_channels); };
+ void pre(size_t nsamples) override;
void run(int ch, sample_t* samples, size_t nsamples) override;
void post(size_t nsamples) override;
bool isFreewheeling() const override { return false; };
@@ -52,5 +52,7 @@ private:
std::size_t num_channels;
unsigned int srate;
unsigned int format;
+ unsigned int max_fragments;
+ unsigned int fragment_size;
std::vector<std::int32_t> data;
};