LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2013, 09:10 AM   #1
HARSHA VARDHAN
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
Question out: pcm_params.c:2286: snd_pcm_hw_refine: Assertion `pcm && params' failed. Aborted


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<pthread.h>
#include <alsa/asoundlib.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#include "wavethread.h"

void *threading_process1(void*);
void threading_process2(void * );
//void *threading_process3(void *);

#define SAMPS_PER_TICK (1u)

FILE *inFile;
RIFF_HEADER header;
int g_start_Audio = 0;
snd_pcm_t *device;
pthread_t id1;






//int configure_alsa_audio(const char *which,snd_pcm_t *device)

void audio_init_configure(void)
{
int err;
/* Open PCM device for playback. */
if ((err = snd_pcm_open(&playback_handle, snd_device_out, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{
fprintf(stderr, "cannot open output audio device %s: %s\n", snd_device_out, snd_strerror(err));
exit(1);
}

// configure_alsa_audio("Playback",playback_handle);
pthread_create(&id1,NULL,&threading_process1,NULL);
pthread_join(id1,NULL);
}


int main (int argc , char *argv[])
{
//, id3

int inframes, outframes,temp=1;
int count;
int chan;
rd_ping_pong = 0;
wr_ping_pong = 0;



/*Validate the command line parameters*/
if(argc<2)
{
printf("usage of player is ./waveplaer wavefile\n"
"Example./waveplayer test.wav\n");
return;
}

/* Open the input file for playing*/
inFile = fopen(argv[1],"rb");

if(inFile == NULL)
{
printf("\n Unable to open input file. \n");
}

//Read the RIFF HEADER DATA
count = fread(&header,44,1,inFile);


audio_init_configure();


while (1)
{



inframes = fread((short *)rdbuf, 4, SAMPS_PER_TICK, inFile);
if(inframes==SAMPS_PER_TICK)
g_start_Audio = 1;
else
g_start_Audio = 0;


/* ----------------------------------------------------------------------
** Determine the number of input and output channels that the current
** audio layout has
** ------------------------------------------------------------------- */
if (g_start_Audio)
{
while ((outframes = snd_pcm_writei(playback_handle, rdbuf, inframes)) < 0)
{
if (outframes == -EAGAIN)
continue;
snd_pcm_prepare(playback_handle);
}


}
else
{
break;
}

}
return 0;
}







void *threading_process1(void* nothing )
{

snd_pcm_hw_params_t *hw_params;
int err,size=SAMPS_PER_TICK;
unsigned int tmp;
snd_pcm_uframes_t frames;
int frame_size;
int sample_rate = header.samplerate;
buffer_size = 8 *size;
snd_pcm_t *device;

/* allocate memory for hardware parameter structure */
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)
{
fprintf (stderr, "cannot allocate parameter structure (%s)\n", snd_strerror(err));
return 0;
}

/* fill structure from current audio parameters */
if ((err = snd_pcm_hw_params_any(device, hw_params)) < 0)
{
fprintf (stderr, "cannot initialize parameter structure (%s)\n", snd_strerror(err));
return 0;
}
/* set access type, sample rate, sample format, channels */
if ((err = snd_pcm_hw_params_set_access(device, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{
fprintf (stderr, "cannot set access type: %s\n", snd_strerror(err));
return 0;
}
if ((err = snd_pcm_hw_params_set_format(device, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
{
fprintf (stderr, "cannot set sample format: %s\n",snd_strerror(err));
return 0;
}
tmp = sample_rate;
if ((err = snd_pcm_hw_params_set_rate_near(device, hw_params, &tmp, 0)) < 0)
{
fprintf (stderr, "cannot set sample rate: %s\n",snd_strerror(err));
return 0;
}
if (tmp != sample_rate)
{
fprintf(stderr, "Could not set requested sample rate, asked for %d got %d\n", sample_rate, tmp);
sample_rate = tmp;
}
if ((err = snd_pcm_hw_params_set_channels(device, hw_params, header.no_channels)) < 0)
{
fprintf (stderr, "cannot set channel count: %s\n",snd_strerror(err));
return 0;
}

frames = buffer_size;
if ((err = snd_pcm_hw_params_set_buffer_size_near(device, hw_params, &frames)) < 0)
{
fprintf(stderr, "Error setting buffer_size %lu frames: %s\n", frames, snd_strerror(err));
return 0;
}

if (buffer_size != frames)
{
fprintf(stderr, "Could not set requested buffer size, asked for %d got %lu\n",buffer_size,frames);
buffer_size = frames * frame_size / fragments;
}

if ((err = snd_pcm_hw_params(device, hw_params)) < 0)
{
fprintf(stderr, "Error setting HW params: %s\n",snd_strerror(err));
return 0;
}
snd_pcm_hw_params_free (hw_params);

}
 
Old 07-04-2013, 09:11 AM   #2
HARSHA VARDHAN
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
plzz any one can help
wat is ASSERTION prob
 
Old 07-04-2013, 01:26 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,685

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by HARSHA VARDHAN View Post
plzz any one can help
wat is ASSERTION prob
Spell out your words, and do NOT bump your own thread; this is a forum of VOLUNTEERS...we help when we can/if we can/if we want to; doing that is fairly rude. You posted a follow-up begging for help after ONE MINUTE???

You didn't post ANY useful details about your problem (like version/distro of Linux, where you got the code, what you're typing in to generate that error, etc.), so don't be surprised when people can't help you. Post details.
 
Old 07-05-2013, 01:05 AM   #4
HARSHA VARDHAN
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Question out2: pcm_params.c:2286: snd_pcm_hw_refine: Assertion `pc && params'

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<pthread.h>
#include <alsa/asoundlib.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#include "wavethread.h"

