Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AudioObjects without using the incomplete hard-coded Lookup-Tables #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions include/adm/utilities/object_creation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,29 @@ namespace adm {
const std::string& name,
const std::string& speakerLayout);

/**
* @brief Create and add `AudioObject` with common definitions direct speakers
* channel bed to document
*
* Creates an `AudioObject` and corresponding `AudioTrackUids` and connects it
* to the common definition ADM elements for the given speaker layout. The
* created ADM elements are added to the given document.
*
* @note The document must already have the common definition elements added.
*
* @param document The document where the `AudioObject` and the
* `AudioTrackUids` should be added to and whose common definition ADM
* elements should be used.
* @param name Name that will be used for the created `AudioObject`.
* @param packFormatId AudioPackFormatId of the given layout.
* @param trackFormatIds AudioTrackFormatIds of all the speakers in the layout.
* @param speakerLabels Labels of all the speakers in the layout.
*/
ADM_EXPORT SimpleCommonDefinitionsObjectHolder
addSimpleCommonDefinitionsObjectTo(std::shared_ptr<Document> document,
const std::string& name,
const std::string& packFormatId,
const std::vector<std::string>& trackFormatIds,
const std::vector<std::string>& speakerLabels);

} // namespace adm
41 changes: 41 additions & 0 deletions src/utilities/object_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,45 @@ namespace adm {
document->add(holder.audioObject);
return holder;
}

SimpleCommonDefinitionsObjectHolder addSimpleCommonDefinitionsObjectTo(
std::shared_ptr<Document> document, const std::string& name,
const std::string& packFormatId,
const std::vector<std::string>& trackFormatIds,
const std::vector<std::string>& speakerLabels) {
SimpleCommonDefinitionsObjectHolder holder;
holder.audioObject = AudioObject::create(AudioObjectName(name));
auto packFormat =
document->lookup(adm::parseAudioPackFormatId(packFormatId));
if (!packFormat) {
std::stringstream ss;
ss << "AudioPackFormatId \"" << packFormatId
<< "\" not found. Are the common definitions added to the document?";
throw error::AdmException(ss.str());
}
holder.audioObject->addReference(packFormat);
if (trackFormatIds.size() != speakerLabels.size()) {
std::stringstream ss;
ss << "Sizes of trackFormatIds and speakerLabels arguments do not match.";
throw error::AdmException(ss.str());
}
for (size_t i = 0; i < trackFormatIds.size(); i++) {
auto track =
document->lookup(adm::parseAudioTrackFormatId(trackFormatIds.at(i)));
if (!track) {
std::stringstream ss;
ss << "AudioTrackFormatId \"" << trackFormatIds.at(i)
<< "\" not found. Id might be invalid.";
throw error::AdmException(ss.str());
}
auto uid = AudioTrackUid::create();
uid->setReference(packFormat);
uid->setReference(track);
holder.audioObject->addReference(uid);
holder.audioTrackUids[speakerLabels.at(i)] = uid;
}
document->add(holder.audioObject);
return holder;
}

} // namespace adm