亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? soundit.c

?? 在linux下多媒體開發實例linux下多媒體開發
?? C
字號:
/* SoundIt library 0.021   Copyright 1994 Brad Pitzel  pitzel@cs.sfu.ca   Feel free to use/distribute/modify as long as proper credits   are included.*/#include "soundit.h"#include <malloc.h>#include <limits.h>	/* PATH_MAX */#include <stdio.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/time.h>#include <sys/stat.h>#include <fcntl.h>#include <linux/soundcard.h>#include <sys/ioctl.h>#include <sys/wait.h>/*==========================================================================*//* the mix buff, where the channels are mixed into. The mix buffer is then   dumped to the sound device (/dev/dsp). Samples are mixed in   Vunclipbuf (buffer of ints), then the values in Vunclipbuf are clipped to   values between 0 and 255, and stored into Vclippedbuf (buffer of unsigned   chars).*/struct Mix    {    unsigned char *Vclippedbuf;	    int *Vunclipbuf;    int Vsize;    };typedef struct Mix Mix;/*==========================================================================*/struct Channel    {    unsigned char *Vstart,*Vcurrent;	/* ptr's into a playing sample */    int	Vlen;				/* length of sample in bytes */    int	Vleft;				/* bytes left of sample to play */    };typedef struct Channel Channel;/*==========================================================================*//* variables prefixed with S_ are static *//* 0 if mixer isn't initialized or init failed, 1 if mixer is good */static int sampleMixerStatus = 0;	static const Sample 	*S_sounds = NULL; /* ptr to array of samples */static int S_num_sounds = 0;		/* size of 'sounds' array above */static int S_fd_snddev = -1;		/* file # for sound device once open */static int S_fd_pipe[2] = { -1, -1 };	/* pipe to talk to child process */static int S_son_pid = -1;		/* process ID for the forked sound mixer */static const char *S_snddev = NULL;	/* char string for device, ie "/dev/dsp" */static int S_num_channels = 6;		/* number of channels to mix */static int S_playback_freq = 0;		/* playback frequency (in Hz) *//*==========================================================================*//* non-public functions, used only within this file*/int Snd_init_dev();int Snd_restore_dev();void Chan_reset( Channel *chan );	/* init channel structure */	/* start a sample playing on a channel */void Chan_assign( Channel *chan, const Sample *snd );	/* mix all channels together into the 'mix' structure */int  Chan_mixAll( Mix *mix, Channel *ch );	/* used by Chan_mixAll to mix the 1st channel */int  Chan_copyIn( Channel *chan, Mix *mix );	/* used by Chan_mixAll to mix the middle channels */int  Chan_mixIn( Channel *chan, Mix *mix );	/* used by Chan_mixAll to mix the last channel */int  Chan_finalMixIn( Channel *chan, Mix *mix );/* alloc mem for mix buffer, and deallocate function *//* The sound channels are mixed together into the mix buffer   *//* then the mix buffer data is sent directly to the sound device */void Mix_alloc( Mix *mix, int size );void Mix_dealloc( Mix *mix );/*==========================================================================*//* justing for testing, normally not called */void dump_snd_list()	{	int i=0;		for(i=0; i<S_num_sounds; i++)		{		/* printf("snd %d: len = %d \n", i, S_sounds[i].len ); */		}	}	/*==========================================================================*/int Snd_init( int num_snd, const Sample *sa, int frequency,               int channels, const char *dev )	{	int result;	S_num_sounds     = num_snd;	S_sounds         = sa;	/* array of sound samples*/	S_playback_freq  = frequency;	S_num_channels   = channels; 	S_snddev= dev;	/* sound device, eg /dev/dsp*/		if (S_sounds==NULL)		return EXIT_FAILURE;		result=Snd_init_dev();	if (result==EXIT_SUCCESS)		{		sampleMixerStatus=1;		}	else		{		sampleMixerStatus=0;		}	return result;	}/*==========================================================================*/int Snd_restore()	{	int result;	if (!sampleMixerStatus)		return EXIT_FAILURE;		result=Snd_restore_dev();	if (result==EXIT_SUCCESS)		{		sampleMixerStatus=0;		}	else		{		sampleMixerStatus=0;		}	return result;	}/*==========================================================================*//* volume control not implemented yet.*/int Snd_effect( int sound_num, int channel )	{	if(! sampleMixerStatus )		return EXIT_FAILURE;			if(S_sounds[sound_num].data != NULL)		{			write(S_fd_pipe[1], &sound_num, sizeof(sound_num));		write(S_fd_pipe[1], &channel, sizeof(channel));		}	return EXIT_SUCCESS;	}/*============================================================================*/int Snd_init_dev()	{	int whoami;	S_fd_snddev = -1;	S_son_pid = 0;	if(access(S_snddev,W_OK) != 0)		{			return EXIT_FAILURE;		}	S_fd_snddev = open(S_snddev,O_WRONLY);	if(S_fd_snddev < 0)		{			return EXIT_FAILURE;		}			close(S_fd_snddev);	if(pipe(S_fd_pipe) < 0)		{			return EXIT_FAILURE;		}	/* now setup 2nd process for writing the data... */	if((whoami = fork()) < 0)		{			return EXIT_FAILURE;		}			if(whoami != 0)	/* successfully created son */		{			close(S_fd_pipe[0]);	/* close end for reading */		S_son_pid = whoami;		return EXIT_SUCCESS;		}				/* Here is the code for the son... */		{		int sound_num,ch,i;		struct timeval tval = {0L,0L};		fd_set readfds,dsp;		Mix mix;				int frag, fragsize;		Channel *chan = (Channel*)malloc( sizeof(Channel)*S_num_channels );		for (i=0; i<S_num_channels; i++)			Chan_reset( chan+i );					S_fd_snddev = open(S_snddev,O_WRONLY );		if(S_fd_snddev < 0)			{				exit(1);			}		frag = FRAG_SPEC; /*defined in soundIt.h */		 		ioctl(S_fd_snddev, SNDCTL_DSP_SETFRAGMENT, &frag); 		ioctl(S_fd_snddev,SNDCTL_DSP_SPEED, &S_playback_freq);		fragsize=0;		ioctl(S_fd_snddev,SNDCTL_DSP_GETBLKSIZE, &fragsize);					/* init mixer object*/		Mix_alloc( &mix, fragsize );		close(S_fd_pipe[1]);	/* close end for writing */		FD_ZERO(&dsp); 		FD_SET(S_fd_snddev, &dsp);				FD_ZERO(&readfds); 		FD_SET(S_fd_pipe[0], &readfds);				for(;;)			{			FD_ZERO(&readfds); 			FD_SET(S_fd_pipe[0], &readfds);			tval.tv_sec=0L;			tval.tv_usec=0L;			i = select(S_fd_pipe[0]+1, &readfds,NULL,NULL,&tval);			if (i > 0 && FD_ISSET(S_fd_pipe[0], &readfds))			  {			    i = read(S_fd_pipe[0], &sound_num, sizeof(int));			    if (i < sizeof(int)) break;			    i = read(S_fd_pipe[0], &ch, sizeof(int));			    if (i < sizeof(int)) break;			    Chan_assign( &(chan[ch]), &(S_sounds[sound_num]) );						  }			Chan_mixAll(&mix,chan);			write(S_fd_snddev, mix.Vclippedbuf, fragsize );			}		Mix_dealloc( &mix );					close(S_fd_pipe[0]);		close(S_fd_pipe[1]);/* * * Important: call _exit() and not exit() !  Otherwise parent process * files will be closed.  In the case of an X11 based application, the * socket to the X server will be closed!!!! * */		_exit (0);		} /*end of child process */	}/*==========================================================================*/int Snd_restore_dev()	{	close(S_fd_pipe[0]);	close(S_fd_pipe[1]);		/* wait for child process to die*/	waitpid(S_son_pid, 0, 0);	return EXIT_SUCCESS;	}/*==========================================================================*//*   CHANNEL MIXING FUNCTIONS						    *//*==========================================================================*/void Chan_reset( Channel *chan )    {    chan->Vstart=NULL;    chan->Vcurrent=NULL;    chan->Vlen=0;    chan->Vleft=0;    }/*==========================================================================*/void Chan_assign( Channel *chan, const Sample *snd )    {    chan->Vstart  = snd->data;    chan->Vcurrent= chan->Vstart;    chan->Vlen    = snd->len;    chan->Vleft   = snd->len;    } /*==========================================================================*/int Chan_copyIn( Channel *chan, Mix *mix )    {    int    i,*p = mix->Vunclipbuf, result, min;    result = (chan->Vleft>0) ? 1 : 0;    min = (chan->Vleft < mix->Vsize) ? chan->Vleft : mix->Vsize;    for(i=0; i<min; i++)        {        *p++ = (int) *chan->Vcurrent++;        }    chan->Vleft -= i;    /* fill the remaining (if any) part of the mix buffer with silence */    while (i<mix->Vsize)             {             *p++ = 128;             i++;             }    return result;                }/*==========================================================================*/int Chan_mixIn( Channel *chan, Mix *mix )     {    int    i,*p = mix->Vunclipbuf, result, min;    result = (chan->Vleft>0) ? 1 : 0;    min = (chan->Vleft < mix->Vsize) ? chan->Vleft : mix->Vsize;        for(i=0; i<min; i++)        {        *p++ += (int) (*chan->Vcurrent++) - 128;        }    chan->Vleft -= i;    return result;    }/*========================================================================*//* clip an int to a value between 0 and 255 */static inline unsigned char clip(int i)    {    return (i<0) ? 0 : ( (i>255) ? 255 : i );    }    /*==========================================================================*/int Chan_finalMixIn( Channel *chan, Mix *mix )    {    register int    i;    int   *p = mix->Vunclipbuf, result, min;    unsigned char *final = mix->Vclippedbuf;    result = (chan->Vleft>0) ? 1 : 0;    min = (chan->Vleft < mix->Vsize) ? chan->Vleft : mix->Vsize;        for(i=0; i<min; i++)        {        *p += (int) (*chan->Vcurrent++) - 128;        *final++ = clip(*p++);        }    chan->Vleft -= i;    /* copy rest of Vunclipbuf over to Vclippedbuf */    while (i<mix->Vsize)             {            *final++ = clip(*p++);            i++;            }                return result;    }/*==========================================================================*/void Mix_alloc(Mix *mix, int size)    {    mix->Vclippedbuf = (unsigned char *)calloc( sizeof(char), size);    mix->Vunclipbuf = (int *)calloc( sizeof(int), size);    mix->Vsize  = size;        if ((mix->Vclippedbuf==NULL)||(mix->Vunclipbuf==NULL))    	{    	exit(-1);    	}    }/*==========================================================================*/void Mix_dealloc( Mix *mix)    {     if (mix->Vclippedbuf) free(mix->Vclippedbuf);     if (mix->Vunclipbuf) free(mix->Vunclipbuf);     }/*==========================================================================*//* Mixes together the channels into one sound.   Returns # of channels currently playing *any* sound   Therefore, return 0 means to channels have a sample, therefore no   sound is playing*/ int Chan_mixAll( Mix *mix, Channel *chan )    {    int result  = 0,i=0;        result  = Chan_copyIn( chan,  mix);    /* we want to loop for S_num_channels-2 */    for(i=2;i<S_num_channels;i++)    	result += Chan_mixIn( ++chan, mix);    	    result += Chan_finalMixIn( ++chan, mix);        return result;    }/*==========================================================================*//* given the name of a .raw sound file, load it into the Sample struct */ /* pointed to by 'sample'                                              *//* Returns -1 couldn't open/read file				       *//*         -2 couldn't alloc memory)                                   */intSnd_loadRawSample( const char *file, Sample *sample )   {   FILE *fp;   sample->data = NULL;   sample->len  = 0;      fp = fopen(file,"r");         if (fp==NULL) return -1;      /* get length of the file */   sample->len = lseek( fileno(fp), 0, SEEK_END );      /* go back to beginning of file */   lseek( fileno(fp), 0, SEEK_SET );   /* alloc memory for sample */   sample->data = (unsigned char *)malloc( sample->len );      if (sample->data==NULL)   	{   	fclose(fp);   	return -2;   	}      fread( sample->data, 1, sample->len, fp ); 	     fclose(fp);      return 0;   }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区免费在线观看| 国产午夜精品一区二区三区视频 | 欧洲精品中文字幕| 中文无字幕一区二区三区| 国产激情一区二区三区| 久久精品视频免费| 国产一区二区免费视频| 久久久久久久久久美女| 国产麻豆91精品| 国产亚洲欧美日韩在线一区| 国产伦精品一区二区三区视频青涩| 欧美精品在线观看一区二区| 亚洲乱码中文字幕综合| 色哟哟精品一区| 亚洲乱码国产乱码精品精小说 | 亚洲欧美偷拍三级| zzijzzij亚洲日本少妇熟睡| 久久午夜电影网| 懂色av一区二区三区免费看| 中文字幕一区二区三| 91精彩视频在线| 亚洲高清免费在线| 91麻豆精品国产91久久久资源速度| 亚洲18色成人| 精品国产第一区二区三区观看体验| 激情综合色丁香一区二区| 精品日产卡一卡二卡麻豆| 久久99国产精品麻豆| 久久婷婷一区二区三区| 成人在线视频一区| 一区二区激情视频| 日韩一二三区视频| 成人av资源下载| 亚洲无线码一区二区三区| 欧美日韩国产首页在线观看| 另类小说一区二区三区| 国产精品美女久久久久高潮| 成人禁用看黄a在线| 亚洲高清不卡在线| 久久婷婷久久一区二区三区| 91原创在线视频| 蜜臀久久久99精品久久久久久| 久久久久成人黄色影片| 色偷偷成人一区二区三区91 | 欧美国产激情一区二区三区蜜月| www.亚洲色图| 日本中文字幕一区| 国产精品日日摸夜夜摸av| 欧美日韩精品一区视频| 成人综合激情网| 亚洲综合色区另类av| 精品国产伦一区二区三区观看体验 | 一区二区视频在线| 欧美一级欧美三级在线观看| 成人av在线播放网站| 日韩国产精品91| 国产精品成人在线观看| 欧美成人a∨高清免费观看| 91麻豆免费看片| 免费av成人在线| 国产精品婷婷午夜在线观看| 欧美一卡二卡三卡四卡| 91麻豆精东视频| 国产福利一区二区三区| 日日夜夜免费精品视频| 亚洲日本乱码在线观看| 精品国产成人系列| 欧美日韩亚洲另类| 91在线精品一区二区三区| 另类小说视频一区二区| 日韩经典中文字幕一区| 亚洲人精品午夜| 国产精品美女久久久久aⅴ| 精品入口麻豆88视频| 在线观看一区二区视频| 国产成人自拍网| 日韩黄色在线观看| 亚洲综合一区二区三区| 国产精品高潮久久久久无| 国产日韩在线不卡| 欧美v亚洲v综合ⅴ国产v| 宅男噜噜噜66一区二区66| 91成人网在线| 成a人片国产精品| 国产aⅴ综合色| 国产一区在线观看视频| 久久99国产精品久久| 久久不见久久见免费视频7| 美国欧美日韩国产在线播放| 香蕉乱码成人久久天堂爱免费| 亚洲天堂2014| 国产精品国产三级国产aⅴ中文| 中文字幕av一区二区三区高| 国产清纯在线一区二区www| 国产喷白浆一区二区三区| 国产日韩高清在线| 国产精品久久久久永久免费观看| 国产亚洲欧美日韩日本| 欧美精品一区二区三区视频| 日韩精品一区二区三区在线| 欧美电影免费观看高清完整版在线观看| 欧美二区在线观看| 日韩精品在线网站| 国产欧美精品一区| 中文字幕精品一区二区三区精品| 国产精品美女视频| 日韩码欧中文字| 午夜精品一区二区三区免费视频| 天天综合天天综合色| 另类小说图片综合网| 国产精品白丝jk白祙喷水网站 | 久久精品免费在线观看| 久久一夜天堂av一区二区三区| 国产亚洲欧美日韩日本| 欧美国产精品v| 一区二区三区在线免费视频| 日产精品久久久久久久性色| 美女国产一区二区三区| 国产成人免费视频精品含羞草妖精| 成人毛片在线观看| 在线看一区二区| 91精品国产综合久久精品麻豆| 91精品一区二区三区久久久久久| 精品国产一区二区三区不卡| 91精品国产aⅴ一区二区| 欧美二区乱c少妇| 久久久久久夜精品精品免费| 亚洲精品日韩一| 九九国产精品视频| 91美女精品福利| 日韩欧美二区三区| 久久久久久97三级| 一区二区三区中文在线观看| 精品一区二区在线播放| 波多野结衣中文一区| 欧美精品色一区二区三区| 久久久噜噜噜久久人人看| 精品第一国产综合精品aⅴ| 欧美一卡在线观看| 亚洲另类春色校园小说| 国产99精品国产| 日韩一区二区三区三四区视频在线观看 | 欧美日韩久久一区| 日韩久久一区二区| 国产美女一区二区三区| 日韩欧美一区中文| 亚洲国产一区二区在线播放| 97精品国产97久久久久久久久久久久 | 国产成人小视频| 日韩欧美高清一区| 蜜臀精品一区二区三区在线观看| 日本道色综合久久| 国产精品久久久久久久久图文区| 另类小说一区二区三区| 欧美高清一级片在线| 亚洲国产成人精品视频| 色综合久久综合网欧美综合网| 日本一区二区视频在线| 国产高清成人在线| 国产女人aaa级久久久级| 国产成人免费视频网站高清观看视频| 日韩欧美一区二区久久婷婷| 蜜臀精品一区二区三区在线观看| 欧美精品在线一区二区三区| 舔着乳尖日韩一区| 7777精品久久久大香线蕉| 天堂成人免费av电影一区| 欧美日韩第一区日日骚| 日日骚欧美日韩| 日韩欧美亚洲国产另类| 国产资源精品在线观看| 久久婷婷色综合| 成人黄色777网| 亚洲日穴在线视频| 欧美三级电影一区| 免费观看日韩av| 精品女同一区二区| 国产精品中文有码| 国产精品国产三级国产普通话三级| a亚洲天堂av| 亚洲国产美女搞黄色| 欧美一卡二卡三卡| 国产在线精品视频| 国产精品剧情在线亚洲| 欧洲av一区二区嗯嗯嗯啊| 日韩高清欧美激情| 久久久久久久av麻豆果冻| 成人av小说网| 午夜伊人狠狠久久| 日韩精品中文字幕一区| 国产 欧美在线| 艳妇臀荡乳欲伦亚洲一区| 制服丝袜亚洲播放| 国产精品一区久久久久| 国产精品久久久久桃色tv| 在线看不卡av| 国模娜娜一区二区三区| 亚洲人123区| 欧美成va人片在线观看| 91一区二区三区在线观看|