Exemple #1
0
int pal_pcm_recode_with_cb(get_recode_stream_fn fn)
{
	int ret = 0;
	int snd_read_num = 0;


    LOGI("palapp","pal_pcm_recode_with_cb\n");
	ret = snd_pcm_open(&pal_pcm_cfg, SOUND_CARD_ID_IN, PCM_IN);
	if (ret != 0) {
		LOGE("palapp","pcm open error\n");
		ret = -1;
	}
#ifdef SAVE_TO_SD
    char file_name[64];
	sprintf(file_name,"0:/%d.wav",aos_now());
	int f_sta = f_open(&pcm_fp, file_name, FA_CREATE_NEW | FA_WRITE | FA_READ);
	if(f_sta != FR_OK) {
		LOG("!!!!!fail to open fat!!!!!\n");
		return -1;
	}
#endif	

	int recd_count = READ_CNT;
	unsigned int write_l = 0;
	LOG("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
	LOG("~~~~~~~~~~~~~~~~~~~~~~~~Please say some thing to me~~~~~~~~~~~~~~~~~~~~~~~~~~~");
	draw_text(0,0,1,"Please say some thing to me");
	aos_msleep(500);
	while(recd_count --) {

		snd_read_num = snd_pcm_read(&pal_pcm_cfg, SOUND_CARD_ID_IN, pcm_data_buf, PCM_BUF_SIZE);
		if(snd_read_num == -1) {
			LOG("!!!!!!!!pcm read error!!!!!!!!\n");
			return -1;
		}
#ifdef SAVE_TO_SD

        
#endif
        
		int size=PCM_BUF_SIZE/PCM_BUF_CNT;
		for(int i=0;i<PCM_BUF_CNT;i++){
		    fn(pcm_data_buf+i*size,size);
			//aos_msleep(5);
		}
	}
	draw_text(0,0,1,"In the processing...");
	snd_pcm_close(SOUND_CARD_ID_IN, PCM_IN);
	LOG("recoder end!\n");
#ifdef SAVE_TO_SD
  	f_close(&pcm_fp);
#endif
	return ret;
} 
Exemple #2
0
static void
alsa_poll_ready_sampling (gpointer data,
   			  gint source,
			  GdkInputCondition condition)
{
    alsa_driver * const d = data;
    int size;

    size = (d->stereo + 1) * (d->bits / 8) * d->fragsize;

    size = snd_pcm_read(d->soundfd, d->sndbuf, size);

    sample_editor_sampled(d->sndbuf, d->fragsize, d->playrate, d->mf);
}
Exemple #3
0
int32 ad_read (ad_rec_t *handle, int16 *buf, int32 max)
{
    int32 length;
    static int infoz = 0;

    length = max * handle->bps;		/* #samples -> #bytes */
    length = snd_pcm_read(handle->dspH, buf, length);
    if (length > 0) {
	if (length % 2) {
	    fprintf(stderr, "snd_pcm_read returned an odd number: %d\n", length);
	    abort();
	}
	length /= handle->bps;
    } else if (length < 0) {
	fprintf(stderr, "Audio read error\n");
	return AD_ERR_GEN;
    } else if (!handle->recording)
	return AD_EOF;
#if 0					/* only do this if you're stumped */
    if ((length != 0) && (++infoz < 200))
	fprintf(stderr, "ad_read(0x%08lx,0x%08lx,%d) => %d\n", handle, buf, max,length);
#endif
    return length;
}