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