|
24 | 24 | #include "OptionHandler.h" |
25 | 25 | #include "Config.h" |
26 | 26 |
|
| 27 | +#include "AudioLoader.h" |
27 | 28 | #include "DurationCalculator.h" |
28 | 29 | #include "Error.h" |
29 | 30 | #include "FileFormat.h" |
|
34 | 35 | #include "Options.h" |
35 | 36 | #include "SndFileAudioFileReader.h" |
36 | 37 | #include "Streams.h" |
| 38 | +#include "VectorAudioFileReader.h" |
37 | 39 | #include "WaveformBuffer.h" |
38 | 40 | #include "WaveformColors.h" |
39 | 41 | #include "WaveformGenerator.h" |
@@ -386,37 +388,73 @@ bool OptionHandler::renderWaveformImage( |
386 | 388 | ); |
387 | 389 | } |
388 | 390 | else { |
389 | | - if (calculate_duration) { |
390 | | - auto result = getDuration(input_filename, input_format, !options.getQuiet()); |
| 391 | + if (FileUtil::isStdioFilename(input_filename.c_str()) && |
| 392 | + FileUtil::isStdinFifo() && |
| 393 | + calculate_duration) { |
| 394 | + std::unique_ptr<AudioFileReader> audio_file_reader( |
| 395 | + createAudioFileReader(input_filename, input_format) |
| 396 | + ); |
391 | 397 |
|
392 | | - if (!result.first) { |
393 | | - // log(Error) << "Failed to get audio duration\n"; |
| 398 | + if (!audio_file_reader->open(input_filename.string().c_str())) { |
394 | 399 | return false; |
395 | 400 | } |
396 | 401 |
|
397 | | - double duration = result.second; |
| 402 | + AudioLoader loader; |
| 403 | + |
| 404 | + if (!audio_file_reader->run(loader)) { |
| 405 | + return false; |
| 406 | + } |
398 | 407 |
|
399 | 408 | scale_factor.reset( |
400 | | - new DurationScaleFactor(0.0, duration, options.getImageWidth()) |
| 409 | + new DurationScaleFactor(0.0, loader.getDuration(), options.getImageWidth()) |
401 | 410 | ); |
402 | | - } |
403 | 411 |
|
404 | | - std::unique_ptr<AudioFileReader> audio_file_reader( |
405 | | - createAudioFileReader(input_filename, input_format) |
406 | | - ); |
| 412 | + const bool split_channels = options.getSplitChannels(); |
407 | 413 |
|
408 | | - if (!audio_file_reader->open(input_filename.string().c_str(), !calculate_duration)) { |
409 | | - return false; |
410 | | - } |
| 414 | + WaveformGenerator processor(input_buffer, split_channels, *scale_factor); |
411 | 415 |
|
412 | | - const bool split_channels = options.getSplitChannels(); |
413 | | - WaveformGenerator processor(input_buffer, split_channels, *scale_factor); |
| 416 | + VectorAudioFileReader reader(loader.getData(), loader.getSampleRate(), loader.getChannels()); |
| 417 | + |
| 418 | + if (!reader.run(processor)) { |
| 419 | + return false; |
| 420 | + } |
| 421 | + |
| 422 | + output_samples_per_pixel = input_buffer.getSamplesPerPixel(); |
414 | 423 |
|
415 | | - if (!audio_file_reader->run(processor)) { |
416 | | - return false; |
417 | 424 | } |
| 425 | + else { |
| 426 | + if (calculate_duration) { |
| 427 | + auto result = getDuration(input_filename, input_format, !options.getQuiet()); |
418 | 428 |
|
419 | | - output_samples_per_pixel = input_buffer.getSamplesPerPixel(); |
| 429 | + if (!result.first) { |
| 430 | + return false; |
| 431 | + } |
| 432 | + |
| 433 | + double duration = result.second; |
| 434 | + |
| 435 | + scale_factor.reset( |
| 436 | + new DurationScaleFactor(0.0, duration, options.getImageWidth()) |
| 437 | + ); |
| 438 | + } |
| 439 | + |
| 440 | + std::unique_ptr<AudioFileReader> audio_file_reader( |
| 441 | + createAudioFileReader(input_filename, input_format) |
| 442 | + ); |
| 443 | + |
| 444 | + if (!audio_file_reader->open(input_filename.string().c_str(), !calculate_duration)) { |
| 445 | + return false; |
| 446 | + } |
| 447 | + |
| 448 | + const bool split_channels = options.getSplitChannels(); |
| 449 | + |
| 450 | + WaveformGenerator processor(input_buffer, split_channels, *scale_factor); |
| 451 | + |
| 452 | + if (!audio_file_reader->run(processor)) { |
| 453 | + return false; |
| 454 | + } |
| 455 | + |
| 456 | + output_samples_per_pixel = input_buffer.getSamplesPerPixel(); |
| 457 | + } |
420 | 458 | } |
421 | 459 |
|
422 | 460 | WaveformBuffer output_buffer; |
|
0 commit comments