diff --git a/darkice/trunk/src/VorbisLibEncoder.cpp b/darkice/trunk/src/VorbisLibEncoder.cpp index 855cbf0..ee24088 100644 --- a/darkice/trunk/src/VorbisLibEncoder.cpp +++ b/darkice/trunk/src/VorbisLibEncoder.cpp @@ -33,12 +33,6 @@ #include "config.h" #endif -#ifdef HAVE_STRING_H -#include -#else -#error need string.h -#endif - #include "Exception.h" #include "Util.h" @@ -154,9 +148,8 @@ VorbisLibEncoder :: conv8 ( unsigned char * pcmBuffer, for ( i = 0, j = 0; i < lenPcmBuffer; ) { short int value; - value = pcmBuffer[i++]; - leftBuffer[j] = ((float) value) / 32768.f; - rightBuffer[j] = leftBuffer[j]; + value = pcmBuffer[i++]; + leftBuffer[j] = ((float) value) / 128.f; ++j; } } else { @@ -165,10 +158,10 @@ VorbisLibEncoder :: conv8 ( unsigned char * pcmBuffer, for ( i = 0, j = 0; i < lenPcmBuffer; ) { short int value; - value = pcmBuffer[i++]; - leftBuffer[j] = ((float) value) / 32768.f; - value = pcmBuffer[i++]; - rightBuffer[j] = ((float) value) / 32768.f; + value = pcmBuffer[i++]; + leftBuffer[j] = ((float) value) / 128.f; + value = pcmBuffer[i++]; + rightBuffer[j] = ((float) value) / 128.f; ++j; } } @@ -192,10 +185,9 @@ VorbisLibEncoder :: conv16 ( unsigned char * pcmBuffer, for ( i = 0, j = 0; i < lenPcmBuffer; ) { short int value; - value = pcmBuffer[i++]; - value += pcmBuffer[i++] << 8; - leftBuffer[j] = ((float) value) / 32768.f; - rightBuffer[j] = leftBuffer[j]; + value = pcmBuffer[i++]; + value |= pcmBuffer[i++] << 8; + leftBuffer[j] = ((float) value) / 32768.f; ++j; } } else { @@ -204,12 +196,12 @@ VorbisLibEncoder :: conv16 ( unsigned char * pcmBuffer, for ( i = 0, j = 0; i < lenPcmBuffer; ) { short int value; - value = pcmBuffer[i++]; - value += pcmBuffer[i++] << 8; - leftBuffer[j] = ((float) value) / 32768.f; - value = pcmBuffer[i++]; - value += pcmBuffer[i++] << 8; - rightBuffer[j] = ((float) value) / 32768.f; + value = pcmBuffer[i++]; + value |= pcmBuffer[i++] << 8; + leftBuffer[j] = ((float) value) / 32768.f; + value = pcmBuffer[i++]; + value |= pcmBuffer[i++] << 8; + rightBuffer[j] = ((float) value) / 32768.f; ++j; } } @@ -255,36 +247,7 @@ VorbisLibEncoder :: write ( const void * buf, } vorbis_analysis_wrote( &vorbisDspState, nSamples); - - while ( 1 == vorbis_analysis_blockout( &vorbisDspState, &vorbisBlock) ) { - ogg_packet oggPacket; - ogg_page oggPage; - - vorbis_analysis( &vorbisBlock, &oggPacket); - ogg_stream_packetin( &oggStreamState, &oggPacket); - - while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) { - int written; - - written = sink->write( oggPage.header, oggPage.header_len); -reportEvent( 5, "written to server ", written, " bytes."); - if ( written < oggPage.header_len ) { - // just let go data that could not be written - reportEvent( 2, - "couldn't write full vorbis header to underlying sink", - oggPage.header_len - written); - } - - written = sink->write( oggPage.body, oggPage.body_len); -reportEvent( 5, "written to server ", written, " bytes."); - if ( written < oggPage.body_len ) { - // just let go data that could not be written - reportEvent( 2, - "couldn't write full vorbis body to underlying sink", - oggPage.body_len - written); - } - } - } + vorbisBlocksOut(); return processed; } @@ -302,7 +265,38 @@ VorbisLibEncoder :: flush ( void ) } vorbis_analysis_wrote( &vorbisDspState, 0); - // ??? + vorbisBlocksOut(); + sink->flush(); +} + + +/*------------------------------------------------------------------------------ + * Send pending Vorbis blocks to the underlying stream + *----------------------------------------------------------------------------*/ +void +VorbisLibEncoder :: vorbisBlocksOut ( void ) throw () +{ + while ( 1 == vorbis_analysis_blockout( &vorbisDspState, &vorbisBlock) ) { + ogg_packet oggPacket; + ogg_page oggPage; + + vorbis_analysis( &vorbisBlock, &oggPacket); + ogg_stream_packetin( &oggStreamState, &oggPacket); + + while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) { + int written; + + written = sink->write( oggPage.header, oggPage.header_len); + written += sink->write( oggPage.body, oggPage.body_len); + + if ( written < oggPage.header_len + oggPage.body_len ) { + // just let go data that could not be written + reportEvent( 2, + "couldn't write full vorbis data to underlying sink", + oggPage.header_len + oggPage.body_len - written); + } + } + } } @@ -331,6 +325,9 @@ VorbisLibEncoder :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.2 2001/09/15 11:36:22 darkeye + added function vorbisBlocksOut(), finalized vorbis support + Revision 1.1 2001/09/14 19:31:06 darkeye added IceCast2 / vorbis support diff --git a/darkice/trunk/src/VorbisLibEncoder.h b/darkice/trunk/src/VorbisLibEncoder.h index ddb0968..9f5f721 100644 --- a/darkice/trunk/src/VorbisLibEncoder.h +++ b/darkice/trunk/src/VorbisLibEncoder.h @@ -40,8 +40,11 @@ #include "config.h" #endif -// TODO +#ifdef HAVE_VORBIS_VORBISENC_H #include +#else +#error need vorbis/vorbisenc.h +#endif #include "Ref.h" @@ -147,8 +150,8 @@ class VorbisLibEncoder : public AudioEncoder, public virtual Reporter * channels are interleaved * @param lenPcmBuffer length of pcmBuffer * @param leftBuffer put the left channel here (must be big enough) - * @param rightBuffer put the right channel here (if mono, same - * as leftChannel, must be big enough) + * @param rightBuffer put the right channel here (if mono, not + * touched, must be big enough) * @param channels number of channels (1 = mono, 2 = stereo) */ void @@ -165,8 +168,8 @@ class VorbisLibEncoder : public AudioEncoder, public virtual Reporter * channels are interleaved * @param lenPcmBuffer length of pcmBuffer * @param leftBuffer put the left channel here (must be big enough) - * @param rightBuffer put the right channel here (if mono, same - * as leftChannel, must be big enough) + * @param rightBuffer put the right channel here (if mono, not + * touched, must be big enough) * @param channels number of channels (1 = mono, 2 = stereo) */ void @@ -176,6 +179,12 @@ class VorbisLibEncoder : public AudioEncoder, public virtual Reporter float * rightBuffer, unsigned int channels ); + /** + * Send pending Vorbis blocks to the underlying stream + */ + void + vorbisBlocksOut( void ) throw (); + protected: @@ -433,6 +442,9 @@ class VorbisLibEncoder : public AudioEncoder, public virtual Reporter $Source$ $Log$ + Revision 1.2 2001/09/15 11:36:22 darkeye + added function vorbisBlocksOut(), finalized vorbis support + Revision 1.1 2001/09/14 19:31:06 darkeye added IceCast2 / vorbis support