ausocean / ausocean/client

ESP/Speaker: Remove unnecessary heap allocation for I2S channel handle

Open
#157 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
0
Avg merge
1h 27m
Merged PRs (30d)
1

Description

## Problem

`i2s_chan_handle_t` is itself a pointer type. `init_amp()` currently allocates a heap object solely to provide storage for that pointer:
```cpp
i2s_chan_handle_t *tx_handle = new i2s_chan_handle_t();
i2s_new_channel(..., tx_handle, ...);
```

This allocation is unnecessary. It also makes ownership unclear because the wrapper pointer is allocated in `audio.cpp` and later deleted in `tas5805.cpp`.

An allocation failure during startup may also occur before the code has an opportunity to handle the error cleanly.

## Proposed change

Store the handle directly:
```cpp
i2s_chan_handle_t tx_handle = nullptr;
i2s_new_channel(..., &tx_handle, ...);
```

Store the resulting handle by value in `TAS5805`:
```cpp
i2s_chan_handle_t tx_handle = nullptr;
```
Update callers to use:
```
i2s_channel_write(tx_handle, ...);
```
rather than dereferencing a pointer-to-handle.

Do not delete the handle. If TAS5805 owns the lifetime of the I2S channel, release it with `i2s_del_channel()` when the channel is no longer needed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Read init_amp() in audio.cpp and the TAS5805 implementation in tas5805.cpp, tracing how tx_handle is created, stored, used, and deleted. Change the handle to a value in both locations, update i2s_channel_write() callers, and verify the channel lifetime is handled with i2s_del_channel() when appropriate; done means the heap wrapper and delete are gone and the project builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.