Exemplo n.º 1
0
Arquivo: wavplay.c Projeto: 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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/*
 * Open /dev/dsp for reading or writing:
 */
DSPFILE *OpenDSP(WAVFILE *wfile,int omode)
{
	int t;					/* Work int */
	unsigned long ul;			/* Work unsigned long */
	DSPFILE *dfile;

	if(g_dfile) CloseDSP(g_dfile);

	dfile = (DSPFILE *) mem_malloc(sizeof (DSPFILE));
	if ( dfile == NULL ) 
	{
		printf("Opening DSP device\n");
		return NULL;
	}

	memset(dfile,0,sizeof *dfile);
	dfile->dspbuf = NULL;
	dfile->fd=-1;

	dfile->dspblksiz = 8*1024;
 
        /*
         * Check the range on the buffer sizes:
         */
        /* Minimum was 4096 but es1370 returns 1024 for 44.1kHz, 16 bit */
        /* and 64 for 8130Hz, 8 bit */
        if ( dfile->dspblksiz < 32 || dfile->dspblksiz > 65536 )
	{
                printf("Audio block size (%d bytes)", (int)dfile->dspblksiz);
                goto errxit;
        }
 
        /*
         * Allocate a buffer to do the I/O through:
         */
        if ( (dfile->dspbuf = (char *) mem_malloc(dfile->dspblksiz)) == NULL )
	{
                printf("For DSP I/O buffer\n");
                goto errxit;
        }

	/* Reset the I2S codec */
	 pcm_ioctl(PCM_RESET, 0);	

	/*
	 * Set the data bit size:
	 */
	t = wfile->wavinfo.DataBits;
	if (t==8)
		pcm_ioctl(PCM_SET_FORMAT, 8);
	else
		pcm_ioctl(PCM_SET_FORMAT,  16);
	/*
	 * Set the mode to be Stereo or Mono:
	 */
	t = wfile->wavinfo.Channels == Stereo ? 2 : 1;
	pcm_ioctl(PCM_SET_CHANNEL, t);
      
	/*
	 * Set the sampling rate:
	 */
	ul = wfile->wavinfo.SamplingRate;
	pcm_ioctl(PCM_SET_SAMPLE_RATE,ul);

	/*
	 * Return successfully opened device:
	 */
	return dfile;				/* Return file descriptor */

	/*
	 * Failed to open/initialize properly:
	 */
errxit:	
	if ( dfile->fd >= 0 )
		close(dfile->fd);		/* Close device */
	if ( dfile->dspbuf != NULL )
		mem_free(dfile->dspbuf);
	mem_free(dfile);
	return NULL;				/* Return error indication */
}