libpynq (release 5EWC0-2023 version 0.2.1 of 2023-09-01 11:02)
Loading...
Searching...
No Matches
Audio library

Macros

#define LINE_IN   0
 
#define MIC   1
 
#define IIC_SLAVE_ADDR   0x3B
 
#define IIC_SCLK_RATE   400000
 
#define I2S_DATA_RX_L_REG   0x00
 
#define I2S_DATA_RX_R_REG   0x04
 
#define I2S_DATA_TX_L_REG   0x08
 
#define I2S_DATA_TX_R_REG   0x0C
 
#define I2S_STATUS_REG   0x10
 

Enumerations

enum  audio_adau1761_regs {
  R0_CLOCK_CONTROL = 0x00 , R1_PLL_CONTROL = 0x02 , R2_DIGITAL_MIC_JACK_DETECTION_CONTROL = 0x08 , R3_RECORD_POWER_MANAGEMENT = 0x09 ,
  R4_RECORD_MIXER_LEFT_CONTROL_0 = 0x0A , R5_RECORD_MIXER_LEFT_CONTROL_1 = 0x0B , R6_RECORD_MIXER_RIGHT_CONTROL_0 = 0x0C , R7_RECORD_MIXER_RIGHT_CONTROL_1 = 0x0D ,
  R8_LEFT_DIFFERENTIAL_INPUT_VOLUME_CONTROL = 0x0E , R9_RIGHT_DIFFERENTIAL_INPUT_VOLUME_CONTROL = 0x0F , R10_RECORD_MICROPHONE_BIAS_CONTROL = 0x10 , R11_ALC_CONTROL_0 = 0x11 ,
  R12_ALC_CONTROL_1 = 0x12 , R13_ALC_CONTROL_2 = 0x13 , R14_ALC_CONTROL_3 = 0x14 , R15_SERIAL_PORT_CONTROL_0 = 0x15 ,
  R16_SERIAL_PORT_CONTROL_1 = 0x16 , R17_CONVERTER_CONTROL_0 = 0x17 , R18_CONVERTER_CONTROL_1 = 0x18 , R19_ADC_CONTROL = 0x19 ,
  R20_LEFT_INPUT_DIGITAL_VOLUME = 0x1A , R21_RIGHT_INPUT_DIGITAL_VOLUME = 0x1B , R22_PLAYBACK_MIXER_LEFT_CONTROL_0 = 0x1C , R23_PLAYBACK_MIXER_LEFT_CONTROL_1 = 0x1D ,
  R24_PLAYBACK_MIXER_RIGHT_CONTROL_0 = 0x1E , R25_PLAYBACK_MIXER_RIGHT_CONTROL_1 = 0x1F , R26_PLAYBACK_LR_MIXER_LEFT_LINE_OUTPUT_CONTROL = 0x20 , R27_PLAYBACK_LR_MIXER_RIGHT_LINE_OUTPUT_CONTROL = 0x21 ,
  R28_PLAYBACK_LR_MIXER_MONO_OUTPUT_CONTROL = 0x22 , R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL = 0x23 , R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL = 0x24 , R31_PLAYBACK_LINE_OUTPUT_LEFT_VOLUME_CONTROL = 0x25 ,
  R32_PLAYBACK_LINE_OUTPUT_RIGHT_VOLUME_CONTROL = 0x26 , R33_PLAYBACK_MONO_OUTPUT_CONTROL = 0x27 , R34_PLAYBACK_POP_CLICK_SUPPRESSION = 0x28 , R35_PLAYBACK_POWER_MANAGEMENT = 0x29 ,
  R36_DAC_CONTROL_0 = 0x2A , R37_DAC_CONTROL_1 = 0x2B , R38_DAC_CONTROL_2 = 0x2C , R39_SERIAL_PORT_PAD_CONTROL = 0x2D ,
  R40_CONTROL_PORT_PAD_CONTROL_0 = 0x2F , R41_CONTROL_PORT_PAD_CONTROL_1 = 0x30 , R42_JACK_DETECT_PIN_CONTROL = 0x31 , R67_DEJITTER_CONTROL = 0x36 ,
  R58_SERIAL_INPUT_ROUTE_CONTROL = 0xF2 , R59_SERIAL_OUTPUT_ROUTE_CONTROL = 0xF3 , R61_DSP_ENABLE = 0xF5 , R62_DSP_RUN = 0xF6 ,
  R63_DSP_SLEW_MODES = 0xF7 , R64_SERIAL_PORT_SAMPLING_RATE = 0xF8 , R65_CLOCK_ENABLE_0 = 0xF9 , R66_CLOCK_ENABLE_1 = 0xFA
}
 

Functions

void audio_init (void)
 
void audio_select_input (int input)
 
