Add some PT-style names to the guesswork on which channel a particular sound file...
authorCarl Hetherington <cth@carlh.net>
Tue, 14 Jan 2020 21:53:38 +0000 (22:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 Jan 2020 21:53:38 +0000 (22:53 +0100)
src/lib/audio_mapping.cc
test/audio_mapping_test.cc

index f07d5de..05dfb7e 100644 (file)
@@ -81,16 +81,32 @@ AudioMapping::make_zero ()
        }
 }
 
+struct ChannelRegex
+{
+       ChannelRegex (string regex_, int channel_)
+               : regex (regex_)
+               , channel (channel_)
+       {}
+
+       string regex;
+       int channel;
+};
+
 void
 AudioMapping::make_default (AudioProcessor const * processor, optional<boost::filesystem::path> filename)
 {
-       static string const regex[] = {
-               ".*[\\._-]L[\\._-].*",
-               ".*[\\._-]R[\\._-].*",
-               ".*[\\._-]C[\\._-].*",
-               ".*[\\._-]Lfe[\\._-].*",
-               ".*[\\._-]Ls[\\._-].*",
-               ".*[\\._-]Rs[\\._-].*"
+       static ChannelRegex const regex[] = {
+               ChannelRegex(".*[\\._-]L[\\._-].*", 0),
+               ChannelRegex(".*[\\._-]R[\\._-].*", 1),
+               ChannelRegex(".*[\\._-]C[\\._-].*", 2),
+               ChannelRegex(".*[\\._-]Lfe[\\._-].*", 3),
+               ChannelRegex(".*[\\._-]LFE[\\._-].*", 3),
+               ChannelRegex(".*[\\._-]Lss[\\._-].*", 4),
+               ChannelRegex(".*[\\._-]Lsr[\\._-].*", 6),
+               ChannelRegex(".*[\\._-]Ls[\\._-].*", 4),
+               ChannelRegex(".*[\\._-]Rss[\\._-].*", 5),
+               ChannelRegex(".*[\\._-]Rsr[\\._-].*", 7),
+               ChannelRegex(".*[\\._-]Rs[\\._-].*", 5),
        };
 
        static int const regexes = sizeof(regex) / sizeof(*regex);
@@ -105,9 +121,9 @@ AudioMapping::make_default (AudioProcessor const * processor, optional<boost::fi
                        /* See if we can guess where this stream should go */
                        if (filename) {
                                for (int i = 0; i < regexes; ++i) {
-                                       boost::regex e (regex[i], boost::regex::icase);
-                                       if (boost::regex_match(filename->string(), e) && i < output_channels()) {
-                                               set (0, i, 1);
+                                       boost::regex e (regex[i].regex, boost::regex::icase);
+                                       if (boost::regex_match(filename->string(), e) && regex[i].channel < output_channels()) {
+                                               set (0, regex[i].channel, 1);
                                                guessed = true;
                                        }
                                }
index 1310313..0565429 100644 (file)
@@ -28,6 +28,8 @@
 #include "lib/util.h"
 
 using std::list;
+using std::string;
+using boost::optional;
 
 BOOST_AUTO_TEST_CASE (audio_mapping_test)
 {
@@ -57,3 +59,34 @@ BOOST_AUTO_TEST_CASE (audio_mapping_test)
                }
        }
 }
+
+static void
+guess_check (string filename, int output_channel)
+{
+       AudioMapping m (1, 8);
+       m.make_default (0, optional<boost::filesystem::path>(filename));
+       for (int i = 0; i < 8; ++i) {
+               BOOST_TEST_INFO (filename);
+               BOOST_CHECK_CLOSE (m.get(0, i), i == output_channel ? 1 : 0, 0.01);
+       }
+}
+
+BOOST_AUTO_TEST_CASE (audio_mapping_guess_test)
+{
+       guess_check ("stuff_L_nonsense.wav", 0);
+       guess_check ("stuff_nonsense.wav", 2);
+       guess_check ("fred_R.wav", 1);
+       guess_check ("jim_C_sheila.aiff", 2);
+       guess_check ("things_Lfe_and.wav", 3);
+       guess_check ("weeee_Ls.aiff", 4);
+       guess_check ("try_Rs-it.wav", 5);
+
+       /* PT-style */
+       guess_check ("things_LFE.wav", 3);
+       guess_check ("ptish_Lsr_abc.wav", 6);
+       guess_check ("ptish_Rsr_abc.wav", 7);
+       guess_check ("more_Lss_s.wav", 4);
+       guess_check ("other_Rss.aiff", 5);
+}
+
+