⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 esdlib.c

📁 Windows NT声卡驱动VXD
💻 C
📖 第 1 页 / 共 2 页
字号:
    */

    /* we either got it, or we didn't */
    return socket_out;
}

/*******************************************************************/
/* open a socket for monitoring as a stream */
int esd_monitor_stream( esd_format_t format, int rate, 
			const char *host, const char *name )
{
    int sock;
    int proto = ESD_PROTO_STREAM_MON;
    char name_buf[ ESD_NAME_MAX ];

    /* connect to the EsounD server */
    sock = esd_open_sound( host );
    if ( sock < 0 ) 
	return sock;
    
    /* prepare the name buffer */
    if ( name )
	strncpy( name_buf, name, ESD_NAME_MAX );
    else
	name_buf[ 0 ] = '\0';

    /* send the audio format information */
    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( sock, &format, sizeof(format) ) != sizeof(format) )
	return -1;
    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) )
	return -1;
    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX )
	return -1;

    /* Reduce buffers on sockets to the minimum needed */
    esd_set_socket_buffers( sock, format, rate, 44100 );

    /* flush the socket */
    /* fsync( sock ); */
    
    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound monitoring stream\n" );
    */

    return sock;
}

/*******************************************************************/
/* open a socket for filtering as a stream */
int esd_filter_stream( esd_format_t format, int rate, 
		       const char *host, const char *name )
{
    int sock;
    int proto = ESD_PROTO_STREAM_FILT;
    char name_buf[ ESD_NAME_MAX ];

    /* connect to the EsounD server */
    sock = esd_open_sound( host );
    if ( sock < 0 ) 
	return sock;
    
    /* prepare the name buffer */
    if ( name )
	strncpy( name_buf, name, ESD_NAME_MAX );
    else
	name_buf[ 0 ] = '\0';

    /* send the audio format information */
    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( sock, &format, sizeof(format) ) != sizeof(format) )
	return -1;
    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) )
	return -1;
    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX )
	return -1;

    /* Reduce buffers on sockets to the minimum needed */
    esd_set_socket_buffers( sock, format, rate, 44100 );

    /* flush the socket */
    /* fsync( sock ); */
    
    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound filterng stream\n" );
    */

    return sock;
}

/*******************************************************************/
/* open a socket for recording as a stream */
int esd_record_stream( esd_format_t format, int rate, 
		       const char *host, const char *name )
{
    int sock;
    int proto = ESD_PROTO_STREAM_REC;
    char name_buf[ ESD_NAME_MAX ];

    /* connect to the EsounD server */
    sock = esd_open_sound( host );
    if ( sock < 0 ) 
	return sock;
    
    /* prepare the name buffer */
    if ( name )
	strncpy( name_buf, name, ESD_NAME_MAX );
    else
	name_buf[ 0 ] = '\0';

    /* send the audio format information */
    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( sock, &format, sizeof(format) ) != sizeof(format) )
	return -1;
    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) )
	return -1;
    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX )
	return -1;

    /* Reduce buffers on sockets to the minimum needed */
    esd_set_socket_buffers( sock, format, rate, 44100 );

    /* flush the socket */
    /* fsync( sock ); */
    
    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound recording stream\n" );
    */

    return sock;
}

/*******************************************************************/
/* open a socket for recording as a stream, fallback to /dev/dsp */
int esd_record_stream_fallback( esd_format_t format, int rate, 
				const char *host, const char *name )
{
    int socket_out;

    /* try to open a connection to the server */
    socket_out = esd_record_stream( format, rate, host, name );
    if ( socket_out >= 0 ) 
	return socket_out;

    /* if ESPEAKER is set, this is an error, bail out */
    if ( getenv( "ESPEAKER" ) )
	return -1;

    /* go for /dev/dsp */
//    esd_audio_format = format;
//    esd_audio_rate = rate;
//    socket_out = esd_audio_open();

    /* Reduce buffers on sockets to the minimum needed */
    esd_set_socket_buffers( socket_out, format, rate, 44100 );

    /* diagnostic info */
    /*
//    if ( getenv( "ESDBG" ) )
//	printf( "esound recording stream fallback\n" );
    */

    /* we either got it, or we didn't */
    return socket_out;
}