void write_audio_reg (unsigned char u8RegAddr, unsigned char u8Data, int iic_fd)
 
void config_audio_pll (void)
 
void config_audio_codec (void)
 
void select_line_in (void)
 
void select_mic (void)
 
void deselect (void)
 
void audio_bypass (unsigned int audio_mmap_size, unsigned int nsamples, unsigned int volume, int uio_index)
 
void audio_record (unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, int uio_index)
 
void audio_play (unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, unsigned int volume, int uio_index)
 
void audio_repeat_play (unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, unsigned int volume, unsigned int repetitions)
 
void audio_generate_tone (unsigned int frequency, uint32_t time_ms, unsigned int volume)
 

Detailed Description

Low-level audio functions.

mic+ph and line_in can be used as audio input and mic+ph as output.

An example of using this library to play audio from line_in to mic+Ph:

#include <libpynq.h>
int main (void)
{
while(1) {
audio_bypass(64*1024, 32*1024, 50, 0);
}
return EXIT_SUCCES;
}
void pynq_init(void)
Initialise the switchbox and GPIO of the PYNQ.
Definition libpynq.c:2
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
Definition libpynq.c:3
void deselect(void)
Function to deselect input, either LINE_IN, or MIC.
Definition audio.c:286
void audio_bypass(unsigned int audio_mmap_size, unsigned int nsamples, unsigned int volume, int uio_index)
Record and play the audio without storing in DRAM.
Definition audio.c:304
void audio_select_input(int input)
selects the audio input channel.
Definition audio.c:77
#define MIC
Definition audio.h:33
void audio_init(void)
Initializes the audio register. Sets the sampling frequency. defines several values such as audio rec...
Definition audio.c:72

Macro Definition Documentation

◆ I2S_DATA_RX_L_REG

#define I2S_DATA_RX_L_REG   0x00

Definition at line 42 of file audio.h.

◆ I2S_DATA_RX_R_REG

#define I2S_DATA_RX_R_REG   0x04

Definition at line 43 of file audio.h.

◆ I2S_DATA_TX_L_REG

#define I2S_DATA_TX_L_REG   0x08

Definition at line 44 of file audio.h.

◆ I2S_DATA_TX_R_REG

#define I2S_DATA_TX_R_REG   0x0C

Definition at line 45 of file audio.h.

◆ I2S_STATUS_REG

#define I2S_STATUS_REG   0x10

Definition at line 46 of file audio.h.

◆ IIC_SCLK_RATE

#define IIC_SCLK_RATE   400000

Definition at line 39 of file audio.h.

◆ IIC_SLAVE_ADDR

#define IIC_SLAVE_ADDR   0x3B

Definition at line 36 of file audio.h.

◆ LINE_IN

#define LINE_IN   0

Definition at line 32 of file audio.h.

◆ MIC

#define MIC   1

Definition at line 33 of file audio.h.

Enumeration Type Documentation

◆ audio_adau1761_regs

Enumerator
R0_CLOCK_CONTROL 
R1_PLL_CONTROL 
R2_DIGITAL_MIC_JACK_DETECTION_CONTROL 
R3_RECORD_POWER_MANAGEMENT 
R4_RECORD_MIXER_LEFT_CONTROL_0 
R5_RECORD_MIXER_LEFT_CONTROL_1 
R6_RECORD_MIXER_RIGHT_CONTROL_0 
R7_RECORD_MIXER_RIGHT_CONTROL_1 
R8_LEFT_DIFFERENTIAL_INPUT_VOLUME_CONTROL 
R9_RIGHT_DIFFERENTIAL_INPUT_VOLUME_CONTROL 
R10_RECORD_MICROPHONE_BIAS_CONTROL 
R11_ALC_CONTROL_0 
R12_ALC_CONTROL_1 
R13_ALC_CONTROL_2 
R14_ALC_CONTROL_3 
R15_SERIAL_PORT_CONTROL_0 
R16_SERIAL_PORT_CONTROL_1 
R17_CONVERTER_CONTROL_0 
R18_CONVERTER_CONTROL_1 
R19_ADC_CONTROL 
R20_LEFT_INPUT_DIGITAL_VOLUME 
R21_RIGHT_INPUT_DIGITAL_VOLUME 
R22_PLAYBACK_MIXER_LEFT_CONTROL_0 
R23_PLAYBACK_MIXER_LEFT_CONTROL_1 
R24_PLAYBACK_MIXER_RIGHT_CONTROL_0 
R25_PLAYBACK_MIXER_RIGHT_CONTROL_1 
R26_PLAYBACK_LR_MIXER_LEFT_LINE_OUTPUT_CONTROL 
R27_PLAYBACK_LR_MIXER_RIGHT_LINE_OUTPUT_CONTROL 
R28_PLAYBACK_LR_MIXER_MONO_OUTPUT_CONTROL 
R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL 
R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL 
R31_PLAYBACK_LINE_OUTPUT_LEFT_VOLUME_CONTROL 
R32_PLAYBACK_LINE_OUTPUT_RIGHT_VOLUME_CONTROL 
R33_PLAYBACK_MONO_OUTPUT_CONTROL 
R34_PLAYBACK_POP_CLICK_SUPPRESSION 
R35_PLAYBACK_POWER_MANAGEMENT 
R36_DAC_CONTROL_0 
R37_DAC_CONTROL_1 
R38_DAC_CONTROL_2 
R39_SERIAL_PORT_PAD_CONTROL 
R40_CONTROL_PORT_PAD_CONTROL_0 
R41_CONTROL_PORT_PAD_CONTROL_1 
R42_JACK_DETECT_PIN_CONTROL 
R67_DEJITTER_CONTROL 
R58_SERIAL_INPUT_ROUTE_CONTROL 
R59_SERIAL_OUTPUT_ROUTE_CONTROL 
R61_DSP_ENABLE 
R62_DSP_RUN 
R63_DSP_SLEW_MODES 
R64_SERIAL_PORT_SAMPLING_RATE 
R65_CLOCK_ENABLE_0 
R66_CLOCK_ENABLE_1 

