diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/Makefile.in ./Makefile.in *** ../esound-0.2.35.org/Makefile.in 2004-08-12 23:23:07.000000000 +0900 --- ./Makefile.in 2006-08-30 14:18:00.000000000 +0900 *************** *** 241,246 **** --- 241,248 ---- samples.c \ $(getopt_src) \ util.c \ + ovutil.c \ + ovutil.h \ esd-config.h \ esd-server.h *************** *** 279,285 **** esdplay.c ! LDADD = libesd.la $(AUDIOFILE_LIBS) esd_LDADD = $(WRAP_LIB) $(LDADD) --- 281,287 ---- esdplay.c ! LDADD = libesd.la $(AUDIOFILE_LIBS) -lvorbis -lvorbisenc esd_LDADD = $(WRAP_LIB) $(LDADD) *************** *** 336,347 **** PROGRAMS = $(bin_PROGRAMS) $(esd_PROGRAMS) am__esd_SOURCES_DIST = esd.c clients.c filter.c mix.c players.c proto.c \ ! samples.c getopt.c getopt1.c util.c esd-config.h esd-server.h am__objects_1 = getopt.$(OBJEXT) getopt1.$(OBJEXT) @NEED_GETOPT_TRUE@am__objects_2 = $(am__objects_1) am_esd_OBJECTS = esd.$(OBJEXT) clients.$(OBJEXT) filter.$(OBJEXT) \ mix.$(OBJEXT) players.$(OBJEXT) proto.$(OBJEXT) \ ! samples.$(OBJEXT) $(am__objects_2) util.$(OBJEXT) esd_OBJECTS = $(am_esd_OBJECTS) esd_DEPENDENCIES = libesd.la esd_LDFLAGS = --- 338,349 ---- PROGRAMS = $(bin_PROGRAMS) $(esd_PROGRAMS) am__esd_SOURCES_DIST = esd.c clients.c filter.c mix.c players.c proto.c \ ! samples.c getopt.c getopt1.c util.c ovutil.c esd-config.h esd-server.h am__objects_1 = getopt.$(OBJEXT) getopt1.$(OBJEXT) @NEED_GETOPT_TRUE@am__objects_2 = $(am__objects_1) am_esd_OBJECTS = esd.$(OBJEXT) clients.$(OBJEXT) filter.$(OBJEXT) \ mix.$(OBJEXT) players.$(OBJEXT) proto.$(OBJEXT) \ ! samples.$(OBJEXT) $(am__objects_2) util.$(OBJEXT) ovutil.$(OBJEXT) esd_OBJECTS = $(am_esd_OBJECTS) esd_DEPENDENCIES = libesd.la esd_LDFLAGS = *************** *** 408,413 **** --- 410,416 ---- @AMDEP_TRUE@ ./$(DEPDIR)/libesd_la-genrand.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/libesd_la-util.Plo ./$(DEPDIR)/mix.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/players.Po ./$(DEPDIR)/proto.Po \ + @AMDEP_TRUE@ ./$(DEPDIR)/players.Po ./$(DEPDIR)/ovutil.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/samples.Po ./$(DEPDIR)/util.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) *************** *** 657,662 **** --- 660,666 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proto.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/samples.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ovutil.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/esd-server.h ./esd-server.h *** ../esound-0.2.35.org/esd-server.h 2003-07-05 23:32:07.000000000 +0900 --- ./esd-server.h 2006-08-30 13:34:58.000000000 +0900 *************** *** 19,24 **** --- 19,26 ---- #include #include + #include "ovutil.h" + /*******************************************************************/ /* sound daemon data structures */ *************** *** 87,92 **** --- 89,95 ---- mix_func_t mix_func; /* mixes data into the combined buffer */ translate_func_t translate_func; /* copies data between players */ + OGGVORBIS vorbis; } esd_player_t; /* TODO?: typedef esd_player_t esd_recorder_t, and monitor? */ diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/esd.h ./esd.h *** ../esound-0.2.35.org/esd.h 2004-08-11 21:16:23.000000000 +0900 --- ./esd.h 2006-08-30 14:54:58.000000000 +0900 *************** *** 101,106 **** --- 101,107 ---- #define ESD_STREAM ( 0x0000 ) #define ESD_SAMPLE ( 0x0100 ) #define ESD_ADPCM ( 0x0200 ) /* TODO: anyone up for this? =P */ + #define ESD_VORBIS ( 0x0400 ) /* nyama extend */ /* the function of the stream/sample, and common functions */ #define ESD_MASK_FUNC ( 0xF000 ) diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/ovutil.c ./ovutil.c *** ../esound-0.2.35.org/ovutil.c 1970-01-01 09:00:00.000000000 +0900 --- ./ovutil.c 2006-08-30 13:23:21.000000000 +0900 *************** *** 0 **** --- 1,79 ---- + + #include + #include + #include "ovutil.h" + + static int OVPacketIn( POGGVORBIS pOV, ogg_packet *op ){ + unsigned char* pBuf = pOV->pBuf+pOV->nBuf; + long lenlen = op->bytes/255+1, i; + for( i=0; inBuf++; + } + pBuf[0] = op->bytes % 255; + pBuf++; + pOV->nBuf++; + memcpy( pBuf, op->packet, op->bytes ); + pOV->nBuf += op->bytes; + return 0; + } + + long OVStart( POGGVORBIS pOV, long sample, long rate, long chan, unsigned char** ppBuf ){ + long ret; + ogg_packet header; + ogg_packet header_comm; + ogg_packet header_code; + + pOV->nChan = chan; + + vorbis_info_init( &(pOV->vi) ); + ret = vorbis_encode_init( &(pOV->vi), chan, sample, rate, rate, rate ); + + vorbis_comment_init( &(pOV->vc) ); + vorbis_comment_add_tag( &(pOV->vc), "ENCODER", "ESDMonSrv" ); + + vorbis_analysis_init( &(pOV->vd), &(pOV->vi) ); + vorbis_block_init( &(pOV->vd), &(pOV->vb) ); + + vorbis_analysis_headerout( &(pOV->vd), &(pOV->vc), &header, &header_comm, &header_code ); + + pOV->nBuf = 0; + OVPacketIn( pOV, &header ); + OVPacketIn( pOV, &header_comm ); + OVPacketIn( pOV, &header_code ); + *ppBuf = pOV->pBuf; + return pOV->nBuf; + } + long OVStop( POGGVORBIS pOV ){ + vorbis_block_clear( &(pOV->vb) ); + vorbis_dsp_clear( &(pOV->vd) ); + vorbis_comment_clear( &(pOV->vc) ); + vorbis_info_clear( &(pOV->vi) ); + return 0; + } + long OVEncode( POGGVORBIS pOV, unsigned char** ppBuf, long len ){ + int i,j; + float** buffer; + + len /= (2*pOV->nChan); + buffer = vorbis_analysis_buffer( &(pOV->vd), len ); + for( i=0; inChan; j++ ){ + buffer[j][i] = (short)((((char*)*ppBuf)[2*(i*pOV->nChan+j)+1]<<8)|(*ppBuf)[2*(i*pOV->nChan+j)+0])/32768.f; + } + } + vorbis_analysis_wrote( &(pOV->vd), len ); + + pOV->nBuf = 0; + while( vorbis_analysis_blockout( &(pOV->vd), &(pOV->vb) )==1){ + vorbis_analysis( &(pOV->vb), 0 ); + vorbis_bitrate_addblock( &(pOV->vb) ); + while( vorbis_bitrate_flushpacket( &(pOV->vd), &(pOV->op) ) ){ + OVPacketIn( pOV, &(pOV->op) ); + } + } + *ppBuf = pOV->pBuf; + return pOV->nBuf; + } + diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/ovutil.h ./ovutil.h *** ../esound-0.2.35.org/ovutil.h 1970-01-01 09:00:00.000000000 +0900 --- ./ovutil.h 2006-08-30 13:23:21.000000000 +0900 *************** *** 0 **** --- 1,32 ---- + + #ifndef _OGG_VORBIS_UTIL_ + #define _OGG_VORBIS_UTIL_ + + #ifdef __cplusplus + extern "C" { + #endif + + #include + + #define OV_BUF_SIZE (4096*3) + + typedef struct{ + ogg_packet op; // one raw packet of data for decode + vorbis_info vi; // struct that stores all the static vorbis bitstream settings + vorbis_comment vc; // struct that stores all the user comments + vorbis_dsp_state vd; // central working state for the packet->PCM decoder + vorbis_block vb; // local working space for packet->PCM decode + unsigned char* pBuf; + long nBuf; + long nChan; + } OGGVORBIS, *POGGVORBIS; + + long OVStart( POGGVORBIS pOV, long sample, long rate, long chan, unsigned char** ppBuf ); + long OVStop( POGGVORBIS pOV ); + long OVEncode( POGGVORBIS pOV, unsigned char** ppBuf, long len ); + + #ifdef __cplusplus + } + #endif + + #endif diff -rcN -x .deps -x Makefile -x 'config.*' -x '*.1' -x libtool -x stamp-h1 -x esd-config -x esound.pc ../esound-0.2.35.org/players.c ./players.c *** ../esound-0.2.35.org/players.c 2002-08-18 18:20:59.000000000 +0900 --- ./players.c 2006-08-30 15:25:02.000000000 +0900 *************** *** 52,57 **** --- 52,62 ---- } } + if( player->vorbis.pBuf ){ + OVStop( &(player->vorbis) ); + free( player->vorbis.pBuf ); + } + /* free any memory allocated with the player */ free( player->data_buffer ); *************** *** 413,418 **** --- 418,424 ---- int can_write; struct timeval timeout; esd_player_t *monitor, *remove = NULL; + unsigned char* pBuf; /* make sure we have a monitor connected */ if ( !esd_monitor_list ) *************** *** 441,449 **** esd_audio_rate, esd_audio_format ); /* write the data buffer to the socket */ ! ESD_WRITE_BIN( monitor->source_id, monitor->data_buffer, ! monitor->buffer_length, length, "mon wr" ); if ( length < 0 ) { /* error on write, close it down */ --- 447,462 ---- esd_audio_rate, esd_audio_format ); + pBuf = monitor->data_buffer; + if( monitor->vorbis.pBuf ){ + length = OVEncode( &(monitor->vorbis), &pBuf, length ); + } + /* write the data buffer to the socket */ ! if( length > 0 ){ ! ESD_WRITE_BIN( monitor->source_id, pBuf, ! length, length, "mon wr" ); ! } if ( length < 0 ) { /* error on write, close it down */ *************** *** 526,532 **** player->rate = *(int*)(client->proto_data + sizeof(int)); player->format = maybe_swap_32( client->swap_byte_order, player->format ); - player->format &= ~ESD_MASK_MODE; /* force to ESD_STREAM */ player->rate = maybe_swap_32( client->swap_byte_order, player->rate ); player->source_id = client->fd; --- 539,544 ---- *************** *** 536,541 **** --- 548,580 ---- ESDBG_TRACE( printf( "(%02d) stream %s: 0x%08x at %d Hz\n", client ->fd, player->name, player->format, player->rate ); ); + if( (player->format & ESD_MASK_MODE)== (ESD_STREAM|ESD_VORBIS) ){ + long BitRate, chan, ret; + unsigned char* pBuf; + player->vorbis.pBuf = (unsigned char*)malloc( OV_BUF_SIZE ); + BitRate = player->rate*8; + if( BitRate <= 12000 ){ + player->rate = 8000; + }else if( BitRate <= 24000 ){ + player->rate = 16000; + }else{ + player->rate = 22050; + } + if( (player->format & ESD_MASK_CHAN)== ESD_STEREO ){ + chan = 2; + }else{ + chan = 1; + } + ret = OVStart( &(player->vorbis), player->rate, BitRate, chan, &pBuf ); + if( ret > 0 ){ + ESD_WRITE_BIN( player->source_id, pBuf, + ret, ret, "vorbis head" ); + } + }else{ + player->vorbis.pBuf = NULL; + } + player->format &= ~ESD_MASK_MODE; /* force to ESD_STREAM */ + /* Reduce buffers on sockets to the minimum needed */ esd_set_socket_buffers( player->source_id, player->format, player->rate, esd_audio_rate );