mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-05 17:46:21 +00:00
895bc7721a
This adds SPDX license headers to all source code files, following the REUSE[1] specification. This does not include any asset files (such as generated JSON files, or textures). While REUSE does support doing so with ".license" files, for now we define these licences using the .reuse/dep5 file. [1]: https://reuse.software/
34 lines
909 B
Markdown
34 lines
909 B
Markdown
---
|
|
module: [kind=event] speaker_audio_empty
|
|
see: speaker.playAudio To play audio using the speaker
|
|
---
|
|
|
|
<!--
|
|
SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
|
|
|
|
SPDX-License-Identifier: MPL-2.0
|
|
-->
|
|
|
|
## Return Values
|
|
1. @{string}: The event name.
|
|
2. @{string}: The name of the speaker which is available to play more audio.
|
|
|
|
|
|
## Example
|
|
This uses @{io.lines} to read audio data in blocks of 16KiB from "example_song.dfpwm", and then attempts to play it
|
|
using @{speaker.playAudio}. If the speaker's buffer is full, it waits for an event and tries again.
|
|
|
|
```lua {data-peripheral=speaker}
|
|
local dfpwm = require("cc.audio.dfpwm")
|
|
local speaker = peripheral.find("speaker")
|
|
|
|
local decoder = dfpwm.make_decoder()
|
|
for chunk in io.lines("data/example.dfpwm", 16 * 1024) do
|
|
local buffer = decoder(chunk)
|
|
|
|
while not speaker.playAudio(buffer) do
|
|
os.pullEvent("speaker_audio_empty")
|
|
end
|
|
end
|
|
```
|