Ejemplo n.º 1
0
/**
 * Prepare recording. Initialize and acquire recording resources.
 */
static javacall_result init_recording(recorder_handle* hRecord)
{
    WAVEFORMATEX format;

    /* Setup wave in format */
    format.wFormatTag = WAVE_FORMAT_PCM;
    format.cbSize = 0;
    format.wBitsPerSample = 16;
    format.nSamplesPerSec = 22050;
    format.nChannels = 1;
    format.nAvgBytesPerSec = format.nSamplesPerSec * (format.wBitsPerSample/8);
    format.nBlockAlign = format.nChannels;

    /* Open WAV in H/W */
    if (NULL == hRecord->hWAVEIN) {
        MMRESULT mmReturn = 0;
        
        mmReturn = waveInOpen(&hRecord->hWAVEIN, WAVE_MAPPER, &format, 
            (DWORD)waveInProc, (DWORD)hRecord, CALLBACK_FUNCTION);

        if (MMSYSERR_NOERROR != mmReturn) {
            hRecord->hWAVEIN = NULL;
            return JAVACALL_FAIL;
        }
    }

    /* Create WAV file for (temp) storage */
    if (NULL == hRecord->hFile) {
        HMMIO hFile;

        /* Create temp file? If there is no pre-setted name. */
        if (0x0 == hRecord->fileName[0]) {
            GetTempPath(MAX_PATH, hRecord->fileName);
            GetTempFileName(hRecord->fileName, "record", 0, hRecord->fileName);
        }

        if (JAVACALL_SUCCEEDED(create_wav_file(hRecord->fileName, &format, &hFile))) {
            hRecord->hFile = hFile;
        } else {
            waveInClose(hRecord->hWAVEIN);
            hRecord->hWAVEIN = NULL;
            return JAVACALL_FAIL;
        }
    }

    /* Add input buffer */
    if (!JAVACALL_SUCCEEDED(add_input_buffer(hRecord, &format))) {
        waveInClose(hRecord->hWAVEIN);
        close_wav_file(hRecord);
        hRecord->hWAVEIN = NULL;
        return JAVACALL_FAIL;
    }

    return JAVACALL_OK;
}
Ejemplo n.º 2
0
static void winsnd_read_preprocess(MSFilter *f){
	WinSnd *d=(WinSnd*)f->data;
	MMRESULT mr;
	int i;
	int bsize;
	DWORD dwFlag;

	d->stat_input=0;
	d->stat_output=0;
	d->stat_notplayed=0;
	d->stat_minimumbuffer=WINSND_MINIMUMBUFFER;

	winsnd_apply_settings(d);
	/* Init Microphone device */
  dwFlag = CALLBACK_FUNCTION | WAVE_FORMAT_DIRECT;
  mr = waveInOpen (&d->indev, d->dev_id, &d->wfx,
              (DWORD) read_callback, (DWORD)f, dwFlag);
	if (mr != MMSYSERR_NOERROR)
	{
    ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
    if (d->dev_id != WAVE_MAPPER)
		    dwFlag = WAVE_MAPPED | CALLBACK_FUNCTION;
    mr = waveInOpen (&d->indev, d->dev_id, &d->wfx,
              (DWORD) read_callback, (DWORD)f, dwFlag);
  }
	if (mr != MMSYSERR_NOERROR)
	{
    ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
		mr = waveInOpen (&d->indev, WAVE_MAPPER, &d->wfx,
					(DWORD) read_callback, (DWORD)f, CALLBACK_FUNCTION);
		if (mr != MMSYSERR_NOERROR)
		{
			d->indev=NULL;
			ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
		    return ;
		}
	}
	bsize=WINSND_NSAMPLES*d->wfx.nAvgBytesPerSec/8000;
	ms_debug("Using input buffers of %i bytes",bsize);
	for(i=0;i<WINSND_NBUFS;++i){
		WAVEHDR *hdr=&d->hdrs_read[i];
		add_input_buffer(d,hdr,bsize);
	}
	d->running=TRUE;
	mr=waveInStart(d->indev);
	if (mr != MMSYSERR_NOERROR){
		ms_error("waveInStart() error");
		return ;
	}
#ifndef _TRUE_TIME
	ms_ticker_set_time_func(f->ticker,winsnd_get_cur_time,d);
#endif
}
Ejemplo n.º 3
0
static void winsnd_read_process(MSFilter *f){
	WinSnd *d=(WinSnd*)f->data;
	mblk_t *m;
	int i;
	ms_mutex_lock(&d->mutex);
	while((m=getq(&d->rq))!=NULL){
		ms_queue_put(f->outputs[0],m);
	}
	ms_mutex_unlock(&d->mutex);
	for(i=0;i<WINSND_NBUFS;++i){
		WAVEHDR *hdr=&d->hdrs_read[i];
		if (hdr->dwUser==0) {
			MMRESULT mr;
			mr=waveInUnprepareHeader(d->indev,hdr,sizeof(*hdr));
			if (mr!=MMSYSERR_NOERROR)
				ms_warning("winsnd_read_process: Fail to unprepare header!");
			add_input_buffer(d,hdr,hdr->dwBufferLength);
		}
	}
}