Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
frasalyu
Posts: 2
Registered: ‎10-02-2012
My Device: Playbook , Curve 9300 3G

Questions about audio input

Hello all. I am trying to develop my BB10 (and OS 2.0) app for Blackberry Playbook, but I am having some issues with audio input.

 

The main issue is that I would like to setup a 512 16bit samples buffer and read it every Xms at 48KHz, but when I am trying to set up the PCM mixer like this:

 

// get pcm info
	memset(&pi, 0, sizeof(pi));
	pi.channel = SND_PCM_CHANNEL_CAPTURE;
	if ((rtn = snd_pcm_plugin_info(pcm_handle, &pi)) < 0) {
		fprintf(stderr, "snd_pcm_plugin_info failed: %s\n", snd_strerror(rtn));
		return -1;
	}

	// setup pcm channel
	memset(&pp, 0, sizeof(pp));
	pp.mode = SND_PCM_MODE_BLOCK;
	pp.channel = SND_PCM_CHANNEL_CAPTURE;
	pp.start_mode = SND_PCM_START_DATA; //SND_PCM_START_FULL;
	pp.stop_mode = SND_PCM_STOP_ROLLOVER; //SND_PCM_STOP_STOP;

	pp.buf.block.frag_size = 2048; //bufferSize; // Trying to set it to 512
	


	pp.buf.block.frags_max = 1; //-1; //num_frags;
	pp.buf.block.frags_min = 1;



	pp.format.interleave = 1;
	pp.format.rate = sampleRate;
	pp.format.voices = inChannels;
	pp.format.format = SND_PCM_SFMT_S16_LE; // Signed 16-bit Little Endian

	strcpy(pp.sw_mixer_subchn_name, "Wave capture channel");
	if ((rtn = snd_pcm_plugin_params(pcm_handle, &pp)) < 0) {
		fprintf(stderr, "snd_pcm_plugin_params failed: %s\n",
				snd_strerror(rtn));
		return -1;
	}

	if ((rtn = snd_pcm_plugin_prepare(pcm_handle, SND_PCM_CHANNEL_CAPTURE))
			< 0) {
		fprintf(stderr, "snd_pcm_plugin_prepare failed: %s\n",
				snd_strerror(rtn));
		return -1;
	}

	// Check setup
	memset(&setup, 0, sizeof(setup));
	memset(&group, 0, sizeof(group));
	setup.channel = SND_PCM_CHANNEL_CAPTURE;
	setup.mixer_gid = &group.gid;

	if ((rtn = snd_pcm_plugin_setup(pcm_handle, &setup)) < 0) {
		fprintf(stderr, "snd_pcm_plugin_setup failed: %s\n", snd_strerror(rtn));
		return -1;
	}

	fprintf(stderr, "Format %s \n",
			snd_pcm_get_format_name(setup.format.format));
	fprintf(stderr, "Frag Size %d \n", setup.buf.block.frag_size);
	fprintf(stderr, "Total Frags: %d \n", setup.buf.block.frags);
	fprintf(stderr, "Rate %d \n", setup.format.rate);

	bsize = setup.buf.block.frag_size;

 I get the following output:

 

Audio Example
Requested format: Signed 16-bit Little Endian
Requested sample rate: 48000
Requested buffer size: 512
Requested output channels: 2

Requested input channels: 2

Format Signed 16-bit Little Endian 
Frag Size 1920 
Total Frags: 3 
Rate 48000 
in_buffer size: 3840

 

I do not understand why if I am setting a 2048 frag_size and pp.buf.block.frags_max = 1, I get:

 Frag Size=1920

Total Frags: 3 

 

Is there something I am missing?

 

Thank you

 

New Contributor
frasalyu
Posts: 2
Registered: ‎10-02-2012
My Device: Playbook , Curve 9300 3G

Re: Questions about audio input

Anyone?

Thanks

 

:smileyhappy: