sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: Mans Rullgard <mans@mansr.com>
To: sox-devel@lists.sourceforge.net
Subject: [PATCH] oss: prefer stereo mode
Date: Fri, 27 Apr 2018 18:50:26 +0100	[thread overview]
Message-ID: <20180427175026.3481-1-mans@mansr.com> (raw)

Some OSS drivers treat mono data as stereo without any indication.
To get correct playabck on such devices, attempt stereo first and
fall back to mono only if this fails.
---
 src/oss.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/oss.c b/src/oss.c
index 9b13dc2f9a1a..9c6682f1d478 100644
--- a/src/oss.c
+++ b/src/oss.c
@@ -63,7 +63,7 @@ typedef struct
 /* common r/w initialization code */
 static int ossinit(sox_format_t* ft)
 {
-    int sampletype, samplesize, dsp_stereo;
+    int sampletype, samplesize;
     int tmp, rc;
     char const* szDevname;
     priv_t* pPriv = (priv_t*)ft->priv;
@@ -153,7 +153,7 @@ static int ossinit(sox_format_t* ft)
         lsx_report("Forcing to signed linear word");
     }
 
-    if (ft->signal.channels > 2) ft->signal.channels = 2;
+    ft->signal.channels = 2;
 
     if (ioctl(pPriv->device, (size_t) SNDCTL_DSP_RESET, 0) < 0)
     {
@@ -213,21 +213,13 @@ static int ossinit(sox_format_t* ft)
         return (SOX_EOF);
     }
 
-    if (ft->signal.channels == 2)
-        dsp_stereo = 1;
-    else
-        dsp_stereo = 0;
-
-    tmp = dsp_stereo;
-    if (ioctl(pPriv->device, SNDCTL_DSP_STEREO, &tmp) < 0)
+    tmp = 1;
+    if (ioctl(pPriv->device, SNDCTL_DSP_STEREO, &tmp) < 0 || tmp != 1)
     {
-        lsx_warn("Couldn't set to %s", dsp_stereo?  "stereo":"mono");
-        dsp_stereo = 0;
+        lsx_warn("Couldn't set to stereo");
+        ft->signal.channels = 1;
     }
 
-    if (tmp != dsp_stereo)
-        ft->signal.channels = tmp + 1;
-
     tmp = ft->signal.rate;
     if (ioctl(pPriv->device, SNDCTL_DSP_SPEED, &tmp) < 0 ||
         (int)ft->signal.rate != tmp) {
-- 
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

                 reply	other threads:[~2018-04-27 17:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180427175026.3481-1-mans@mansr.com \
    --to=sox-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).