audioread icon indicating copy to clipboard operation
audioread copied to clipboard

Support for Seeking to a frame?

Open pconerly opened this issue 5 years ago • 2 comments

Hello, Are there any plans to support seeking to a specific frame?

I'm writing a small app that shows a song's Hz spectograph and, and allows play/pausing of the song along with the spectograph. Play/pause works great, but I'd like a way to reset what frame we're reading from. (That would allow to the user to "stop" and set the time to 0, or click on a spot and seek to that spot.)

I found that the OSX AudioToolbox backend has ExtAudioFileSeek: https://developer.apple.com/documentation/audiotoolbox/1486821-extaudiofileread?language=objc

And Python aifc has:

aifc.rewind()
aifc.setpos(pos)

https://docs.python.org/3.6/library/aifc.html

Backends to investigate:

  • [x] rawread.py/aifc (has aifc.setpos)
  • [x] ffdec ffmpeg (has a seek option on command start. Audioread might have to close & restart the channel on seek?)
  • [x] gstdec.py/Gstreamer / pygobject (has IOChannel.seek)
  • [x] macca.py/AudioToolbox (has ExtAudioFileSeek)
  • [x] maddec.py/MAD/pymad (has seek_time)

pconerly avatar Aug 21 '18 18:08 pconerly

Great idea! This might be hard to support in some backends, like the ffmpeg one, but that shouldn't stop us from adding it to backends where it's easy/possible.

One thing to remember is that we'll want a consistent story for what happens when you seek too far or backwards, if that's disallowed (silent no-op? immediate exception? exception after trying to read post-seek?).

sampsyo avatar Aug 21 '18 22:08 sampsyo

@sampsyo I think I'd vote for an immediate exception, so that users can take their own action. But also, I investigated the backends and I think it's possible to do with all of them.

I'm gonna try adding it to one of the backends and then submit a PR that we can chat about.

pconerly avatar Aug 22 '18 17:08 pconerly