Skip to content

Commit

Permalink
Support mono input files in uhjencoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Mar 28, 2024
1 parent 7dcb770 commit 3d4f537
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion utils/uhjencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ struct SpeakerPos {
};

/* Azimuth is counter-clockwise. */
constexpr std::array MonoMap{
SpeakerPos{SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f},
};
constexpr std::array StereoMap{
SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f},
SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f},
Expand Down Expand Up @@ -298,6 +301,7 @@ int main(al::span<std::string_view> args)
if(sf_command(infile.get(), SFC_GET_CHANNEL_MAP_INFO, chanmap.data(),
ininfo.channels*int{sizeof(int)}) == SF_TRUE)
{
static const std::array<int,1> monomap{{SF_CHANNEL_MAP_CENTER}};
static const std::array<int,2> stereomap{{SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT}};
static const std::array<int,4> quadmap{{SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT,
SF_CHANNEL_MAP_REAR_LEFT, SF_CHANNEL_MAP_REAR_RIGHT}};
Expand Down Expand Up @@ -331,7 +335,9 @@ int main(al::span<std::string_view> args)
{ return std::find(b.begin(), b.end(), id) != b.end(); };
return std::all_of(a.cbegin(), a.cend(), find_channel);
};
if(match_chanmap(chanmap, stereomap))
if(match_chanmap(chanmap, monomap))
spkrs = MonoMap;
else if(match_chanmap(chanmap, stereomap))
spkrs = StereoMap;
else if(match_chanmap(chanmap, quadmap))
spkrs = QuadMap;
Expand Down Expand Up @@ -364,6 +370,12 @@ int main(al::span<std::string_view> args)
continue;
}
}
else if(ininfo.channels == 1)
{
fprintf(stderr, " ... assuming front-center\n");
spkrs = MonoMap;
chanmap[0] = SF_CHANNEL_MAP_CENTER;
}
else if(ininfo.channels == 2)
{
fprintf(stderr, " ... assuming WFX order stereo\n");
Expand Down

0 comments on commit 3d4f537

Please sign in to comment.