Opened 3 years ago

Closed 3 years ago

#5785 closed defect (invalid)

swr_drop_output misbehaviour

Reported by: richardpl Owned by:
Priority: normal Component: swresample
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:
How to reproduce:

Try attached example code

Expected result: properly looped audio.
Actual result: Discarded samples.

Attachments (1)

resampling_audio.c (8.0 KB) - added by richardpl 3 years ago.

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by richardpl

comment:1 Changed 3 years ago by michael

The example seems buggy, it doesnt produce a sinewave that repeats every 1000 samples so droping 1000 will not produce a smooth output. If that is corrected with the patch below the output seems fine.
Or maybe iam missunderstanding the issue ?

diff --git a/doc/examples/resampling_audio.c b/doc/examples/resampling_audio.c
index 2dd2513..a698275 100644
--- a/doc/examples/resampling_audio.c
+++ b/doc/examples/resampling_audio.c
@@ -66,7 +66,7 @@ static void fill_samples(double *dst, int nb_samples, int nb_channels, int sampl
     int i, j;
     double tincr = 1.0 / sample_rate, *dstp = dst;
-    const double c = 2 * M_PI * 440.0;
+    const double c = 2 * M_PI * 48000 / 100; // or 48000 / 1000
     /* generate sin tone with 440Hz frequency and duplicated channels */
     for (i = 0; i < nb_samples; i++) {

comment:2 Changed 3 years ago by richardpl

You misunderstood the issue. Problem is swr dropping 1000 samples, and reporting it dropped 0 samples. While it should not drop any sample.
When feeding it another round of samples it take into account previous value.

comment:3 Changed 3 years ago by michael

swr_drop_output() drops exactly the number requested, thats how its documented as well. "Drops the specified number of output samples."
The return code is documented as ">= 0 on success, or a negative AVERROR code on failure" it has no relation to how many samples will be dropped, i would expect the number of actually dropped samples to be exactly what was requested.

Can you explain what you are trying to do ? / what usecase this is about ?

comment:4 Changed 3 years ago by richardpl

Usecase is seamless looping, without need to reinitializing swr.

comment:5 Changed 3 years ago by michael

If you want to bring the state back to the initial state calling
swr_close() and swr_init() should do that efficiently, this will not reinitialize the resampler

you can drop output samples too but this will not return to exactly the initial state in general.

swr_drop_output(swr_ctx,swr_get_out_samples(swr_ctx, 0));
would drop all the old data, but when new data comes in the buffers will get filled before output comes out, so this will result in an apparent loss of a few audio samples

you can also resample into a dummy buffer and throw that away which will look correct but is possibly not what you actually want because old data remains in the buffer and will be output

If theres some variant missing or can be improved, please say so

comment:6 Changed 3 years ago by richardpl

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.