Git Product home page Git Product logo

Comments (14)

rillian avatar rillian commented on July 30, 2024

Maybe a --discrete switch would make sense for this? Note that setting the channel mapping to 255 we prevent audio playback in most software; it's intended for use by DAW software which is used to handling unmixed audio.

I would expect a --no-coupling option to still use stereo, but prevent any coupling between them, so normal playback would work. Looks like this could call opus_multistream_encoder_create() instead of opus_multistream_surround_encoder_create() for the necessary control.

from opus-tools.

Worldexe avatar Worldexe commented on July 30, 2024

Well, we can choose --discrete flag, but imo --no-coupling a bit more descriptive one.

Hmm, should I call opus_multistream_encoder_create with channels=2,streams=1,coupled=0?
This seems wrong as it will lead to validate_layout() error.

Calling that with channels=2,streams=2,coupled=0 seems the same as calling opus_multistream_surround_encoder_create() with header.channel_mapping=255.
I also do not see any difference in mediainfo output or player (AIMP) behaviour.
Am I wrong?

Sorry, I am not familiar with Opus codebase, so maybe my questions are a bit stupid =)

from opus-tools.

rillian avatar rillian commented on July 30, 2024

You're right. I was thinking opus_multistream_surround_encoder_create() would propagate the mapping_family argument into the file header, but it only uses it to set up channel coupling and tweak some encoder parameters, then discards the value. It's opusenc.c that writes the actual value into the file header. So passing channels = 2, streams = 2, 'coupled = 0or creating a surround encoder with that andchannel_mapping = 255` should be the same.

What I was trying to get out is that there's a semantic difference between opusenc actually writing header.channel_mapping = 255 into the .opus file header (discrete channels) and writing header.channel_mapping = 2 (left/right stereo, which just happen to be uncoupled).

from opus-tools.

Worldexe avatar Worldexe commented on July 30, 2024

According to https://wiki.xiph.org/OggOpus, there is no reason to set header's channel mapping to 2, as

The remaining channel mapping families (2...254) are reserved. A decoder encountering a reserved mapping byte should act as though the mapping byte is 255.

Well, we can set it to 2, but who knows how it will be used in future.

from opus-tools.

rillian avatar rillian commented on July 30, 2024

Sorry, I meant header.channel_mapping = 1, which is different from 255, unlike 2.

from opus-tools.

Worldexe avatar Worldexe commented on July 30, 2024

Sorry, I did not forgot about this, just didnt have enough time :(

from opus-tools.

JamesDunne avatar JamesDunne commented on July 30, 2024

Sorry to resurrect an old issue, but the proposed flag would be perfect for my use case of encoding multiple independent channels from a DAW for playback in a custom player. I exported the multichannel mix as WAV but opusenc offers no control over the channel mapping via command line switches. I see the codec is designed to handle my scenario but the tools are not.

I'm frankly getting tired of audio tools presuming surround configurations based solely on the channel counts. Just because I'm exporting an 8 channel WAV does not mean it's a 7.1 surround mix. Sure it can be default as that's low friction for most users but at least allow for customization and control.

I plan to make a PR of my own to address the issue but it will take some time.

from opus-tools.

Worldexe avatar Worldexe commented on July 30, 2024

Sorry for not doing this myself :(
Here is what I use; adapted just now to current HEAD, hope it still works;
Maybe, this will be useful for your PR.

From 9993b87e9c9635588796d3a2753c693c8d27e4f5 Mon Sep 17 00:00:00 2001
From: "World.exe" <>
Date: Wed, 1 Nov 2017 19:12:35 +0300
Subject: [PATCH] Adding force channel decoupling.

---
 src/opusenc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/opusenc.c b/src/opusenc.c
index 129dcdb..2901298 100644
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -136,6 +136,7 @@ void usage(void)
   printf(" --framesize n      Set maximum frame size in milliseconds\n");
   printf("                      (2.5, 5, 10, 20, 40, 60, default: 20)\n");
   printf(" --expect-loss      Set expected packet loss in percent (default: 0)\n");
+  printf(" --no-coupling      Force disable channel coupling\n");
   printf(" --downmix-mono     Downmix to mono\n");
   printf(" --downmix-stereo   Downmix to stereo (if >2 channels)\n");
   printf(" --max-delay n      Set maximum container delay in milliseconds\n");
@@ -345,6 +346,8 @@ int main(int argc, char **argv)
   int                comment_padding=512;
   int                serialno;
   opus_int32         lookahead=0;
+  int                no_coupling=0;
+
 #ifdef WIN_UNICODE
    int argc_utf8;
    char **argv_utf8;
@@ -577,6 +580,8 @@ int main(int argc, char **argv)
           inopt.copy_pictures=0;
         } else if(strcmp(long_options[option_index].name,"discard-pictures")==0){
           inopt.copy_pictures=0;
+        } else if(strcmp(long_options[option_index].name,"no-coupling")==0){
+          no_coupling=1;
         }
         /*Commands whose arguments would leak file paths or just end up as metadata
            should have save_cmd=0; to prevent them from being saved in the
@@ -698,6 +703,10 @@ int main(int argc, char **argv)
   /*Initialize Opus encoder*/
   /*Frame sizes <10ms can only use the MDCT modes, so we switch on RESTRICTED_LOWDELAY
     to save the extra 4ms of codec lookahead when we'll be using only small frames.*/
+  if(no_coupling){ 
+    header.channel_mapping=255;
+  }
+
   st=opus_multistream_surround_encoder_create(coding_rate, chan, header.channel_mapping, &header.nb_streams, &header.nb_coupled,
      header.stream_map, frame_size<480/(48000/coding_rate)?OPUS_APPLICATION_RESTRICTED_LOWDELAY:OPUS_APPLICATION_AUDIO, &ret);
   if(ret!=OPUS_OK){
-- 
1.9.5.msysgit.1

from opus-tools.

JamesDunne avatar JamesDunne commented on July 30, 2024

@Worldexe I've just completed something similar albeit more flexible on my fork.

--no-surround      Disable surround sound encoding
--coupled 1,4      Specify coupled input channels (e.g. 1/2, 4/5)

However, the encoder still remaps channels according to vorbis channel ordering which is not what I want. I want the input channels to be mapped 1:1 to the output channels.

I'm currently looking for a way to completely disable the vorbis channel remapping but I don't see any obvious avenue to do so in the code here. It'd be great if I could specify my own output channel mapping to vorbis so that the coupled channels found in the original input audio file are kept in their original places in the output file with the added benefit of being coupled together for stereo processing.

from opus-tools.

JamesDunne avatar JamesDunne commented on July 30, 2024

Nevermind what I wrote last. I'm using Reaper as my DAW and it is decoding as surround and remapping the channels on decode. opusenc and opusdec with my --no-surround option correctly encode and decode the channels without reordering.

from opus-tools.

JamesDunne avatar JamesDunne commented on July 30, 2024

Got a working PR to resolve this: #19

Tested it out locally on my 8-channel non-surround mix and it works!

from opus-tools.

MT00x avatar MT00x commented on July 30, 2024

After 6 years.. sorry.
What is the right way to encode 2 channels uncoupled using opus_multistream_encoder_create?
Any changes in validate_layout?

from opus-tools.

chris-hld avatar chris-hld commented on July 30, 2024

This #80 should also fix this issue

from opus-tools.

vadimkantorov avatar vadimkantorov commented on July 30, 2024

@ePirat @mark4o Probably this issue can be closed now, for #80 was merged in master

from opus-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.