Hi Steve,
as i said my audio codec supports to select more then one recording source at a 
time. so i download one application and did some
changes to capture from both the surface at the same time by orring with both 
LINEIN and MIC.
But i got the below error

Failed to ask mixer for available recorders -- 1.
: Invalid argument

but recording from individual sources working fine. So what is the right way to 
select both the recording source at the same time. Below is the code
that i executed.
   /* Standard Linux headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include <getopt.h>
#include <pthread.h>
#include <errno.h>

#include <linux/soundcard.h>

#define FAILURE                 -1
/* The number of channels of the audio codec */
#define NUM_CHANNELS           1

/* The sample rate of the audio codec */
#define SAMPLE_RATE            8000

/* The gain (0-100) of the left and right channels */
#define LEFT_GAIN              100
#define RIGHT_GAIN             100

/* Number of samples to process */
#define NUMSAMPLES             320

/* Mono 16 bit */
#define RAWBUFSIZE             NUMSAMPLES * 2

/* Stereo 16 bit */
#define INPUTBUFSIZE           NUMSAMPLES * 2

unsigned short rawbuf[RAWBUFSIZE],inputbuf[INPUTBUFSIZE];

int main()
{
    int     vol         = LEFT_GAIN | (RIGHT_GAIN << 8);
    int     channels    = NUM_CHANNELS;
    int     sampleRate  = SAMPLE_RATE;
        int format = AFMT_S16_LE;
    int     soundFd;
    int     mixerFd;
    int     recMask;

    /* Open the sound device for writing */
    if ((soundFd = open("/dev/dsp", O_RDWR)) == -1) {
        printf("Failed to open the sound device (/dev/dsp)\n");
        return FAILURE;
    }

    /* Set the sound format (only AFMT_S16_LE supported) */
    if (ioctl(soundFd, SNDCTL_DSP_SETFMT, &format) == -1) {
        printf("Could not set format %d\n", format);
        return FAILURE;
    }

    /* Set the number of channels */
    if (ioctl(soundFd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
        printf("Could not set mixer to %d channels\n", channels);
        return FAILURE;
    }

    /* Set the sample rate */
    if (ioctl(soundFd, SNDCTL_DSP_SPEED, &sampleRate) == -1) {
        printf("Could not set sample rate (%d)\n", sampleRate);
        return FAILURE;
    }

    /* If we are sampling select the right capture device and volume */
    if ((mixerFd = open("/dev/mixer", O_RDONLY)) == -1) {
            printf("Failed to open /dev/mixer\n");
            return FAILURE;
   }

        recMask |= SOUND_MASK_MIC;
    recMask |= SOUND_MASK_LINE;
        if (ioctl(mixerFd, SOUND_MIXER_WRITE_RECSRC, &recMask) == -1) {
            perror("Failed to ask mixer for available recorders -- 1.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_READ_RECMASK, &recMask) == -1) {
            printf("Failed to ask mixer for available recorders -- 2.\n");
            return FAILURE;
        }

        if ((recMask & SOUND_MASK_MIC) == 0) {
            printf("Line input not a supported recorder.\n");
            return FAILURE;
        }
    if ((recMask & SOUND_MASK_LINE) == 0) {
                    printf("Failed to read the current recorder.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_WRITE_IGAIN, &vol) == -1) {
            printf("Failed to set the volume of line in.\n");
            return FAILURE;
        }

        close(mixerFd);

    printf("Audio sample rate set to %dHz\n", SAMPLE_RATE);
int outputFd = open("audio",O_WRONLY | O_CREAT | O_TRUNC, 00644);
int i=0,numBytes;
    if (outputFd == -1) {
        printf("Failed to open file for writing\n");
        exit(0);
    }
        while(i++<500)
        {
                numBytes=read(soundFd, inputbuf, INPUTBUFSIZE);
                if(numBytes==-1)
                {
                        printf("error\n");
                        exit(0);
                        close(outputFd);

                }
                else{
                        printf("numBytes=%d\n",numBytes);
                }
                usleep(10);
                write(soundFd, inputbuf, INPUTBUFSIZE);
        //stereoToMono(inputbuf, rawbuf, NUMSAMPLES);
       if (write(outputFd, inputbuf, INPUTBUFSIZE) == -1) {
            printf("Error writing the encoded \n");
                close(outputFd);
            exit(0);
        }
        }
close(outputFd);
        close(soundFd);

    return 0;
}




Steve Chen wrote:

On Mon, 2009-03-09 at 19:42 +0530, Prabhu Kalyan Rout wrote:


Actually i wanted to record from both MIC and LINE IN at the same
time. From the



It would be difficult to record separate audio streams on mic and
line-in since both goes to the same ADC.




below code i found that my codec does supports that
 status = ioctl(fd, SOUND_MIXER_READ_CAPS, &caps);
 if (status == -1)
   perror("SOUND_MIXER_READ_CAPS ioctl failed");

if (!(caps & SOUND_CAP_EXCL_INPUT))

Thanks

Viral Sachde wrote:


On Mon, Mar 9, 2009 at 3:38 PM, Prabhu Kalyan Rout
<[email protected]><mailto:[email protected]> wrote:



Hi,
My requirement is to capture from both LINE IN and MIC. But current OSS
functionality does not allow us to do that
Can any body tell me how to achieve this functionality using OSS as the
driver?
Thanks




Do you mean, you wish two separate analog input support, one inserted
in Line-in, another in Mic ?





______________________________________________________________________
http://www.mindtree.com/email/disclaimer.html
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]<mailto:[email protected]>
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source






________________________________
http://www.mindtree.com/email/disclaimer.html
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to