Definition at line 49 of file audio.h.

Function Documentation

◆ audio_bypass()

void audio_bypass ( unsigned int  audio_mmap_size,
unsigned int  nsamples,
unsigned int  volume,
int  uio_index 
)

Record and play the audio without storing in DRAM.

Parameters
audio_mmap_sizeis the address range of the audio codec.
nsamplesis the number of samples to read and output.
uio_indexis the uio index in /dev list.

Definition at line 304 of file audio.c.

Here is the call graph for this function:

◆ audio_generate_tone()

void audio_generate_tone ( unsigned int  frequency,
uint32_t  time_ms,
unsigned int  volume 
)

Definition at line 570 of file audio.c.

Here is the call graph for this function:

◆ audio_init()

void audio_init ( void  )

Initializes the audio register. Sets the sampling frequency. defines several values such as audio record volume and playback volume. output is always played over mic+ph aux output.

Definition at line 72 of file audio.c.

Here is the call graph for this function:

◆ audio_play()

void audio_play ( unsigned int  audio_mmap_size,
unsigned int *  BufAddr,
unsigned int  nsamples,
unsigned int  volume,
int  uio_index 
)

Definition at line 430 of file audio.c.

Here is the call graph for this function:

◆ audio_record()

void audio_record ( unsigned int  audio_mmap_size,
unsigned int *  BufAddr,
unsigned int  nsamples,
int  uio_index 
)

Function to support audio recording without the audio codec controller.

Notice that the buffer has to be twice the size of the number of samples, because both left and right channels are sampled.

Parameters
audio_mmap_sizeis the address range of the audio codec.
BufAddris the buffer address.
nsamplesis the number of samples.
uio_indexis the uio index in /dev list.

Definition at line 381 of file audio.c.

Here is the call graph for this function:

◆ audio_repeat_play()

void audio_repeat_play ( unsigned int  audio_mmap_size,
unsigned int *  BufAddr,
unsigned int  nsamples,
unsigned int  volume,
unsigned int  repetitions 
)

Function to play one audio fragment for multiple repititions.

Parameters
audio_mmap_sizeis the address range of the audio codec.
BufAddris the buffer address.
nsamplesis the number of samples.
volumeis the volume of the output.
repetitionsis the number of repitions.

Definition at line 502 of file audio.c.

Here is the call graph for this function:

◆ audio_select_input()

void audio_select_input ( int  input)

selects the audio input channel.

Parameters
inputdefines the input. Can be 0 LINE_IN or 1 MIC
Warning
Fails with program exit when input is not valid.

Definition at line 77 of file audio.c.

Here is the call graph for this function:

◆ config_audio_codec()

void config_audio_codec ( void  )

Definition at line 174 of file audio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_audio_pll()

void config_audio_pll ( void  )

Definition at line 102 of file audio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deselect()

void deselect ( void  )

Function to deselect input, either LINE_IN, or MIC.

Definition at line 286 of file audio.c.

Here is the call graph for this function:

◆ select_line_in()

void select_line_in ( void  )

Function to select LINE_IN as input.

Definition at line 234 of file audio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_mic()

void select_mic ( void  )

Function to select MIC as input.

Definition at line 257 of file audio.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_audio_reg()

void write_audio_reg ( unsigned char  u8RegAddr,
unsigned char  u8Data,
int  iic_fd 
)

Definition at line 90 of file audio.c.

Here is the call graph for this function:
Here is the caller graph for this function: