Sound

Implements an interface to the sound device driver. This will allow you to read and write data to the sound device driver. Typical usage of this module (mono loopback example, no error checking):. More...

Data Structures

struct  Sound_Attrs
 Attributes used to create a Sound device driver instance. More...

Defines

#define Sound_MAXDEVNAME   20
 Max number of characters in the sound device name.

Typedefs

typedef struct Sound_Object * Sound_Handle
 Handle through which to reference a Sound device driver.

Enumerations

enum  Sound_Std {
  Sound_Std_OSS = 0,
  Sound_Std_ALSA,
  Sound_Std_COUNT
}
 Sound standards supported on Linux (OSS and ALSA). More...
enum  Sound_Mode {
  Sound_Mode_OUTPUT,
  Sound_Mode_INPUT,
  Sound_Mode_FULLDUPLEX,
  Sound_Mode_COUNT
}
 Sound device driver opened for reading, writing or both. More...
enum  Sound_Input {
  Sound_Input_MIC,
  Sound_Input_LINE,
  Sound_Input_COUNT
}
 Sound inputs. More...

Functions

Sound_Handle Sound_create (Sound_Attrs *attrs)
 Creates a Sound device driver instance.
Int Sound_write (Sound_Handle hSound, Buffer_Handle hBuf)
 Write a buffer to the sound output. This function can only be called if the driver was opened for writing.
Int Sound_read (Sound_Handle hSound, Buffer_Handle hBuf)
 Fill a buffer from the sound input. This function can only be called if the driver was opened for reading.
Int Sound_delete (Sound_Handle hSound)
 Deletes a Sound device driver instance.

Variables

const Sound_Attrs Sound_Attrs_STEREO_DEFAULT
 Default attributes for a stereo Sound device driver.
const Sound_Attrs Sound_Attrs_MONO_DEFAULT
 Default attributes for a mono Sound device driver.

Detailed Description

Implements an interface to the sound device driver. This will allow you to read and write data to the sound device driver. Typical usage of this module (mono loopback example, no error checking):.

   #include <xdc/std.h>
   #include <ti/sdo/dmai/Dmai.h>
   #include <ti/sdo/dmai/Sound.h>
   #include <ti/sdo/dmai/Buffer.h>
   Buffer_Attrs bAttrs = Buffer_Attrs_DEFAULT;
   Sound_Attrs sAttrs = Sound_Attrs_MONO_DEFAULT;
   Buffer_Handle hBuf;
   Sound_Handle hSound;

   Dmai_init();
   hBuf = Buffer_create(1024, &bAttrs);
   hSound = Sound_create(&sAttrs);
   while (1) {
       Sound_read(hSound, hBuf);
       // Process read data in hBuf.
       Sound_write(hSound, hBuf);
   }
   Sound_delete(hSound);
   Buffer_delete(hBuf);

Define Documentation

#define Sound_MAXDEVNAME   20

Max number of characters in the sound device name.


Typedef Documentation

typedef struct Sound_Object* Sound_Handle

Handle through which to reference a Sound device driver.


Enumeration Type Documentation

enum Sound_Std

Sound standards supported on Linux (OSS and ALSA).

Enumerator:
Sound_Std_OSS  OSS sound standard.
Sound_Std_ALSA  ALSA sound standard.
Sound_Std_COUNT 

enum Sound_Mode

Sound device driver opened for reading, writing or both.

Enumerator:
Sound_Mode_OUTPUT  Output only.
Sound_Mode_INPUT  Output only.
Sound_Mode_FULLDUPLEX  Both input and output (if supported).
Sound_Mode_COUNT 

Sound inputs.

Enumerator:
Sound_Input_MIC  Microphone input.
Sound_Input_LINE  Line in input.
Sound_Input_COUNT 


Function Documentation

Sound_Handle Sound_create ( Sound_Attrs attrs  ) 

Creates a Sound device driver instance.

Parameters:
[in] attrs Sound_Attrs to use for creating the Sound device driver instance.
Return values:
Handle for use in subsequent operations (see Sound_Handle).
NULL for failure.

Int Sound_write ( Sound_Handle  hSound,
Buffer_Handle  hBuf 
)

Write a buffer to the sound output. This function can only be called if the driver was opened for writing.

Parameters:
[in] hSound The Sound_Handle to write to.
[in] hBuf The Buffer_Handle of the buffer to write to the sound device driver.
Return values:
Dmai_EOK for success.
Negative value for failure, see Dmai.h.
Remarks:
Sound_create must be called before this function.

If mono samples are being written, only half of the submitted buffer can be filled with data, as the Sound module will convert the mono samples to stereo before sending them to the device driver and need the extra space.

Int Sound_read ( Sound_Handle  hSound,
Buffer_Handle  hBuf 
)

Fill a buffer from the sound input. This function can only be called if the driver was opened for reading.

Parameters:
[in] hSound The Sound_Handle to read from.
[in] hBuf The Buffer_Handle of the buffer to fill using the sound device driver.
Return values:
Dmai_EOK for success.
Negative value for failure, see Dmai.h.
Remarks:
Sound_create must be called before this function.

If mono samples are being read, only half of the Buffer will be filled with data, use Buffer_getNumBytesUsed to get the actual number.

Int Sound_delete ( Sound_Handle  hSound  ) 

Deletes a Sound device driver instance.

Parameters:
[in] hSound The Sound_Handle to delete.
Return values:
Dmai_EOK for success.
Negative value for failure, see Dmai.h.
Remarks:
Sound_create must be called before this function.


Variable Documentation

Default attributes for a stereo Sound device driver.

    sampleRate        = 44100,
    channels          = 2,
    leftGain          = 100,
    rightGain         = 100,
    mode              = Sound_Mode_FULLDUPLEX,
    soundInput        = Sound_Input_MIC,
    bufSize           = 4096,

Default attributes for a mono Sound device driver.

    sampleRate        = 8000,
    channels          = 1,
    leftGain          = 100,
    rightGain         = 100,
    mode              = Sound_Mode_FULLDUPLEX,
    soundInput        = Sound_Input_MIC,
    bufSize           = 4096,


Copyright 2011, Texas Instruments Incorporated