Luth Haroon / SD_modified
Embed: (wiki syntax)

« Back to documentation index

USBAudio Class Reference

USBAudio Class Reference

USBAudio example. More...

#include <USBAudio.h>

Inherits USBDevice.

Public Member Functions

 USBAudio (uint32_t frequency=48000, uint8_t channel_nb=1, uint16_t vendor_id=0x7bb8, uint16_t product_id=0x1111, uint16_t product_release=0x0100)
 Constructor.
float getVolume ()
 Get current volume between 0.0 and 1.0.
bool read (uint8_t *buf)
 Read an audio packet.
bool readNB (uint8_t *buf)
 Try to read an audio packet.
void attach (void(*fptr)(void))
 attach a handler to update the volume
template<typename T >
void attach (T *tptr, void(T::*mptr)(void))
 Attach a nonstatic void/void member function to update the volume.

Detailed Description

USBAudio example.

include "mbed.h" include "USBAudio.h"

Serial pc(USBTX, USBRX);

// frequency: 48 kHz define FREQ 48000

// 1 channel: mono define NB_CHA 1

// length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there is one channel, the length will be 48 * 2 * 1 define AUDIO_LENGTH_PACKET 48 * 2 * 1

// USBAudio USBAudio audio(FREQ, NB_CHA);

int main() { int16_t buf[AUDIO_LENGTH_PACKET/2];

while (1) { // read an audio packet audio.read((uint8_t *)buf);

// print packet received pc.printf("recv: "); for(int i = 0; i < AUDIO_LENGTH_PACKET/2; i++) { pc.printf("%d ", buf[i]); } pc.printf("\r\n"); } }

Definition at line 68 of file USBAudio.h.


Constructor & Destructor Documentation

USBAudio ( uint32_t  frequency = 48000,
uint8_t  channel_nb = 1,
uint16_t  vendor_id = 0x7bb8,
uint16_t  product_id = 0x1111,
uint16_t  product_release = 0x0100 
)

Constructor.

Parameters:
frequencyfrequency in Hz (default: 48000)
channel_nbchannel number (1 or 2) (default: 1)
vendor_idYour vendor_id
product_idYour product_id
product_releaseYour preoduct_release

Definition at line 26 of file USBAudio.cpp.


Member Function Documentation

void attach ( void(*)(void)  fptr )

attach a handler to update the volume

Parameters:
functionFunction to attach

Definition at line 113 of file USBAudio.h.

void attach ( T *  tptr,
void(T::*)(void)  mptr 
)

Attach a nonstatic void/void member function to update the volume.

Parameters:
tptrObject pointer
mptrMember function pointer

Definition at line 124 of file USBAudio.h.

float getVolume (  )

Get current volume between 0.0 and 1.0.

Returns:
volume

Definition at line 74 of file USBAudio.cpp.

bool read ( uint8_t *  buf )

Read an audio packet.

warning: blocking

Parameters:
bufpointer on a buffer which will be filled with an audio packet
Returns:
true if successfull

Definition at line 52 of file USBAudio.cpp.

bool readNB ( uint8_t *  buf )

Try to read an audio packet.

warning: non blocking

Parameters:
bufpointer on a buffer which will be filled if an audio packet is available
Returns:
true if successfull

Definition at line 60 of file USBAudio.cpp.