X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fexport_format_base.cc;h=ed8bb9d5f875f934217e9cf039c566034ba228aa;hb=be6d6231fbe56875815c81999e1fc41db0e21a23;hp=bddd61d0abfd93b7487c9f75d0a59a8225a692da;hpb=f2b007195cd75b195e38a4cd7757debac73e7792;p=ardour.git diff --git a/libs/ardour/export_format_base.cc b/libs/ardour/export_format_base.cc index bddd61d0ab..ed8bb9d5f8 100644 --- a/libs/ardour/export_format_base.cc +++ b/libs/ardour/export_format_base.cc @@ -18,7 +18,7 @@ */ -#include +#include "ardour/export_format_base.h" namespace ARDOUR { @@ -46,7 +46,7 @@ ExportFormatBase::SelectableCompatible::set_compatible (bool value) ExportFormatBase::ExportFormatBase () { - + } ExportFormatBase::ExportFormatBase (ExportFormatBase const & other) : @@ -61,7 +61,7 @@ ExportFormatBase::ExportFormatBase (ExportFormatBase const & other) : ExportFormatBase::~ExportFormatBase () { - + } boost::shared_ptr @@ -70,12 +70,6 @@ ExportFormatBase::get_intersection (ExportFormatBase const & other) const return do_set_operation (other, SetIntersection); } -boost::shared_ptr -ExportFormatBase::get_difference (ExportFormatBase const & other) const -{ - return do_set_operation (other, SetDifference); -} - boost::shared_ptr ExportFormatBase::get_union (ExportFormatBase const & other) const { @@ -86,9 +80,9 @@ boost::shared_ptr ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation operation) const { boost::shared_ptr result (new ExportFormatBase ()); - + /* Sets */ - + // Endiannesses { EndianSet::const_iterator start1 = endiannesses.begin(); @@ -96,20 +90,17 @@ ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation EndianSet::const_iterator start2 = other.endiannesses.begin(); EndianSet::const_iterator end2 = other.endiannesses.end(); std::insert_iterator insert (result->endiannesses, result->endiannesses.begin()); - + switch (operation) { case SetIntersection: std::set_intersection (start1, end1, start2, end2, insert); break; - case SetDifference: - std::set_difference (start1, end1, start2, end2, insert); - break; case SetUnion: std::set_union (start1, end1, start2, end2, insert); break; } } - + // Sample formats { SampleFormatSet::const_iterator start1 = sample_formats.begin(); @@ -117,21 +108,18 @@ ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation SampleFormatSet::const_iterator start2 = other.sample_formats.begin(); SampleFormatSet::const_iterator end2 = other.sample_formats.end(); std::insert_iterator insert (result->sample_formats, result->sample_formats.begin()); - + switch (operation) { case SetIntersection: std::set_intersection (start1, end1, start2, end2, insert); break; - case SetDifference: - std::set_difference (start1, end1, start2, end2, insert); - break; case SetUnion: std::set_union (start1, end1, start2, end2, insert); break; } } - - + + // Sample rates { SampleRateSet::const_iterator start1 = sample_rates.begin(); @@ -139,20 +127,17 @@ ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation SampleRateSet::const_iterator start2 = other.sample_rates.begin(); SampleRateSet::const_iterator end2 = other.sample_rates.end(); std::insert_iterator insert (result->sample_rates, result->sample_rates.begin()); - + switch (operation) { case SetIntersection: std::set_intersection (start1, end1, start2, end2, insert); break; - case SetDifference: - std::set_difference (start1, end1, start2, end2, insert); - break; case SetUnion: std::set_union (start1, end1, start2, end2, insert); break; } } - + // Format ids { FormatSet::const_iterator start1 = format_ids.begin(); @@ -160,20 +145,17 @@ ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation FormatSet::const_iterator start2 = other.format_ids.begin(); FormatSet::const_iterator end2 = other.format_ids.end(); std::insert_iterator insert (result->format_ids, result->format_ids.begin()); - + switch (operation) { case SetIntersection: std::set_intersection (start1, end1, start2, end2, insert); break; - case SetDifference: - std::set_difference (start1, end1, start2, end2, insert); - break; case SetUnion: std::set_union (start1, end1, start2, end2, insert); break; } } - + // Qualities { QualitySet::const_iterator start1 = qualities.begin(); @@ -181,21 +163,44 @@ ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation QualitySet::const_iterator start2 = other.qualities.begin(); QualitySet::const_iterator end2 = other.qualities.end(); std::insert_iterator insert (result->qualities, result->qualities.begin()); - + switch (operation) { case SetIntersection: std::set_intersection (start1, end1, start2, end2, insert); break; - case SetDifference: - std::set_difference (start1, end1, start2, end2, insert); - break; case SetUnion: std::set_union (start1, end1, start2, end2, insert); break; } } - + return result; } +ExportFormatBase::SampleRate +ExportFormatBase::nearest_sample_rate (framecnt_t sample_rate) +{ + int diff = 0; + int smallest_diff = INT_MAX; + SampleRate best_match = SR_None; + + #define DO_SR_COMPARISON(rate) \ + diff = std::fabs((rate) - sample_rate); \ + if(diff < smallest_diff) { \ + smallest_diff = diff; \ + best_match = (rate); \ + } + + DO_SR_COMPARISON(SR_8); + DO_SR_COMPARISON(SR_22_05); + DO_SR_COMPARISON(SR_44_1); + DO_SR_COMPARISON(SR_48); + DO_SR_COMPARISON(SR_88_2); + DO_SR_COMPARISON(SR_96); + DO_SR_COMPARISON(SR_192); + + return best_match; + #undef DO_SR_COMPARISON +} + }; // namespace ARDOUR