bbc / audiowaveform

C++ program to generate waveform data and render waveform images from audio files
https://waveform.prototyping.bbc.co.uk
GNU General Public License v3.0
1.94k stars 242 forks source link

Auto -End parameter #58

Open galenhuckins opened 6 years ago

galenhuckins commented 6 years ago

Is there way to have the script autodetect the length to show the entire audio file without setting start/end/zoom?

chrisn commented 6 years ago

At present, no, but I could change the --zoom option to accept an auto value that, when combined with the --width option, scales the waveform to fit the specified width. Does that sound OK? Thanks for the suggestion!

galenhuckins commented 6 years ago

That would be perfect. I don't have access to duration metadata on some of the files and so displaying an overview is tricky. Thanks for being so responsive, great script!

chrisn commented 6 years ago

This is a useful feature, so I will plan to add it, but I can't give any promises about timescale at this stage.

Proper-Job commented 6 years ago

@chrisn That would be really helpful.

chrisn commented 6 years ago

I've just published 1.2.0 which implements this feature. Feedback welcome!

ashraffayad commented 3 years ago

the --zoom auto function didn't work (v1.4.2).

This was the command audiowaveform -i a.mp3 -b 8 -w 400 -h 30 -z auto -o track.json

This was the output

Input file: a.mp3
Format: Audio MPEG layer III stream
Bit rate: 160000 kbit/s
CRC: no
Mode: joint (MS/intensity) stereo
Emphasis: no
Sample rate: 44100 Hz
Encoding delay: unknown
Padding: unknown
Invalid zoom: minimum 2
chrisn commented 3 years ago

I think you've found a bug. The -z auto option should only work with PNG output, so the error message is wrong. If you want JSON output, you need to pass a number with -z. We could enable auto for JSON output, but you won't get the exact number of output points as you expect, due to rounding errors. See this related issue: https://github.com/bbc/audiowaveform/issues/114 for more details.

ashraffayad commented 3 years ago

I understand. Thanks Chrisn

chrisn commented 3 years ago

I'll re-open this, as it would be a useful feature.

henock1 commented 3 years ago

This would be a nice improvement. I seem to be running into this when rendering pngs in 1.4.2 as well:

Example 1:

Command: audiowaveform -i dat/example1.dat -o output.png --output-format png --no-axis-labels --waveform-color 000000 --background-color 00000000 -z auto -w 3500 -h 250 Output:

Input file: dat/example1.dat
Channels: 1
Sample rate: 44100 Hz
Bits: 8
Samples per pixel: 256
Length: 1540 points
Invalid zoom, minimum: 256

I worked around this error by not passing a -z param: Command: audiowaveform -i dat/example1.dat -o output.png --output-format png --no-axis-labels --waveform-color 000000 --background-color 00000000 -w 3500 -h 250 Output:

Input file: dat/example1.dat
Channels: 1
Sample rate: 44100 Hz
Bits: 8
Samples per pixel: 256
Length: 1540 points
Image dimensions: 3500x250 pixels
Channels: 1
Sample rate: 44100 Hz
Samples per pixel: 256
Start time: 0 seconds
Start index: 0
Buffer size: 1540
Axis labels: no
Amplitude scale: 1
Output file: output.png
Done

Example 2 Command: audiowaveform -i dat/example2.dat -o output.png --output-format png --no-axis-labels --waveform-color 000000 --background-color 00000000 -z auto Output:

Input file: dat/example2.dat
Channels: 1
Sample rate: 48000 Hz
Bits: 8
Samples per pixel: 480
Length: 556 points
Invalid zoom, minimum: 480
chrisn commented 3 years ago

@henock1 With your example 1, the data file length is 1540 points and the image width is 3500 pixels. If you specify -z auto, you're asking for the 1540 data points to be stretched to fit into 3500 pixels. This isn't currently supported, and why it reports "Invalid zoom".

Without -z auto, the data points will not be stretched, and the waveform will not fill the entire image width. The same happens in example 2, where the data file length is 556 points and the default image width (800 pixels) is used.

Is the solution here to implement stretching?

If you want the waveform to fill the image width, you would need to create new data files with higher resolution, e.g., 128 samples/pixel instead of 256.

ice6 commented 1 year ago

cool, so -z auto is equal to 'auto end' :)