Slim::Music::Info::setDelayedCallback incorrect delay calc for 48000 sample rate

expectingtofly <expectingtofly.a9vffb-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]>
Newsgroups gmane.music.equipment.slimdevices.devel
Organization Logitech Squeezebox Forums
Message-ID <[email protected]>
I have been trying to get precise track info display on the BBC sounds
plugin which uses Slim::Music::Info::setDelayedCallback to provide the
track info at the right time in sync with the audio.
I've noticed that the 'getStreamDelay' operation that it uses to
calculate the delay require,  has the sample rate of 44100 hard coded
into the calculation.  BBC Sounds audio uses a 48000 sample rate which
makes the delay calculation (for the output buffer bit) around 8% out.


Code:
--------------------
    sub getStreamDelay {
  	my ( $client, $outputDelayOnly ) = @_;
  	
  	return 0 unless $client->streamingSong();
  	
  	my $bitrate = $client->streamingSong()->streambitrate() || 128000;
  	my $delay   = 0;
  	
  	if ( $bitrate > 0 ) {
  		my $decodeBuffer = $client->bufferFullness() / ( int($bitrate / 8) );
  		my $outputBuffer = $client->outputBufferFullness() / (44100 * 8);
  	
  		if ( $outputDelayOnly ) {
  			$delay = $outputBuffer;
  		}
  		else {
  			$delay = $decodeBuffer + $outputBuffer;
  		}
  	}
  	
  	return $delay;
  }
--------------------


It isn't that noticeable, to be honest, and if I really wanted to fix it
I could easily bring the calculation and timer into the plugin.

But I wondered if this is like this for historical reasons and is best
left alone, and it is a more complicated subject than I realise? (e.g.
resampling can happen etc).  If it isn't, I'm happy to do a PR to fix
it.



Stuart McLean   

EXPECTINGTOFLY PLUGINS :
    
- *BBC Sounds* : 
  https://github.com/expectingtofly/LMS_BBC_Sounds_Plugin 
- *Virgin Radio (UK)* : 
  https://github.com/expectingtofly/LMS_Virgin_Radio_Plugin 
- *Times Radio* : 
  https://github.com/expectingtofly/LMS_TIMES_RADIO_PLUGIN 
- *Global Player (UK)* : 
  https://github.com/expectingtofly/LMS_GlobalPlayer_Plugin 
  
For BBC Sounds help see the 'BBC Sounds Wiki'
(https://github.com/expectingtofly/LMS_BBC_Sounds_Plugin/wiki).
------------------------------------------------------------------------
expectingtofly's Profile: http://forums.slimdevices.com/member.php?userid=63263
View this thread: http://forums.slimdevices.com/showthread.php?t=115303
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.