The classic Multimedia sound management seems to not work properly
under 32 bits OS... (Win95 and NT 4)

Try this replacement, or better, pick up the sound management
of DirectX modules (Direct sound) (see dirx_256.c or dirx_64k.c)

For example ds_wing.c is wing.c with direct sound sound management.

G_LAMONOCA@msn.com

(Globals)
          
static long randstamp;
#define MASKSAMPLE 0xff
#define MASKRANDOM 0x000fffffL
#define MAXSAMPLE (MASKSAMPLE+1)
static long splfrq[MAXSAMPLE]={0};
static long spllen[MAXSAMPLE]={0};

(static void killsystem2(void))
{       
...
         
	int i;
	char filename[80];
	char command[80];
                                                    
	
	for(i=0;i<MAXSAMPLE;i++)
	if (splfrq[i])
	{	                                                             
		sprintf(command,"stop sound_%02x",i);
		mciSendString(command,NULL,NULL,NULL);
		sprintf(command,"close sound_%02x",i);
		mciSendString(command,NULL,NULL,NULL);
		sprintf(filename,"c:\\%05x_%02x.wav",randstamp,i);
		unlink(filename);
	}
...
}                                          



(static void initwindow(void))
{
	randstamp=(GetTickCount()+randint())&MASKRANDOM;
...
}

/*******************************************************************/
/* gestion des samples */
                                          

struct sWaveDataChunk
{
	char					data[4];
	long					WaveDataChunkSize;
};

struct sFormatChunk
{
	char 					fmt[4];
	long					FormatChunkSize;
	short    				wFormatTag;
	short					nChannels;
	long					nSamplesPerSec;
	long					nAvgBytesPerSec;
	short					nBlockAlign;
	short					FormatSpecific;
};                          

struct sDataChunk
{
	char 					WAVE[4];
	struct 	sFormatChunk	FormatChunk;
	struct 	sWaveDataChunk	WaveDataChunk;
};

struct sRIFF
{
	char 					RIFF[4];
	long 					DataChunkSize;
	struct 	sDataChunk		DataChunk;	
};

                                       

                                      
void msgboxint(int n,char *t)
{
	char s[250];
	sprintf(s,"%d",n);
	MessageBox(GetFocus(),s,t,0);
}                
                           
void msgboxhex(int n,char *t)
{
	char s[250];
	sprintf(s,"0x%04x",n);
	MessageBox(GetFocus(),s,t,0);
}                                       

void msgboxstr(char *s,char *t)
{
	MessageBox(GetFocus(),s,t,0);
}
    
void mes(DWORD code, char *t)
{       
	int ret;
	char s[250];
	if (!code) return;
	ret=mciGetErrorString(code,s,250);
	if (ret!=TRUE) sprintf(s,"Erreur inconnue #%ld",code);
	MessageBox(GetFocus(),s,t,0);
}


