i2s - Digital Audio#
Adapted Air780E/Air700E Air780EP/Air780EPV Air601 Air101/Air103
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Tip
This library has its own demo,click this link to view the demo example of i2s
Example
-- This library belongs to the underlying adaptation library, please refer to the example for specific usage.
-- demo/multimedia
-- demo/tts
-- demo/record
Constant#
constant |
type |
explanation |
---|---|---|
i2s.MODE_I2S |
number |
I2S Standards, such ES7149 |
i2s.MODE_LSB |
number |
LSB Format |
i2s.MODE_MSB |
number |
MSB format, such TM8211 |
i2s.MONO_L |
number |
Left channel |
i2s.MONO_R |
number |
Right Channel |
i2s.STEREO |
number |
Stereo |
i2s.setup(id, mode, sample, bitw, channel, format, framebit)#
Initialization i2s
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
i2s Channel number, related to specific equipment |
int |
Mode, 0 master 1 slave |
int |
Sampling rate, default 44100. Optional |
int |
Number of data bits, default 16, can be a multiple of 8 |
int |
Channel, 0 left channel, 1 right channel, 2 stereo. Optional |
int |
format, optional MODE_I2S, MODE_LSB, MODE_MSB |
int |
1 BCLK number of channels, optional 16 and 32 |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
int |
underlying return value |
Examples
-- Initialize with default parameters i2s
i2s.setup(0)
-- Initialize i2s with detailed parameters, example with default values
i2s.setup(0, 0, 44100, 16, 0, 0, 16)
i2s.send(id, data, len)#
Send i2s data
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Channel id |
string |
Data, which can be a string or zbuff |
int |
Data length, unit byte, string is the full length of the string by default, zbuff is the pointer position by default |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
int |
The underlying return value, for debugging trial |
Examples
local f = io.open("/luadb/abc.wav")
while 1 do
local data = f:read(4096)
if not data or #data == 0 then
break
end
i2s.send(0, data)
sys.wait(100)
end
i2s.recv(id, buffer, len)#
Receive i2s data, note that the data has been stored in zbuff at the time of callback, currently only air780e series support
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Channel id |
zbuff |
Data cache |
int |
The length of the data returned at a time, in bytes, must be consistent with the size of the zbuff passed in. |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
Examples
local buffer = zbuff.create(3200)
local succ = i2s.recv(0, buffer, 3200);
i2s.close(id)#
Close i2s
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Channel id |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
i2s.close(0)
i2s.on(id, func)#
Register I2S Event Callback
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
i2s id, i2s0 Write 0, i2s1 write 1 |
function |
Callback Method |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
i2s.on(0, function(id, buff)
if buff then
log.info("i2s get data in zbuff")
else
log.info("i2s tx one block done")
end
end)
i2s.txStat(id)#
Get the send buffer status for i2s
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
i2s id, i2s0 Write 0, i2s1 write 1 |
return |
Total size of the underlying buffer |
return |
Remaining data to be sent in the underlying buffer |
Return Value
None
Examples
-- Read the status of the send buffer to determine whether incoming audio data needs to continue
local max, remain = i2s.txStat(0)
log.info("i2s Send Buffer Status", max, remain)
i2s.getPara(id)#
Obtain the I2S parameter. For more information, see setup
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Channel id |
Return Value
return value type |
explanation |
---|---|
boolean |
Is true in working state |
int |
Mode, 0 master 1 slave |
int |
Sample Rate |
int |
Number of data bits |
int |
vocal tract |
int |
Format |
int |
1 BCLK number of channels |
Examples
None