Hi,

Sam Kaufman wrote:
Hi.

In my app, I am trying to call AmAudioFile::rewind(5000) to rewind a streaming 
MP3 by a few seconds, but it seems to have no effect. Is this meant to be 
supported?

AmAudioFile::rewind is implemented by fseek(3) on the underlying fp. This works well on normal (wav) audio files, because for every AmAudioFile::read(), fread(3) is called.

For mp3, it's a little different: the codec sets the buffer parameters (see mp3.c:367ff), which will cause AmBufferedAudio to read a chunk of mp3 audio from the file and decode it. The reason is that with MP3 stream, you need to decode a chunk of mp3, until you get sufficient audio to play.

File               v fp readpos
+------------------------------------------+
|                                          |
+------------------------------------------+
Buffer   v AmBufferedAudio::r (play pos)
   +---------------+
   |               |
   +---------------+

So, if you want to rewind this, you need to
 - calculate whether rewind length is in buffer,
   if yes you can simply do r-=PCM16_S2B(millisecs*8) and
   you're done

 - rewind fp by rest_of_buffer + calcBytesToRead(millisecs)

 - fix mp3_samples2bytes (see mp3.c), should be possible with CBR

 - reset buffer (AmBufferedAudio::r=AmBufferedAudio::w=0)

hth
Stefan



Probably irrelevant: I am doing this via Python and ivr. I implemented an 
optional integer parameter for IvrAudioFile.rewind that binds to 
AmAudioFile::rewind(int ms). I believe it works because, with a debug level of 
3, I see
[#b61fcb70/14969] [rewind, AmAudioFile.cpp:266] DEBUG: Rewinding 5000 
milliseconds (150 bytes)

Any help would be appreciated, including, if it's not supported, pointers for 
how I might go about implementing.

Best,

Sam
_______________________________________________
Sems mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/sems



--
Stefan Sayer
VoIP Services Consulting and Development

Warschauer Str. 24
10243 Berlin

tel:+491621366449
sip:[email protected]
email/xmpp:[email protected]


_______________________________________________
Sems mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/sems

Reply via email to