sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* [PATCH] oss: prefer stereo mode
@ 2018-04-27 17:50 Mans Rullgard
  0 siblings, 0 replies; only message in thread
From: Mans Rullgard @ 2018-04-27 17:50 UTC (permalink / raw)
  To: sox-devel

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-27 17:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 17:50 [PATCH] oss: prefer stereo mode Mans Rullgard

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).