question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid audible glitch when clipping and re-concatenating a single audio source

See original GitHub issue

It works perfect when play a single .m4a file with ProgressiveMediaSource. But it seems not sealmess when play the same audio file with ClippingMediaSource and ConcatenatingMediaSource. For example

        val durations = longArrayOf(20100, 467, 11233, 7100, 6267, 10300)
        var start = 0L
        val audioFile = File(dir, "sample.m4a")
        val audioSource = DefaultMediaSourceFactory(context)
            .createMediaSource(MediaItem.fromUri(Uri.fromFile(audioFile)))
        val concatAudioSource = ConcatenatingMediaSource(true)
        for (i in 0 until durations.size) {
            val durationUs = durations[i] * 1000
            val end = start + durationUs
            val clipAudio = ClippingMediaSource(audioSource, start, end)
            concatAudioSource.addMediaSource(clipAudio)
            start = end
        }
        _player?.run {
            setMediaSource(concatAudioSource)
            prepare()
        }

then you will heard that an obvious pause(maybe glitch?, I’m not sure) between two period. It’s easy to reproduce

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
toniheicommented, Dec 6, 2021

the reason why produce a glitch

The reason is that ExoPlayer flushes the MediaCodec between the different audio resources. If you disable the flushing manually and keep the same codec instance, everything works smoothly without any audible glitches.

We have to flush the codec in the general case because we can’t know whether feeding data from two audio sources to the same decoder consecutively is save (=doesn’t result in some other form of audible glitch). So this enhancement is tracking to either:

  • keep the decoder in some cases where we can be sure it’s safe (unclear if there is such a case)
  • signal to the decoder that two consecutive audio sources are continuous and can use the same decoder. This only makes sense in combination with ClippingMediaSource, so needed to be forwarded from this source somehow.
  • Support merging sources with different number of periods. This is the most flexible approach as it avoids clipping to start with. It doesn’t fit very well into our media model though.
1reaction
YouheiLeecommented, Dec 6, 2021

And I tried that if I cut a resource at an exact pcm frame(I use atds as audio format), there will produce a glitch either. so I guess the reason why produce a glitch is not because ExoPlayer can not cut audio resource at an exact pcm frame but there has no pre-cache of next period when the active period is playing. But I’m not sure about that. I will read source code more deeply when I have time。

Read more comments on GitHub >

github_iconTop Results From Across the Web

pydub audio glitches when splitting/joining mp3 - Stack Overflow
I need the audio playback to be 'seamless' with no audible joins between the separate pieces. At the moment however, the joins between...
Read more >
How can I troubleshoot playback issues on my device? - Audible
Skipping audio; Static or background noises. There are a few basic troubleshooting steps that may resolve these issues. Some options include:.
Read more >
10 Unity Audio Tips (That You Won't Find in the Tutorials)
It's possible to force an individual Audio Source to ignore Audio Listener Pause, allowing it to play even while other audio sources are...
Read more >
just_audio 0.6.8 | Flutter Package - Pub.dev
Compose complex arrangements of audio through concatenating, looping and clipping. Works with audio_session to handle phonecall and other audio interruptions.
Read more >
Master Audio - AAA Sound Solution. #1 audio plugin on Asset ...
Mesh / spline audio - position audio source at the closest part of ... Fixed bug: Single song playlist that loops with Preload...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found