bool wxSoundBackendOSS::Play(wxSoundData *data, unsigned flags,
                             volatile wxSoundPlaybackStatus *status)
{
    int dev = OpenDSP(data);

    if (dev < 0)
        return false;

    ioctl(dev, SNDCTL_DSP_SYNC, 0);

    do
    {
        bool play = true;
        int i;
        unsigned l = 0;
        size_t datasize = data->m_dataBytes;

        do
        {
            if (status->m_stopRequested)
            {
                wxLogTrace(_T("sound"), _T("playback stopped"));
                close(dev);
                return true;
            }

            i= (int)((l + m_DSPblkSize) < datasize ?
                     m_DSPblkSize : (datasize - l));
            if (write(dev, &data->m_data[l], i) != i)
            {
                play = false;
            }
            l += i;
        } while (play && l < datasize);
    } while (flags & wxSOUND_LOOP);

    close(dev);
    return true;
}
Beispiel #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;
}
Beispiel #3
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;
}