pynq.lib.audio Module¶
The pynq.lib.audio module is a driver for reading and recording values from an on-board audio mirophone, loading preexisting audio files, or playing audio input to an output device.
-
class
pynq.lib.audio.
AudioADAU1761
(description)[source]¶ Bases:
pynq.overlay.DefaultIP
Class to interact with audio codec controller.
Each raw audio sample is a 24 bits, padded to 32 bits. The audio controller supports both mono and stereo modes, and I2S format of data.
-
buffer
¶ The numpy array to store the audio.
Type: numpy.ndarray
-
sample_rate
¶ Sample rate of the codec.
Type: int
-
sample_len
¶ Sample length of the current buffer content.
Type: int
-
iic_index
¶ The index of the IIC instance in /dev.
Type: int
-
uio_index
¶ The index of the UIO instance in /dev.
Type: int
-
bindto
= ['xilinx.com:user:audio_codec_ctrl:1.0']¶
-
bypass
(seconds)[source]¶ Stream audio controller input directly to output.
It will run for a certain number of seconds, then stop automatically.
Parameters: seconds (float) – The number of seconds to be recorded. Returns: Return type: None
-
configure
(sample_rate=48000, iic_index=1, uio_name='audio-codec-ctrl')[source]¶ Configure the audio codec.
The sample rate of the codec is 48KHz, by default. This method will configure the PLL and codec registers.
The parameter iic_index is required as input; uio_index is calculated automatically from uio_name.
Users can also explicitly call this function to reconfigure the driver.
Parameters: - sample_rate (int) – Sample rate of the codec.
- iic_index (int) – The index of the IIC instance in /dev.
- uio_name (int) – The name of the UIO configured in the device tree.
-
deselect_inputs
()[source]¶ Deselect the inputs.
This method will disable both LINE_IN and MIC inputs.
-
static
info
(file)[source]¶ Prints information about the sound files.
The information includes name, channels, samples, frames, etc.
Note
The file will be searched in the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of wav. Returns: Return type: None
-
load
(file)[source]¶ Loads file into internal audio buffer.
The recorded file is of format *.wav. Note that we expect 32-bit samples in the buffer while the each saved sample is only 24 bits. Hence we need to pad the highest 8 bits when reading the wave file.
Note
The file will be searched in the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of wav. Returns: Return type: None
-
play
()[source]¶ Play audio buffer via audio jack.
Since both channels are sampled, the buffer size has to be twice the sample length.
Returns: Return type: None
-
record
(seconds)[source]¶ Record data from audio controller to audio buffer.
The sample rate for both channels is 48000Hz. Note that the sample_len will only be changed when the buffer is modified. Since both channels are sampled, the buffer size has to be twice the sample length.
Parameters: seconds (float) – The number of seconds to be recorded. Returns: Return type: None
-
save
(file)[source]¶ Save audio buffer content to a file.
The recorded file is of format *.wav. Note that only 24 bits out of each 32-bit sample are the real samples; the highest 8 bits are padding, which should be removed when writing the wave file.
Note
The saved file will be put into the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of wav. Returns: Return type: None
-
-
class
pynq.lib.audio.
AudioDirect
(description, gpio_name=None)[source]¶ Bases:
pynq.overlay.DefaultIP
Class to interact with audio controller.
Each audio sample is a 32-bit integer. The audio controller supports only mono mode, and uses pulse density modulation (PDM).
-
buffer
¶ The numpy array to store the audio.
Type: numpy.ndarray
-
sample_rate
¶ Sample rate of the current buffer content.
Type: int
-
sample_len
¶ Sample length of the current buffer content.
Type: int
-
bindto
= ['xilinx.com:user:audio_direct:1.1']¶
-
static
info
(file)[source]¶ Prints information about the sound files.
The information includes name, channels, samples, frames, etc.
Note
The file will be searched in the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of pdm. Returns: Return type: None
-
load
(file)[source]¶ Loads file into internal audio buffer.
The recorded file is of format *.pdm.
Note
The file will be searched in the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of pdm. Returns: Return type: None
-
record
(seconds)[source]¶ Record data from audio controller to audio buffer.
The sample rate per word is 192000Hz.
Parameters: seconds (float) – The number of seconds to be recorded. Returns: Return type: None
-
save
(file)[source]¶ Save audio buffer content to a file.
The recorded file is of format *.pdm.
Note
The saved file will be put into the specified path, or in the working directory in case the path does not exist.
Parameters: file (string) – File name, with a default extension of pdm. Returns: Return type: None
-