| 490 | } |
| 491 | |
| 492 | bool CLExportProcessor::Initialize(AudacityProject& project, |
| 493 | const Parameters& parameters, |
| 494 | const wxFileNameWrapper& fName, |
| 495 | double t0, double t1, bool selectionOnly, |
| 496 | double sampleRate, unsigned channels, |
| 497 | MixerOptions::Downmix* mixerSpec, |
| 498 | const Tags* metadata) |
| 499 | { |
| 500 | context.t0 = t0; |
| 501 | context.t1 = t1; |
| 502 | context.channels = channels; |
| 503 | |
| 504 | ExtendPath ep; |
| 505 | long rc; |
| 506 | |
| 507 | const auto path = fName.GetFullPath(); |
| 508 | |
| 509 | context.cmd = wxString::FromUTF8(ExportPluginHelpers::GetParameterValue<std::string>(parameters, CLOptionIDCommand)); |
| 510 | context.showOutput = ExportPluginHelpers::GetParameterValue(parameters, CLOptionIDShowOutput, false); |
| 511 | |
| 512 | // Bug 2178 - users who don't know what they are doing will |
| 513 | // now get a file extension of .wav appended to their ffmpeg filename |
| 514 | // and therefore ffmpeg will be able to choose a file type. |
| 515 | if( context.cmd == wxT("ffmpeg -i - \"%f\"") && !fName.HasExt()) |
| 516 | context.cmd.Replace( "%f", "%f.wav" ); |
| 517 | context.cmd.Replace(wxT("%f"), path); |
| 518 | |
| 519 | // Kick off the command |
| 520 | context.process = std::make_unique<ExportCLProcess>(&context.output); |
| 521 | auto& process = *context.process; |
| 522 | |
| 523 | rc = wxExecute(context.cmd, wxEXEC_ASYNC, &process); |
| 524 | if (!rc) { |
| 525 | process.Detach(); |
| 526 | process.CloseOutput(); |
| 527 | throw ExportException(XO("Cannot export audio to %s") |
| 528 | .Format( path ) |
| 529 | .Translation()); |
| 530 | } |
| 531 | |
| 532 | // Turn off logging to prevent broken pipe messages |
| 533 | wxLogNull nolog; |
| 534 | |
| 535 | // establish parameters |
| 536 | int rate = lrint(sampleRate); |
| 537 | const size_t maxBlockLen = 44100 * 5; |
| 538 | unsigned long totalSamples = lrint((t1 - t0) * rate); |
| 539 | unsigned long sampleBytes = totalSamples * channels * SAMPLE_SIZE(floatSample); |
| 540 | |
| 541 | wxOutputStream *os = process.GetOutputStream(); |
| 542 | |
| 543 | // RIFF header |
| 544 | struct { |
| 545 | char riffID[4]; // "RIFF" |
| 546 | wxUint32 riffLen; // basically the file len - 8 |
| 547 | char riffType[4]; // "WAVE" |
| 548 | } riff; |
| 549 |
no test coverage detected