void playsample(void *adr,long len,long freq)
{                      
	struct sRIFF st;
	char filename[80];
	char command[80];
	int fd;
	int n;
	
	n=(int)*((char *)adr);
	if ((n>=0)&&(n<MAXSAMPLE))
	{
		if ((freq!=splfrq[n])||(len!=spllen[n]))
		{        
		
	        sprintf(command,"stop sound_%02x",n);
    		mes(mciSendString(command,NULL,NULL,NULL),"fixsample");  
	        sprintf(command,"close sound_%02x",n);
    		mes(mciSendString(command,NULL,NULL,NULL),"fixsample");
	    		
			sprintf(filename,"c:\\%05x_%02x.wav",randstamp,n);
			fd=bcreate(filename);
			if (fd) 
			{                                    
				                                   
	    		                   
				strncpy(st.RIFF,"RIFF",4);
				st.DataChunkSize=sizeof(struct sDataChunk)+len;
				strncpy(st.DataChunk.WAVE,"WAVE",4);              
				strncpy(st.DataChunk.FormatChunk.fmt,"fmt ",4);
				st.DataChunk.FormatChunk.FormatChunkSize=sizeof(struct sFormatChunk)-8;
				st.DataChunk.FormatChunk.wFormatTag=1;
				st.DataChunk.FormatChunk.nChannels=1;
				st.DataChunk.FormatChunk.nSamplesPerSec=freq;
				st.DataChunk.FormatChunk.nAvgBytesPerSec=freq;
				st.DataChunk.FormatChunk.nBlockAlign=1;
				st.DataChunk.FormatChunk.FormatSpecific=8;
				strncpy(st.DataChunk.WaveDataChunk.data,"data",4);
				st.DataChunk.WaveDataChunk.WaveDataChunkSize=len;
		                            
				*((char *)adr)=-128; 
				
				bwrite(fd,&st,sizeof(struct sRIFF));
				bwrite(fd,adr,len);
				bclose(fd);
			                           
				*((char *)adr)=n;
			                    
				splfrq[n]=freq; 
				spllen[n]=len;               
				                                                              
				sprintf(command,"open %s type waveaudio alias sound_%02x",filename,n);
	  			mes(mciSendString(command,NULL,NULL,NULL),"fixsample");
				sprintf(command,"cue sound_%02x",n);
	    		mes(mciSendString(command,NULL,NULL,NULL),"fixsample");                                               
			}
		}                      
		                                                               
		sprintf(command,"seek sound_%02x to start",n);
		mes(mciSendString(command,NULL,NULL,NULL),"playsample");
		sprintf(command,"play sound_%02x",n);
		mes(mciSendString(command,NULL,NULL,NULL),"playsample");
	}
                     
                                                                     
}



void stopsample()
{
	char command[80];
	int i;
	
	for(i=0;i<MAXSAMPLE;i++)
	if (splfrq[i])
	{	
		sprintf(command,"stop sound_%02x",i);
		mes(mciSendString(command,NULL,NULL,NULL),"stopsample");
	}
}
                           
                           
                           
void fixsample(void *adr,long len)
{                                          
	char command[80];
	char filename[80];
	struct sRIFF st;
	int fd;
    int i;  
                                           
           
	i=0;
	while ((splfrq[i]) && (i<MAXSAMPLE)) i++;
	if (i<MAXSAMPLE)
	{
		sprintf(filename,"c:\\%05x_%02x.wav",randstamp,i);
		fd=bcreate(filename);
		if (fd) 
		{                                    
			                   
			strncpy(st.RIFF,"RIFF",4);
			st.DataChunkSize=sizeof(struct sDataChunk)+len;
			strncpy(st.DataChunk.WAVE,"WAVE",4);              
			strncpy(st.DataChunk.FormatChunk.fmt,"fmt ",4);
			st.DataChunk.FormatChunk.FormatChunkSize=sizeof(struct sFormatChunk)-8;
			st.DataChunk.FormatChunk.wFormatTag=1;
			st.DataChunk.FormatChunk.nChannels=1;
			st.DataChunk.FormatChunk.nSamplesPerSec=11025;
			st.DataChunk.FormatChunk.nAvgBytesPerSec=11025;
			st.DataChunk.FormatChunk.nBlockAlign=1;
			st.DataChunk.FormatChunk.FormatSpecific=8;
			strncpy(st.DataChunk.WaveDataChunk.data,"data",4);
			st.DataChunk.WaveDataChunk.WaveDataChunkSize=len;
	
			bwrite(fd,&st,sizeof(struct sRIFF));
			bwrite(fd,adr,len);
			bclose(fd);
		                                
			splfrq[i]=11025L;           
			spllen[i]=len;            
			
			*((char *)adr)=i;
                         
			sprintf(command,"open %s type waveaudio alias sound_%02x",filename,i);
  			mes(mciSendString(command,NULL,NULL,NULL),"fixsample");
			sprintf(command,"cue sound_%02x",i);
    		mes(mciSendString(command,NULL,NULL,NULL),"fixsample");
		}
	}
	            
}


#else