void *threading_process1( void *nting);


#define SAMPS_PER_TICK (256u)

FILE *inFile;
RIFF_HEADER header;
int g_start_Audio = 0;
snd_pcm_t *device;
pthread_t id1;

void audio_init_configure(void)
{
int err;
/* Open PCM device for playback. */
if ((err = snd_pcm_open(&playback_handle, snd_device_out, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{
fprintf(stderr, "cannot open output audio device %s: %s\n", snd_device_out, snd_strerror(err));
exit(1);
}


pthread_create(&id1,NULL,&threading_process1,NULL);
pthread_join(id1,NULL);
}


int main (int argc , char *argv[])
{


int inframes, outframes,temp=1;
int count;
int chan;
rd_ping_pong = 0;
wr_ping_pong = 0;



/*Validate the command line parameters*/
if(argc<2)
{
printf("usage of player is ./waveplaer wavefile\n"
"Example./waveplayer test.wav\n");
return;
}

/* Open the input file for playing*/
inFile = fopen(argv[1],"rb");

if(inFile == NULL)
{
printf("\n Unable to open input file. \n");
}

//Read the RIFF HEADER DATA
count = fread(&header,44,1,inFile);


audio_init_configure();


while (1)
{



inframes = fread((short *)rdbuf, 4, SAMPS_PER_TICK, inFile);
if(inframes==SAMPS_PER_TICK)
g_start_Audio = 1;
else
g_start_Audio = 0;


/* ----------------------------------------------------------------------
** Determine the number of input and output channels that the current
** audio layout has
** ------------------------------------------------------------------- */
if (g_start_Audio)
{
while ((outframes = snd_pcm_writei(playback_handle, rdbuf, inframes)) < 0)
{
if (outframes == -EAGAIN)
continue;
snd_pcm_prepare(playback_handle);
}


}
else
{
break;
}

}
return 0;

}

void *threading_process1(void *nothing )
{

snd_pcm_hw_params_t *hw_params;
int err,size=SAMPS_PER_TICK;
unsigned int tmp;
snd_pcm_uframes_t frames;
int frame_size;
int sample_rate = header.samplerate;
buffer_size = 8 *size;
snd_pcm_t *device;

/* allocate memory for hardware parameter structure */
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)
{
fprintf (stderr, "cannot allocate parameter structure (%s)\n", snd_strerror(err));
return 0;
}

/* fill structure from current audio parameters */
if ((err = snd_pcm_hw_params_any(device, hw_params)) < 0)
{
fprintf (stderr, "cannot initialize parameter structure (%s)\n", snd_strerror(err));
return 0;
}
/* set access type, sample rate, sample format, channels */
if ((err = snd_pcm_hw_params_set_access(device, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{
fprintf (stderr, "cannot set access type: %s\n", snd_strerror(err));
return 0;
}
if ((err = snd_pcm_hw_params_set_format(device, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
{
fprintf (stderr, "cannot set sample format: %s\n",snd_strerror(err));
return 0;
}
tmp = sample_rate;
if ((err = snd_pcm_hw_params_set_rate_near(device, hw_params, &tmp, 0)) < 0)
{
fprintf (stderr, "cannot set sample rate: %s\n",snd_strerror(err));
return 0;
}
if (tmp != sample_rate)
{
fprintf(stderr, "Could not set requested sample rate, asked for %d got %d\n", sample_rate, tmp);
sample_rate = tmp;
}
if ((err = snd_pcm_hw_params_set_channels(device, hw_params, header.no_channels)) < 0)
{
fprintf (stderr, "cannot set channel count: %s\n",snd_strerror(err));
return 0;
}

frames = buffer_size;
if ((err = snd_pcm_hw_params_set_buffer_size_near(device, hw_params, &frames)) < 0)
{
fprintf(stderr, "Error setting buffer_size %lu frames: %s\n", frames, snd_strerror(err));
return 0;
}

if (buffer_size != frames)
{
fprintf(stderr, "Could not set requested buffer size, asked for %d got %lu\n",buffer_size,frames);
buffer_size = frames * frame_size / fragments;
}

if ((err = snd_pcm_hw_params(device, hw_params)) < 0)
{
fprintf(stderr, "Error setting HW params: %s\n",snd_strerror(err));
return 0;
}
snd_pcm_hw_params_free (hw_params);

}




am using :
Linux panda-desktop 3.2.0-1412-omap4 #16-Ubuntu SMP PREEMPT Tue Apr 17 19:38:42 UTC 2012 armv7l armv7l armv7l GNU/Linux

compiler doesnt througing errore
but when execute:
./out2 YedutaNilichindhiChoodu_16000.wav
ASSERTION:'pcm && params'
its not playing wave file.
my_program is to play wavefile using threads
 
Old 07-05-2013, 08:37 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,685

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by HARSHA VARDHAN View Post
am using :
Linux panda-desktop 3.2.0-1412-omap4 #16-Ubuntu SMP PREEMPT Tue Apr 17 19:38:42 UTC 2012 armv7l armv7l armv7l GNU/Linux

compiler doesnt througing errore
Do you mean the program compiles without error? What kind of machine are you running this on, and what version of Ubuntu are you using?
Quote:
but when execute:
./out2 YedutaNilichindhiChoodu_16000.wav
ASSERTION:'pcm && params'
its not playing wave file. my_program is to play wavefile using threads
First, are you sure the wav file you're trying to play isn't corrupted? Can you play it with another player, and are you sure your sound hardware/speakers are working correctly? There are thread/sound related bugs on the Ubuntu forums, too:
https://bugs.launchpad.net/ubuntu/+s...io/+bug/932096

..but you still haven't said what version of Ubuntu, what kind of hardware, desktop GUI, etc., so we don't know if you're using pulseaudio or ALSA.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ALSA API - snd_pcm_open: Assertion `pcmp && name' failed. grlongo Programming 3 07-07-2014 06:00 AM
openldap assertion error -- ldap_parse_result: Assertion `r != ((void *)0)' failed nottings Linux - Server 1 02-19-2009 12:20 AM
Japanese canna won't work : Warning: &#12363;&#12394;&#28450;&#23383;&#22793;&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Ph&#7909;c h&#7891;i d&#7919; li&#7879;u b&#7883; m&#7845;t???, c&#7913; pollsite General 1 06-27-2005 12:39 PM
Assertion `pcm->access == SND_PCM_ACCESS_RW_INTERLEAVED' failed vasudevadas Programming 5 07-15-2004 05:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration