| 609 | } |
| 610 | |
| 611 | bool OpusExportProcessor::Initialize( |
| 612 | AudacityProject& project, const Parameters& parameters, |
| 613 | const wxFileNameWrapper& fName, double t0, double t1, bool selectionOnly, |
| 614 | double sampleRate, unsigned numChannels, MixerOptions::Downmix* mixerSpec, |
| 615 | const Tags* metadata) |
| 616 | { |
| 617 | context.sampleRate = int32_t(sampleRate); |
| 618 | |
| 619 | if (!IsValidSampleRate(context.sampleRate)) |
| 620 | throw ExportException(XO("Unsupported sample rate").Translation()); |
| 621 | |
| 622 | context.t0 = t0; |
| 623 | context.t1 = t1; |
| 624 | context.numChannels = numChannels; |
| 625 | context.fName = fName; |
| 626 | |
| 627 | // Internally the Opus is always in 48k, find out the multiplier for |
| 628 | // values, that expect 48k sample rate |
| 629 | context.opus.sampleRateFactor = 48000 / context.sampleRate; |
| 630 | |
| 631 | const auto bitRate = ExportPluginHelpers::GetParameterValue<int>( |
| 632 | parameters, OPUSOptionIDBitRate, OPUS_AUTO); |
| 633 | const auto vbrMode = ExportPluginHelpers::GetParameterValue<int>( |
| 634 | parameters, OPUSOptionIDVBRMode, VBRMode::VBR); |
| 635 | const int complexity = ExportPluginHelpers::GetParameterValue<int>( |
| 636 | parameters, OPUSOptionIDQuality, 10); |
| 637 | const int frameMultiplier = ExportPluginHelpers::GetParameterValue<int>( |
| 638 | parameters, OPUSOptionIDFrameDuration, 200); |
| 639 | const int application = ExportPluginHelpers::GetParameterValue<int>( |
| 640 | parameters, OPUSOptionIDApplication, OPUS_APPLICATION_AUDIO); |
| 641 | const int cutoff = ExportPluginHelpers::GetParameterValue<int>( |
| 642 | parameters, OPUSOptionIDCutoff, OPUS_AUTO); |
| 643 | |
| 644 | // Number of samples per frame per channel |
| 645 | context.opus.frameSize = frameMultiplier * context.sampleRate / 10000; |
| 646 | |
| 647 | context.status = selectionOnly ? XO("Exporting selected audio as Opus") : |
| 648 | XO("Exporting the audio as Opus"); |
| 649 | |
| 650 | // Create opus encoder |
| 651 | int error; |
| 652 | |
| 653 | if (numChannels <= 2) |
| 654 | { |
| 655 | context.opus.channelMapping = 0; |
| 656 | context.opus.nbStreams = 1; |
| 657 | context.opus.nbCoupled = numChannels - 1; |
| 658 | context.opus.streamMap[0] = 0; |
| 659 | context.opus.streamMap[1] = 1; |
| 660 | |
| 661 | context.opus.encoder = opus_multistream_encoder_create( |
| 662 | sampleRate, numChannels, context.opus.nbStreams, |
| 663 | context.opus.nbCoupled, context.opus.streamMap, application, &error); |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | context.opus.channelMapping = numChannels <= 8 ? 1 : 255; |
| 668 |
nothing calls this directly
no test coverage detected