/*******************************************************************/
/* cache a sample in the server returns sample id, <= 0 is error */
int esd_sample_cache( int esd, esd_format_t format, int rate, 
		      const int size, const char *name )
{
    int id = 0;
    int proto = ESD_PROTO_SAMPLE_CACHE;

    /* prepare the name buffer */
    char name_buf[ ESD_NAME_MAX ];
    if ( name )
	strncpy( name_buf, name, ESD_NAME_MAX );
    else
	name_buf[ 0 ] = '\0';
    /* printf( "caching sample: %s (%d) - %ld bytes\n", 
	    name_buf, esd, size ); */

    /* send the necessary information */
    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;

    if ( write( esd, &format, sizeof(format) ) != sizeof(format) )
	return -1;
    if ( write( esd, &rate, sizeof(rate) ) != sizeof(rate) )
	return -1;
    if ( write( esd, &size, sizeof(size) ) != sizeof(size) )
	return -1;
    if ( write( esd, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX )
	return -1;

    /* flush the socket */
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &id, sizeof(id) ) != sizeof(id) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound caching sample\n" );
    */

    /* return the sample id to the client */
    return id;
}

/*******************************************************************/
/* call this after sending the sample data to the server, should */
/* return the same sample id read previously, <= 0 is error */
int esd_confirm_sample_cache( int esd )
{
    int id = 0;

    /* get the sample id back from the server */
    if ( read( esd, &id, sizeof(id) ) != sizeof(id) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound confirming cached sample\n" );
    */

    /* return the sample id to the client */
    return id;
}

/*******************************************************************/
/* get the sample ID for an already-cached sample */
int esd_sample_getid( int esd, const char *name)
{
    int proto = ESD_PROTO_SAMPLE_GETID;
    int id;
    char namebuf[ESD_NAME_MAX];

    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;

    /* prepare the name buffer */
    if ( name )
	strncpy( namebuf, name, ESD_NAME_MAX );
    else
	namebuf[ 0 ] = '\0';

    if ( write( esd, namebuf, ESD_NAME_MAX ) != ESD_NAME_MAX )
	return -1;

    /* flush the socket */
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &id, sizeof(id) ) != sizeof(id) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound getting cached sample id: \'%s\' = %d\n",
		name, id );
    */
    
    /* return the sample id to the client */
    return id;
}

/*******************************************************************/
/* uncache a sample in the server */
int esd_sample_free( int esd, int sample )
{
    int id;
    int proto = ESD_PROTO_SAMPLE_FREE;

    /* printf( "freeing sample (%d) - <%d>\n", esd, sample ); */

    /* send the necessary information */
    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) )
	return -1;
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &id, sizeof(id) ) != sizeof(id) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
        printf( "esound freeing sample\n" );
    */

    /* return the id to the client (0 = error, 1 = ok) */
    return id;
}

/*******************************************************************/
/* uncache a sample in the server */
int esd_sample_play( int esd, int sample )
{
    int is_ok;
    int proto = ESD_PROTO_SAMPLE_PLAY;

    /* printf( "playing sample (%d) - <%d>\n", esd, sample ); */

    /* send the necessary information */
    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) )
	return -1;
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound playing sample\n" );
    */

    /* return the id to the client (0 = error, 1 = ok) */
    return is_ok;
}


/*******************************************************************/
/* loop a previously cached sample in the server */
int esd_sample_loop( int esd, int sample )
{
    int is_ok;
    int proto = ESD_PROTO_SAMPLE_LOOP;

    /* printf( "looping sample (%d) - <%d>\n", esd, sample ); */

    /* send the necessary information */
    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) )
	return -1;
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound looping sample\n" );
    */

    /* return the id to the client (0 = error, 1 = ok) */
    return is_ok;
}

/*******************************************************************/
/* stop a looping sample in the server */
int esd_sample_stop( int esd, int sample )
{
    int is_ok;
    int proto = ESD_PROTO_SAMPLE_STOP;

    /* printf( "stopping sample (%d) - <%d>\n", esd, sample ); */

    /* send the necessary information */
    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) )
	return -1;
    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) )
	return -1;
    /* fsync( esd ); */

    /* get the sample id back from the server */
    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) )
	return -1;

    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound stopping sample\n" );
    */

    /* return the id to the client (0 = error, 1 = ok) */
    return is_ok;
}

/*******************************************************************/
/* closes fd, previously obtained by esd_open */
int esd_close( int esd )
{
    /* diagnostic info */
    /*
    if ( getenv( "ESDBG" ) )
	printf( "esound closing\n" );
    */

    return close( esd );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -