This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5728: Number of channels in ALSA application

Other Parts Discussed in Thread: AM5728

Hi, sir:

    I am using mcasp of am5728. Now I want to change the default channels number which equals to 2. 

    int channels = params_channels(params);       //   here I printk the value of channels,  this code is in davinci-mcasp.c

    I truely believed that when I use alsa framework, I only need to call the function snd_pcm_set_params to set the channels.

    But when I  do so , I still get the same value of 2 like before. Would you please tell me why? Thanks a lot!

   My pragram is as below:

/*
 *  This extra small demo sends a random samples to your speakers.
 */
#include <alsa/asoundlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include <math.h>
static char *device = "default";                        /* playback device */
snd_output_t *output = NULL;
unsigned char buffer[1*1024];                          /* some random data */
//unsigned short int buffer[1*1024];                          /* some random data */
int main(void)
{
        int err;
        unsigned int i;
        snd_pcm_t *handle;
		//snd_pcm_hw_params_t *hwparams;
        snd_pcm_sframes_t frames;
		//int channels = 4;
		printf("size of buffer is %d\n", sizeof(buffer));
        for (i = 0; i < sizeof(buffer); i++)
                //buffer[i] = random() & 0xff;
                //buffer[i] = 0xff;
                buffer[i] = i;
        if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
                printf("Playback open error: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }

		//snd_pcm_hw_params_alloca(&hwparams);
		//snd_pcm_hw_params_set_channels(handle, hwparams, channels);

        if ((err = snd_pcm_set_params(handle,
                                      //SND_PCM_FORMAT_U8,
                                      SND_PCM_FORMAT_U16,
                                      SND_PCM_ACCESS_RW_INTERLEAVED,
                                      16,	// channels
                                      48000,
                                      1,
                                      500000)) < 0) {   /* 0.5sec */
                printf("Playback open error: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }
        //for (i = 0; i < 16; i++) {
		//while(1){
        //        frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
		//		//printf("frames = %d\n", frames);
        //        if (frames < 0)
        //                frames = snd_pcm_recover(handle, frames, 0);
        //        if (frames < 0) {
        //                printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
        //                break;
        //        }
        //        if (frames > 0 && frames < (long)sizeof(buffer))
        //                printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
		//		//snd_pcm_drain(handle);
        //}
        snd_pcm_close(handle);
        return 0;
}