Hello,
mmm... can be strange endianess problems? I say strange because you set the format as AFMT_S16_LE (LE means little endian) but... just now I have see that the ioctl can return ok but the format can be different from what you have choosen. You have to check the format variable!
I have see this at this page:
http://manuals.opensound.com/developer/SNDCTL_DSP_SETFMT.html
This is the description:

   Description

This ioctl call selects the sample format to be used with this stream. Please see the Supported audio formats <http://manuals.opensound.com/developer/formats.html> section for more info about the different audio formats. *The application should check the argument value after the call. It contains the sample format that will be actually be used.* If the application cannot support this format it should give an error message and ask the user to select some other sample format. Using wrong sample format is a major error since it may result in very high volume noise that may cause hearing damage. Please see the description of Return information about an audio device <http://manuals.opensound.com/developer/SNDCTL_AUDIOINFO.html> for more information about the possible parameters.

and


   OSS ioctl return values

The return value from the OSS ioctl calls will be -1 if a fatal error occurred. *Other values mean that the ioctl call was more or less successful.* However in most cases *the application must check the value returned in the argument* to see what was the accepted value.

See you
   Emanuele Ghidoli

Ramachandran M ha scritto:
Hi,
i am getting some problem with OSS driver.
I create two files.
1.loopback.c It read the pcm sample and play the sample and write in to a file as pcm samples.

2.fileread.c
    It reads the pcm samples file which is written by loopback.c

Issues:

1.if i run the loopback.c and fileread.c in a DAVINCI Board ,It is running perfectly. 2.if i run the loopback.c and fileread.c in a x386 Machine(Fedora core 5), ,It is running perfectly.
But
3.if i run the loopback.c in DAVINCI and fileread.c in x386 Machine(Fedora core 5),it is not working properly. 4.if i run the loopback.c in x386 Machine(Fedora core 5),and fileread.c in DAVINCI ,it is not working properly. what might be the reson.?

I have attached the code.
Please give me some solution.

Regards,

Ram
------------------------------------------------------------------------


/*
 * speech.c
 *
 * ============================================================================
 * Copyright (c) Texas Instruments Inc 2005
 *
 * Use of this software is controlled by the terms and conditions found in the
 * license agreement under which this software has been supplied or provided.
 * ============================================================================
 */

/* 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


/* G.711 encoded samples */
#define NUMSAMPLES             640

/* The size of the read buffer */

#define READBUFSIZE NUMSAMPLES*2


#if 0
monoTostereo(inBuf,outBuf,inBufSize,outBufSize)
{int i, * bytesProcessed=0;

for (i = (inBufSize - 1); i >= 0; i--) {
        outBuf[4 * i]     = outBuf[2 * i];
        outBuf[4 * i + 1] = outBuf[2 * i + 1];
        outBuf[4 * i + 2] = outBuf[2 * i];
        outBuf[4 * i + 3] = outBuf[2 * i + 1];
    }

    if (inBufSize < NUMSAMPLES) {
        *bytesProcessed = inBufSize;
        *outBufSize = inBufSize * 4;
    }
    else {
        *bytesProcessed = NUMSAMPLES;
        *outBufSize = NUMSAMPLES * 4;
    }
}
#endif
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;
    unsigned short readBuffer[3072],rawBuffer[3072];


    /* 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; 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_LINE) == 0) {
        if ((recMask & SOUND_MASK_MIC) == 0) {
            printf("Line input not a supported recorder.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_READ_RECSRC, &recMask) == -1) {
            printf("Failed to read the current recorder.\n");
            return FAILURE;
        }

        //recMask |= SOUND_MASK_LINE;
        recMask |= SOUND_MASK_MIC;

        if (ioctl(mixerFd, SOUND_MIXER_WRITE_RECSRC, &recMask) == -1) {
            printf("Failed to set line input as recorder.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_READ_RECSRC, &recMask) == -1) {
            printf("Failed to read the current recorder.\n");
            return FAILURE;
        }

        //if ((recMask & SOUND_MASK_LINE) == 0) {
        if ((recMask & SOUND_MASK_MIC) == 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_RDONLY, 00444);

    if (outputFd == -1) {
        printf("Failed to open file for writing\n");
        exit(0);
    }
        while(1)
        {
                
                
                
       if (read(outputFd, readBuffer, READBUFSIZE) == -1) {
            printf("Error reading the encoded \n");
                close(outputFd);
            exit(0);
        }
        //monoTostereo(readBuffer,rawBuffer,READBUFSIZE,RAWBUFSIZE);
        write(soundFd, readBuffer, READBUFSIZE);
        }       
close(outputFd);
        close(soundFd);

    return 0;
}
------------------------------------------------------------------------

/*
 * speech.c
 *
 * ============================================================================
 * Copyright (c) Texas Instruments Inc 2005
 *
 * Use of this software is controlled by the terms and conditions found in the
 * license agreement under which this software has been supplied or provided.
 * ============================================================================
 */

/* 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; 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_LINE) == 0) {
        if ((recMask & SOUND_MASK_MIC) == 0) {
            printf("Line input not a supported recorder.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_READ_RECSRC, &recMask) == -1) {
            printf("Failed to read the current recorder.\n");
            return FAILURE;
        }

        //recMask |= SOUND_MASK_LINE;
        recMask |= SOUND_MASK_MIC;

        if (ioctl(mixerFd, SOUND_MIXER_WRITE_RECSRC, &recMask) == -1) {
            printf("Failed to set line input as recorder.\n");
            return FAILURE;
        }

        if (ioctl(mixerFd, SOUND_MIXER_READ_RECSRC, &recMask) == -1) {
            printf("Failed to read the current recorder.\n");
            return FAILURE;
        }

        //if ((recMask & SOUND_MASK_LINE) == 0) {
        if ((recMask & SOUND_MASK_MIC) == 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;
}
------------------------------------------------------------------------

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

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

Reply via email to