LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   out: pcm_params.c:2286: snd_pcm_hw_refine: Assertion `pcm && params' failed. Aborted (https://www.linuxquestions.org/questions/linux-newbie-8/out-pcm_params-c-2286-snd_pcm_hw_refine-assertion-%60pcm-and-and-params-failed-aborted-4175468474/)

HARSHA VARDHAN 07-04-2013 09:10 AM

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);

}

HARSHA VARDHAN 07-04-2013 09:11 AM

plzz any one can help
wat is ASSERTION prob

TB0ne 07-04-2013 01:26 PM

Quote:

Originally Posted by HARSHA VARDHAN (Post 4984171)
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.

HARSHA VARDHAN 07-05-2013 01:05 AM

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

TB0ne 07-05-2013 08:37 AM

Quote:

Originally Posted by HARSHA VARDHAN (Post 4984507)
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.


All times are GMT -5. The time now is 11:51 AM.