Fixes BufferSink sample size

This commit is contained in:
alban.peignier@gmail.com 2013-06-10 19:31:22 +00:00
parent 3f511ecda0
commit e941d69f14
2 changed files with 40 additions and 33 deletions

View File

@ -264,6 +264,18 @@ class AudioSource : public Source, public virtual Reporter
return bitsPerSample; return bitsPerSample;
} }
/**
* Get the number of bytes for a sample for each channel
* (returns 4 bytes for 16 bits par sample in stereo)
*
* @return the number of bits per sample.
*/
inline unsigned int
getSampleSize ( void ) const throw ()
{
return bitsPerSample / 8 * channel;
}
/** /**
* Factory method for creating an AudioSource object of the * Factory method for creating an AudioSource object of the
* appropriate type, based on the compiled DSP support and * appropriate type, based on the compiled DSP support and
@ -324,4 +336,3 @@ class AudioSource : public Source, public virtual Reporter
#endif /* AUDIO_SOURCE_H */ #endif /* AUDIO_SOURCE_H */

View File

@ -181,7 +181,7 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
if ( !(cs = config.get( "input")) ) { if ( !(cs = config.get( "input")) ) {
throw Exception( __FILE__, __LINE__, "no section [input] in config"); throw Exception( __FILE__, __LINE__, "no section [input] in config");
} }
str = cs->getForSure( "sampleRate", " missing in section [input]"); str = cs->getForSure( "sampleRate", " missing in section [input]");
sampleRate = Util::strToL( str); sampleRate = Util::strToL( str);
str = cs->getForSure( "bitsPerSample", " missing in section [input]"); str = cs->getForSure( "bitsPerSample", " missing in section [input]");
@ -274,13 +274,13 @@ DarkIce :: configIceCast ( const Config & config,
bitrate = str ? Util::strToL( str) : 0; bitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality"); str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0; quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode", str = cs->getForSure( "bitrateMode",
" not specified in section ", " not specified in section ",
stream); stream);
if ( Util::strEq( str, "cbr") ) { if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr; bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) { if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding"); "bitrate not specified for CBR encoding");
@ -307,8 +307,8 @@ DarkIce :: configIceCast ( const Config & config,
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"invalid bitrate mode: ", str); "invalid bitrate mode: ", str);
} }
server = cs->getForSure( "server", " missing in section ", stream); server = cs->getForSure( "server", " missing in section ", stream);
str = cs->getForSure( "port", " missing in section ", stream); str = cs->getForSure( "port", " missing in section ", stream);
@ -332,7 +332,7 @@ DarkIce :: configIceCast ( const Config & config,
fileAddDate = str ? (Util::strEq( str, "yes") ? true : false) : false; fileAddDate = str ? (Util::strEq( str, "yes") ? true : false) : false;
fileDateFormat = cs->get("fileDateFormat"); fileDateFormat = cs->get("fileDateFormat");
bufferSize = dsp->getBitsPerSample() / 8 * dsp->getSampleRate() * dsp->getChannel() * bufferSecs; bufferSize = dsp->getSampleSize() * dsp->getSampleRate() * bufferSecs;
reportEvent( 3, "buffer size: ", bufferSize); reportEvent( 3, "buffer size: ", bufferSize);
localDumpName = cs->get( "localDumpFile"); localDumpName = cs->get( "localDumpFile");
@ -410,7 +410,7 @@ DarkIce :: configIceCast ( const Config & config,
} }
#endif #endif
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
encConnector->attach( audioOuts[u].encoder.get()); encConnector->attach( audioOuts[u].encoder.get());
#endif // HAVE_LAME_LIB || HAVE_TWOLAME_LIB #endif // HAVE_LAME_LIB || HAVE_TWOLAME_LIB
} }
@ -487,7 +487,7 @@ DarkIce :: configIceCast2 ( const Config & config,
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"unsupported stream format: ", str); "unsupported stream format: ", str);
} }
str = cs->get( "sampleRate"); str = cs->get( "sampleRate");
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate(); sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
str = cs->get( "channel"); str = cs->get( "channel");
@ -500,13 +500,13 @@ DarkIce :: configIceCast2 ( const Config & config,
maxBitrate = str ? Util::strToL( str) : 0; maxBitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality"); str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0; quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode", str = cs->getForSure( "bitrateMode",
" not specified in section ", " not specified in section ",
stream); stream);
if ( Util::strEq( str, "cbr") ) { if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr; bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) { if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding"); "bitrate not specified for CBR encoding");
@ -551,9 +551,9 @@ DarkIce :: configIceCast2 ( const Config & config,
fileAddDate = str ? (Util::strEq( str, "yes") ? true : false) : false; fileAddDate = str ? (Util::strEq( str, "yes") ? true : false) : false;
fileDateFormat = cs->get( "fileDateFormat"); fileDateFormat = cs->get( "fileDateFormat");
bufferSize = dsp->getBitsPerSample() / 8 * dsp->getSampleRate() * dsp->getChannel() * bufferSecs; bufferSize = dsp->getSampleSize() * dsp->getSampleRate() * bufferSecs;
reportEvent( 3, "buffer size: ", bufferSize); reportEvent( 3, "buffer size: ", bufferSize);
localDumpName = cs->get( "localDumpFile"); localDumpName = cs->get( "localDumpFile");
// go on and create the things // go on and create the things
@ -616,7 +616,7 @@ DarkIce :: configIceCast2 ( const Config & config,
lowpass, lowpass,
highpass ); highpass );
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
#endif // HAVE_LAME_LIB #endif // HAVE_LAME_LIB
break; break;
@ -640,7 +640,7 @@ DarkIce :: configIceCast2 ( const Config & config,
dsp->getChannel(), dsp->getChannel(),
maxBitrate); maxBitrate);
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
#endif // HAVE_VORBIS_LIB #endif // HAVE_VORBIS_LIB
break; break;
@ -681,7 +681,7 @@ DarkIce :: configIceCast2 ( const Config & config,
sampleRate, sampleRate,
channel ); channel );
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
#endif // HAVE_TWOLAME_LIB #endif // HAVE_TWOLAME_LIB
break; break;
@ -702,7 +702,7 @@ DarkIce :: configIceCast2 ( const Config & config,
sampleRate, sampleRate,
dsp->getChannel()); dsp->getChannel());
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
#endif // HAVE_FAAC_LIB #endif // HAVE_FAAC_LIB
break; break;
@ -722,7 +722,7 @@ DarkIce :: configIceCast2 ( const Config & config,
sampleRate, sampleRate,
channel ); channel );
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
#endif // HAVE_AACPLUS_LIB #endif // HAVE_AACPLUS_LIB
break; break;
@ -805,13 +805,13 @@ DarkIce :: configShoutCast ( const Config & config,
bitrate = str ? Util::strToL( str) : 0; bitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality"); str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0; quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode", str = cs->getForSure( "bitrateMode",
" not specified in section ", " not specified in section ",
stream); stream);
if ( Util::strEq( str, "cbr") ) { if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr; bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) { if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding"); "bitrate not specified for CBR encoding");
@ -907,7 +907,7 @@ DarkIce :: configShoutCast ( const Config & config,
icq, icq,
localDumpFile); localDumpFile);
encoder = new LameLibEncoder( audioOuts[u].server.get(), encoder = new LameLibEncoder( audioOuts[u].server.get(),
dsp.get(), dsp.get(),
bitrateMode, bitrateMode,
@ -917,7 +917,7 @@ DarkIce :: configShoutCast ( const Config & config,
channel, channel,
lowpass, lowpass,
highpass ); highpass );
audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8); audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
encConnector->attach( audioOuts[u].encoder.get()); encConnector->attach( audioOuts[u].encoder.get());
#endif // HAVE_LAME_LIB #endif // HAVE_LAME_LIB
@ -991,13 +991,13 @@ DarkIce :: configFileCast ( const Config & config )
bitrate = str ? Util::strToL( str) : 0; bitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality"); str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0; quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode", str = cs->getForSure( "bitrateMode",
" not specified in section ", " not specified in section ",
stream); stream);
if ( Util::strEq( str, "cbr") ) { if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr; bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) { if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__, throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding"); "bitrate not specified for CBR encoding");
@ -1192,7 +1192,7 @@ DarkIce :: setRealTimeScheduling ( void ) throw ( Exception )
throw Exception( __FILE__, __LINE__, "sched_getparam", errno); throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
} }
origSchedPriority = param.sched_priority; origSchedPriority = param.sched_priority;
/* set SCHED_FIFO with max - 1 priority or user configured value */ /* set SCHED_FIFO with max - 1 priority or user configured value */
if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) { if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno); throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
@ -1272,12 +1272,9 @@ DarkIce :: encode ( void ) throw ( Exception )
if ( !encConnector->open() ) { if ( !encConnector->open() ) {
throw Exception( __FILE__, __LINE__, "can't open connector"); throw Exception( __FILE__, __LINE__, "can't open connector");
} }
bytes = dsp->getSampleRate() * bytes = dsp->getSampleRate() * dsp->getSampleSize() * duration;
(dsp->getBitsPerSample() / 8UL) *
dsp->getChannel() *
duration;
len = encConnector->transfer( bytes, 4096, 1, 0 ); len = encConnector->transfer( bytes, 4096, 1, 0 );
reportEvent( 1, len, "bytes transfered to the encoders"); reportEvent( 1, len, "bytes transfered to the encoders");
@ -1295,7 +1292,7 @@ int
DarkIce :: run ( void ) throw ( Exception ) DarkIce :: run ( void ) throw ( Exception )
{ {
reportEvent( 3, "encoding"); reportEvent( 3, "encoding");
if (enableRealTime) { if (enableRealTime) {
setRealTimeScheduling(); setRealTimeScheduling();
} }
@ -1321,4 +1318,3 @@ DarkIce :: cut ( void ) throw ()
reportEvent( 5, "cutting ends"); reportEvent( 5, "cutting ends");
} }