libpynq  (release 5EID0-2023 version 0.3.0 of 2024-04-25 09:42 )
audio.h
Go to the documentation of this file.
1 #ifndef AUDIO_H
2 #define AUDIO_H
3 #include <stdint.h>
4 
32 #define LINE_IN 0
33 #define MIC 1
34 
35 // Slave address for the ADAU audio controller 8
36 #define IIC_SLAVE_ADDR 0x3b
37 
38 // I2C Serial Clock frequency in Hertz
39 #define IIC_SCLK_RATE 400000
40 
41 // I2S Register
42 #define I2S_DATA_RX_L_REG 0x00
43 #define I2S_DATA_RX_R_REG 0x04
44 #define I2S_DATA_TX_L_REG 0x08
45 #define I2S_DATA_TX_R_REG 0x0C
46 #define I2S_STATUS_REG 0x10
47 
48 // Audio registers
97  R62_DSP_RUN = 0xF6,
102 };
103 
109 extern void audio_init(void);
110 
116 extern void audio_select_input(int input);
117 
118 // Original ADAU1761 code
119 
120 extern void write_audio_reg(unsigned char u8RegAddr, unsigned char u8Data,
121  int iic_fd);
122 
123 extern void config_audio_pll(void);
124 
125 extern void config_audio_codec(void);
126 
130 extern void select_line_in(void);
131 
135 extern void select_mic(void);
136 
140 extern void deselect(void);
141 
149 extern void audio_bypass(unsigned int audio_mmap_size, unsigned int nsamples,
150  unsigned int volume, int uio_index);
151 
164 extern void audio_record(unsigned int audio_mmap_size, unsigned int *BufAddr,
165  unsigned int nsamples, int uio_index);
166 
167 /*
168  * @brief Function to support audio playing without the audio codec controller.
169  *
170  * Notice that the buffer has to be twice the size of the number of samples,
171  * because both left and right channels are sampled.
172  * Consecutive indexes are played synchronisly on left and right output.
173  *
174  * @param audio_mmap_size is the address range of the audio codec.
175  * @param BufAddr is the buffer address.
176  * @param nsamples is the number of samples.
177  * @param uio_index is the uio index in /dev list.
178  * @param volume is the volume of the output.
179  */
180 extern void audio_play(unsigned int audio_mmap_size, unsigned int *BufAddr,
181  unsigned int nsamples, unsigned int volume,
182  int uio_index);
183 
193 extern void audio_repeat_play(unsigned int audio_mmap_size,
194  unsigned int *BufAddr, unsigned int nsamples,
195  unsigned int volume, unsigned int repetitions);
196 
197 /*
198  * @brief Function to generate a specific tone on the audio output.
199  * @param frequency is the frequency in Hz to be played.
200  * @param time_ms is the time the frequency should be played in ms.
201  * @param volume is the volume of the output.
202  */
203 extern void audio_generate_tone(unsigned int frequency, uint32_t time_ms,
204  unsigned int volume);
205 
206 int32_t *audio_record_response(unsigned int frequency, uint32_t nperiods, unsigned
207 int volume, uint32_t *nsamples);
208 
209 void audio_record_response_start(void);
214 #endif
R26_PLAYBACK_LR_MIXER_LEFT_LINE_OUTPUT_CONTROL
@ R26_PLAYBACK_LR_MIXER_LEFT_LINE_OUTPUT_CONTROL
Definition: audio.h:76
audio_select_input
void audio_select_input(int input)
selects the audio input channel.
Definition: audio.c:77
audio_adau1761_regs
audio_adau1761_regs
Definition: audio.h:49
R3_RECORD_POWER_MANAGEMENT
@ R3_RECORD_POWER_MANAGEMENT
Definition: audio.h:53
R40_CONTROL_PORT_PAD_CONTROL_0
@ R40_CONTROL_PORT_PAD_CONTROL_0
Definition: audio.h:90
R9_RIGHT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
@ R9_RIGHT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
Definition: audio.h:59
R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL
@ R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL
Definition: audio.h:80
R27_PLAYBACK_LR_MIXER_RIGHT_LINE_OUTPUT_CONTROL
@ R27_PLAYBACK_LR_MIXER_RIGHT_LINE_OUTPUT_CONTROL
Definition: audio.h:77
R8_LEFT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
@ R8_LEFT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
Definition: audio.h:58
R22_PLAYBACK_MIXER_LEFT_CONTROL_0
@ R22_PLAYBACK_MIXER_LEFT_CONTROL_0
Definition: audio.h:72
R0_CLOCK_CONTROL
@ R0_CLOCK_CONTROL
Definition: audio.h:50
R4_RECORD_MIXER_LEFT_CONTROL_0
@ R4_RECORD_MIXER_LEFT_CONTROL_0
Definition: audio.h:54
audio_record_response_start
void audio_record_response_start(void)
Definition: audio.c:703
R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL
@ R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL
Definition: audio.h:79
R21_RIGHT_INPUT_DIGITAL_VOLUME
@ R21_RIGHT_INPUT_DIGITAL_VOLUME
Definition: audio.h:71
R66_CLOCK_ENABLE_1
@ R66_CLOCK_ENABLE_1
Definition: audio.h:101
R36_DAC_CONTROL_0
@ R36_DAC_CONTROL_0
Definition: audio.h:86
R42_JACK_DETECT_PIN_CONTROL
@ R42_JACK_DETECT_PIN_CONTROL
Definition: audio.h:92
R37_DAC_CONTROL_1
@ R37_DAC_CONTROL_1
Definition: audio.h:87
R23_PLAYBACK_MIXER_LEFT_CONTROL_1
@ R23_PLAYBACK_MIXER_LEFT_CONTROL_1
Definition: audio.h:73
R39_SERIAL_PORT_PAD_CONTROL
@ R39_SERIAL_PORT_PAD_CONTROL
Definition: audio.h:89
R58_SERIAL_INPUT_ROUTE_CONTROL
@ R58_SERIAL_INPUT_ROUTE_CONTROL
Definition: audio.h:94
R61_DSP_ENABLE
@ R61_DSP_ENABLE
Definition: audio.h:96
R19_ADC_CONTROL
@ R19_ADC_CONTROL
Definition: audio.h:69
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.
Definition: audio.c:419
R33_PLAYBACK_MONO_OUTPUT_CONTROL
@ R33_PLAYBACK_MONO_OUTPUT_CONTROL
Definition: audio.h:83
R65_CLOCK_ENABLE_0
@ R65_CLOCK_ENABLE_0
Definition: audio.h:100
R20_LEFT_INPUT_DIGITAL_VOLUME
@ R20_LEFT_INPUT_DIGITAL_VOLUME
Definition: audio.h:70
R41_CONTROL_PORT_PAD_CONTROL_1
@ R41_CONTROL_PORT_PAD_CONTROL_1
Definition: audio.h:91
write_audio_reg
void write_audio_reg(unsigned char u8RegAddr, unsigned char u8Data, int iic_fd)
Definition: audio.c:90
config_audio_pll
void config_audio_pll(void)
Definition: audio.c:118
config_audio_codec
void config_audio_codec(void)
Definition: audio.c:208
R63_DSP_SLEW_MODES
@ R63_DSP_SLEW_MODES
Definition: audio.h:98
audio_generate_tone
void audio_generate_tone(unsigned int frequency, uint32_t time_ms, unsigned int volume)
Definition: audio.c:608
R38_DAC_CONTROL_2
@ R38_DAC_CONTROL_2
Definition: audio.h:88
R6_RECORD_MIXER_RIGHT_CONTROL_0
@ R6_RECORD_MIXER_RIGHT_CONTROL_0
Definition: audio.h:56
R14_ALC_CONTROL_3
@ R14_ALC_CONTROL_3
Definition: audio.h:64
R32_PLAYBACK_LINE_OUTPUT_RIGHT_VOLUME_CONTROL
@ R32_PLAYBACK_LINE_OUTPUT_RIGHT_VOLUME_CONTROL
Definition: audio.h:82
R18_CONVERTER_CONTROL_1
@ R18_CONVERTER_CONTROL_1
Definition: audio.h:68
R13_ALC_CONTROL_2
@ R13_ALC_CONTROL_2
Definition: audio.h:63
select_line_in
void select_line_in(void)
Function to select LINE_IN as input.
Definition: audio.c:268
R12_ALC_CONTROL_1
@ R12_ALC_CONTROL_1
Definition: audio.h:62
audio_init
void audio_init(void)
Initializes the audio register. Sets the sampling frequency. defines several values such as audio rec...
Definition: audio.c:72
R10_RECORD_MICROPHONE_BIAS_CONTROL
@ R10_RECORD_MICROPHONE_BIAS_CONTROL
Definition: audio.h:60
R28_PLAYBACK_LR_MIXER_MONO_OUTPUT_CONTROL
@ R28_PLAYBACK_LR_MIXER_MONO_OUTPUT_CONTROL
Definition: audio.h:78
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.
Definition: audio.c:338
R2_DIGITAL_MIC_JACK_DETECTION_CONTROL
@ R2_DIGITAL_MIC_JACK_DETECTION_CONTROL
Definition: audio.h:52
R17_CONVERTER_CONTROL_0
@ R17_CONVERTER_CONTROL_0
Definition: audio.h:67
R7_RECORD_MIXER_RIGHT_CONTROL_1
@ R7_RECORD_MIXER_RIGHT_CONTROL_1
Definition: audio.h:57
audio_play
void audio_play(unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, unsigned int volume, int uio_index)
Definition: audio.c:468
R5_RECORD_MIXER_LEFT_CONTROL_1
@ R5_RECORD_MIXER_LEFT_CONTROL_1
Definition: audio.h:55
audio_record_response
int32_t * audio_record_response(unsigned int frequency, uint32_t nperiods, unsigned int volume, uint32_t *nsamples)
Definition: audio.c:743
R67_DEJITTER_CONTROL
@ R67_DEJITTER_CONTROL
Definition: audio.h:93
deselect
void deselect(void)
Function to deselect input, either LINE_IN, or MIC.
Definition: audio.c:320
R11_ALC_CONTROL_0
@ R11_ALC_CONTROL_0
Definition: audio.h:61
R59_SERIAL_OUTPUT_ROUTE_CONTROL
@ R59_SERIAL_OUTPUT_ROUTE_CONTROL
Definition: audio.h:95
R34_PLAYBACK_POP_CLICK_SUPPRESSION
@ R34_PLAYBACK_POP_CLICK_SUPPRESSION
Definition: audio.h:84
R16_SERIAL_PORT_CONTROL_1
@ R16_SERIAL_PORT_CONTROL_1
Definition: audio.h:66
R25_PLAYBACK_MIXER_RIGHT_CONTROL_1
@ R25_PLAYBACK_MIXER_RIGHT_CONTROL_1
Definition: audio.h:75
select_mic
void select_mic(void)
Function to select MIC as input.
Definition: audio.c:291
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.
Definition: audio.c:540
R35_PLAYBACK_POWER_MANAGEMENT
@ R35_PLAYBACK_POWER_MANAGEMENT
Definition: audio.h:85
R31_PLAYBACK_LINE_OUTPUT_LEFT_VOLUME_CONTROL
@ R31_PLAYBACK_LINE_OUTPUT_LEFT_VOLUME_CONTROL
Definition: audio.h:81
R1_PLL_CONTROL
@ R1_PLL_CONTROL
Definition: audio.h:51
R62_DSP_RUN
@ R62_DSP_RUN
Definition: audio.h:97
R24_PLAYBACK_MIXER_RIGHT_CONTROL_0
@ R24_PLAYBACK_MIXER_RIGHT_CONTROL_0
Definition: audio.h:74
R15_SERIAL_PORT_CONTROL_0
@ R15_SERIAL_PORT_CONTROL_0
Definition: audio.h:65
R64_SERIAL_PORT_SAMPLING_RATE
@ R64_SERIAL_PORT_SAMPLING_RATE
Definition: audio.h:99