Beispiel #1
0
BOOL CPlayer::WavOpenFile(LPCTSTR pszFile)
{
	if (!m_Reader.Open(pszFile))
		return FALSE;

	_tcscpy(m_szFile, pszFile);
	if (!WavScanFile()) {
		WavClose();
		return FALSE;
	}

	m_fOpen = OPEN_WAV_FILE;
	return TRUE;
}
Beispiel #2
0
void CPlayer::Close()
{
	CAutoLock lock(&m_csecInterface);
	Stop();
	
	PlugInClose();
	MpgClose();
	OvClose();
	WavClose();
	NetClose();

	memset(&m_Info, 0, sizeof(m_Info));
	m_szFile[0] = NULL;
	m_nDuration = 0;

	m_fOpen = OPEN_NONE;
	m_StreamingStatus = MAP_STREAMING_DISABLED;
}
Beispiel #3
0
/*
 * Play a series of WAV files:
 */
int wavplay(char *pathname)
{

#if 0
	const char *Pathname;			/* Pathname of the open WAV file */

	if ( (Pathname = *argv) == NULL )
		Pathname = "-";			/* Standard input */
	else	
		Pathname = *(++argv);		/* Point to first pathname on command line */
#endif

//	printf("wavplay Pathname:\t%s\n",pathname);
	/*
	 * Play each Pathname:
	 */
	//do
	//{
		/*
		 * Open the wav file for read, unless its stdin:
		 */
		if ( (g_wfile = WavOpenForRead(pathname)) == NULL )
			goto errxit;


//		printf("after wavopenforread\n");
		/*
		 * Report the file details, unless in quiet mode:
		 */
		//printf("Device:\t\t%s\n",env_AUDIODEV);
//		printf("Sampling Rate:\t%lu Hz\n",(unsigned long)g_wfile->wavinfo.SamplingRate);
//		printf("Mode:\t\t%s\n",g_wfile->wavinfo.Channels == Mono ? "Mono" : "Stereo");
//		printf("Samples:\t%lu\n",(unsigned long)g_wfile->wavinfo.Samples);
//		printf("Bits:\t\t%u\n\n",(unsigned)g_wfile->wavinfo.DataBits);

		/*
		 * If not -i mode, play the file:
		 */
		if ( (g_dfile = OpenDSP(g_wfile,O_RDWR)) == NULL )
			goto errxit;
//		printf("after opendsp\n");

		if ( PlayDSP(g_dfile,g_wfile) )
			goto errxit;
//		printf("after playdsp*****\n");

                if ( CloseDSP(g_dfile) ) 
		{  /* Close /dev/dsp */
                        g_dfile = NULL;           /* Mark it as closed */
                       goto errxit;
                }
//		printf("after close dsp\n");
                g_dfile = NULL;   

                /* Mark it as closed */
                if ( WavClose(g_wfile) )          /* Close the wav file */
                        g_wfile = NULL; 	  /* Mark the file as closed */
                g_wfile = NULL;                   /* Mark the file as closed */
//		printf("after end playwav\n");

	//} while ( (Pathname = *++argv) != NULL );

	return 0;

	/*
	 * Error exit:
	 */
errxit:	
//	printf("error exit playwav\n");
	if ( g_wfile != NULL )
		WavClose(g_wfile);
//	printf("error wavclose\n");
	if ( g_dfile != NULL )
		CloseDSP(g_dfile);
//	printf("error CloseDSP\n");
	return -1;
}
Beispiel #4
0
Datei: wavplay.c Projekt: rd8/qGo
int wavplay(char *argv,ErrFunc erf) {

  WavPlayOpts wavopts;
	WAVFILE *wfile;				/* Opened wav file */
	DSPFILE *dfile = NULL;			/* Opened /dev/dsp device */
	const char *Pathname;			/* Pathname of the open WAV file */
	int e;					/* Saved error code */

  memset(&wavopts,0,sizeof wavopts);	/* Zero this structure */
	wavopts.IPCKey = 0;		/* Default IPC Key for lock */
/*/	wavopts.Mode = getOprMode(argv[0],&cmd_name,&clntIPC);*/
	wavopts.Channels.optChar = 0;
	wavopts.ipc = -1;			/* Semaphore ipc ID */
	wavopts.DataBits.optValue = 16;		/* Default to 16 bits */
	wavopts.Channels.optValue = Stereo;
	wavopts.SamplingRate.optValue = 8000;

  
	if ( erf != NULL )			/* If called from external module.. */
		v_erf = erf;			/* ..set error reporting function */


  Pathname = argv;
    /*
    fprintf(stdout,"Playing WAV file %s \n",Pathname);
    fprintf(stdout, "AUDIODEV : %s : \n",AUDIODEV);
    fprintf(stdout, "WAVPLAYPATH : %s : \n",WAVPLAYPATH);
    fprintf(stdout, "WAVPLAYPATH : % : \n", AUDIOLCK);
     */

		/*
		 * Open the wav file for read, unless its stdin:
		 */
		if ( (wfile = WavOpenForRead(Pathname,v_erf)) == NULL )
			goto errxit;


		/*
		 * Merge in command line option overrides:
		 */
 
		WavReadOverrides(wfile,&wavopts);



  		if ( !wavopts.bInfoMode ) {
			/*
			 * If not -i mode, play the file:
			 */
			if ( (dfile = OpenDSP(wfile,O_WRONLY,v_erf)) == NULL )
				goto errxit;

       
			if ( PlayDSP(dfile,wfile,NULL,v_erf) )
				goto errxit;

			if ( CloseDSP(dfile,v_erf) ) {	/* Close /dev/dsp */
				dfile = NULL;		/* Mark it as closed */
				goto errxit;
			}
     
		}

		dfile = NULL;				/* Mark it as closed */
		if ( WavClose(wfile,v_erf) )		/* Close the wav file */
			wfile = NULL;			/* Mark the file as closed */
		wfile = NULL;				/* Mark the file as closed */



	return 0;

	/*
	 * Error exit:
	 */
errxit:	e = errno;					/* Save errno value */

  fprintf(stdout, "error %s : \n",sys_errlist[errno]);
	if ( wfile != NULL )
		WavClose(wfile,NULL);			/* Don't report errors here */
	if ( dfile != NULL )
		CloseDSP(dfile,NULL);			/* Don't report errors here */
	errno = e;					/* Restore error code */
	return -1;
}
Beispiel #5
0
/*
 * Open a WAV file for reading: returns (WAVFILE *)
 *
 * The opened file is positioned at the first byte of WAV file data, or
 * NULL is returned if the open is unsuccessful.
 */
WAVFILE *WavOpenForRead(const char *Pathname) 
{
	WAVFILE *wfile;
	UInt32 offset;				/* File offset */
	Byte ubuf[4];				/* 4 byte buffer */
	UInt32 dbytes;				/* Data byte count */
						/* wavfile.c values : */
	int channels;				/* Channels recorded in this wav file */
	u_long samplerate;			/* Sampling rate */
	int sample_bits;			/* data bit size (8/12/16) */
	u_long samples;				/* The number of samples in this file */
	u_long datastart;			/* The offset to the wav data */

	if(g_wfile) WavClose(g_wfile); 

	wfile = wavfile_alloc(Pathname);

	if ( wfile == NULL )
		return NULL;			/* Insufficient memory (class B msg) */

	/*
	 * Open the file for reading:
	 */
//	printf("Opening WAV file %p\n", wfile->Pathname);
	if ( (wfile->fd = sound_open(wfile->Pathname,O_RDONLY)) < 0 ) 
	{
		printf("Opening WAV file %p failed\n", wfile->Pathname);
		goto errxit;
	}

	if ( sound_lseek(wfile->fd,0,SEEK_SET) != 0 ) 
	{
		printf("Rewinding WAV file %p\n",wfile->Pathname);
		goto errxit;		/* Wav file must be seekable device */
	}

	if ( WaveReadHeader(wfile->fd,&channels,&samplerate,&sample_bits,&samples,&datastart) != 0 ) 
	{
		printf("Reading WAV header from %p", wfile->Pathname);
		goto errxit;
	}

	/*
	 * Copy WAV data over to WAVFILE struct:
	 */
	if ( channels == 2 )
		wfile->wavinfo.Channels = Stereo;
	else	wfile->wavinfo.Channels = Mono;

	wfile->wavinfo.SamplingRate = (UInt32) samplerate;
	wfile->wavinfo.Samples = (UInt32) samples;
	wfile->wavinfo.DataBits = (UInt16) sample_bits;
	wfile->wavinfo.DataStart = (UInt32) datastart;
        wfile->num_samples = wfile->wavinfo.Samples;

	offset = wfile->wavinfo.DataStart - 4;

	/*
	 * Seek to byte count and read dbytes:
	 */
	if ( sound_lseek(wfile->fd,offset,SEEK_SET) != offset ) 
	{
		printf("Seeking to WAV data in %p",wfile->Pathname);
		goto errxit;			/* Seek failure */
	}

	if ( sound_read(wfile->fd,ubuf,4) != 4 ) 
	{
		printf("Reading dbytes from %s",wfile->Pathname);
		goto errxit;
	}

	/*
	 * Put little endian value into 32 bit value:
	 */
	dbytes = ubuf[3];
	dbytes = (dbytes << 8) | ubuf[2];
	dbytes = (dbytes << 8) | ubuf[1];
	dbytes = (dbytes << 8) | ubuf[0];

	wfile->wavinfo.DataBytes = dbytes;

	/*
	 * Open succeeded:
	 */
	return wfile;				/* Return open descriptor */

	/*
	 * Return error after failed open:
	  WavClose*/
errxit:	
	mem_free(wfile);				/* Dispose of WAVFILE struct */
	return NULL;				/* Return error indication */
}