| 641 | } |
| 642 | |
| 643 | ExportResult CLExportProcessor::Process(ExportProcessorDelegate& delegate) |
| 644 | { |
| 645 | delegate.SetStatusString(context.status); |
| 646 | auto& process = *context.process; |
| 647 | auto exportResult = ExportResult::Success; |
| 648 | { |
| 649 | size_t numBytes = 0; |
| 650 | constSamplePtr mixed = nullptr; |
| 651 | |
| 652 | wxOutputStream *os = process.GetOutputStream(); |
| 653 | auto closeIt = finally ( [&] { |
| 654 | // Should make the process die, before propagating any exception |
| 655 | process.CloseOutput(); |
| 656 | } ); |
| 657 | |
| 658 | // Start piping the mixed data to the command |
| 659 | while (exportResult == ExportResult::Success && process.IsActive() && os->IsOk()) { |
| 660 | // Capture any stdout and stderr from the command |
| 661 | Drain(process.GetInputStream(), &context.output); |
| 662 | Drain(process.GetErrorStream(), &context.output); |
| 663 | |
| 664 | // Need to mix another block |
| 665 | if (numBytes == 0) { |
| 666 | auto numSamples = context.mixer->Process(); |
| 667 | if (numSamples == 0) |
| 668 | break; |
| 669 | |
| 670 | mixed = context.mixer->GetBuffer(); |
| 671 | numBytes = numSamples * context.channels; |
| 672 | |
| 673 | // Byte-swapping is necessary on big-endian machines, since |
| 674 | // WAV files are little-endian |
| 675 | #if wxBYTE_ORDER == wxBIG_ENDIAN |
| 676 | auto buffer = (const float *) mixed; |
| 677 | for (int i = 0; i < numBytes; i++) { |
| 678 | buffer[i] = wxUINT32_SWAP_ON_BE(buffer[i]); |
| 679 | } |
| 680 | #endif |
| 681 | numBytes *= SAMPLE_SIZE(floatSample); |
| 682 | } |
| 683 | |
| 684 | // Don't write too much at once...pipes may not be able to handle it |
| 685 | size_t bytes = wxMin(numBytes, 4096); |
| 686 | numBytes -= bytes; |
| 687 | |
| 688 | while (bytes > 0) { |
| 689 | os->Write(mixed, bytes); |
| 690 | if (!os->IsOk()) { |
| 691 | exportResult = ExportResult::Error; |
| 692 | break; |
| 693 | } |
| 694 | bytes -= os->LastWrite(); |
| 695 | mixed += os->LastWrite(); |
| 696 | } |
| 697 | |
| 698 | if(exportResult == ExportResult::Success) |
| 699 | exportResult = ExportPluginHelpers::UpdateProgress( |
| 700 | delegate, *context.mixer, context.t0, context.t1); |
nothing calls this directly
no test coverage detected