Skip to content

Commit a8390d7

Browse files
Dan AlbertDanAlbert
authored andcommitted
Increase warning level for audio-echo.
Add -Wextra, use add_compile_options instead of target_compile_options so it affects the whole file (there's only one target here so it makes no difference, but it's safer for copying), and fix the issues: 1. A function that took an int32_t for comparison with other unsigned types, despite the only caller passing a uint32_t that was being narrowed anyway. 2. A bunch of unused arguments. 3. Removed some unused code that had warnings rather than fixing it.
1 parent 5c283e2 commit a8390d7

File tree

5 files changed

+17
-56
lines changed

5 files changed

+17
-56
lines changed

audio-echo/app/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.22.1)
22
project(echo LANGUAGES C CXX)
33

4+
add_compile_options(-Wall -Wextra -Werror)
5+
46
add_library(echo
57
SHARED
68
audio_main.cpp
@@ -18,12 +20,6 @@ target_link_libraries(echo
1820
log
1921
atomic)
2022

21-
target_compile_options(echo
22-
PRIVATE
23-
-Wall
24-
-Werror
25-
)
26-
2723
if (ANDROID_ABI STREQUAL riscv64)
2824
# This sample uses OpenSLES, which was deprecated in API 26. Our
2925
# minSdkVersion is 21, but we also build for riscv64, which isn't a

audio-echo/app/src/main/cpp/audio_effect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ float AudioDelay::getDecayWeight(void) const { return decayWeight_; }
130130
* @param channelCount for liveAudio, must be 2 for stereo
131131
* @param numFrames is length of liveAudio in Frames ( not in byte )
132132
*/
133-
void AudioDelay::process(int16_t* liveAudio, int32_t numFrames) {
133+
void AudioDelay::process(int16_t* liveAudio, uint32_t numFrames) {
134134
if (feedbackFactor_ == 0 || bufSize_ < numFrames) {
135135
return;
136136
}
@@ -144,7 +144,7 @@ void AudioDelay::process(int16_t* liveAudio, int32_t numFrames) {
144144
}
145145

146146
// process every sample
147-
int32_t sampleCount = channelCount_ * numFrames;
147+
auto sampleCount = channelCount_ * numFrames;
148148
int16_t* samples = &static_cast<int16_t*>(buffer_)[curPos_ * channelCount_];
149149
for (size_t idx = 0; idx < sampleCount; idx++) {
150150
#if 1

audio-echo/app/src/main/cpp/audio_effect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AudioDelay : public AudioFormat {
5050
size_t getDelayTime(void) const;
5151
void setDecayWeight(float weight);
5252
float getDecayWeight(void) const;
53-
void process(int16_t* liveAudio, int32_t numFrames);
53+
void process(int16_t* liveAudio, uint32_t numFrames);
5454

5555
private:
5656
size_t delayTime_ = 0;

audio-echo/app/src/main/cpp/audio_main.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static EchoAudioEngine engine;
5252
bool EngineService(void* ctx, uint32_t msg, void* data);
5353

5454
JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_createSLEngine(
55-
JNIEnv* env, jclass type, jint sampleRate, jint framesPerBuf,
56-
jlong delayInMs, jfloat decay) {
55+
JNIEnv*, jclass, jint sampleRate, jint framesPerBuf, jlong delayInMs,
56+
jfloat decay) {
5757
SLresult result;
5858
memset(&engine, 0, sizeof(engine));
5959

@@ -103,7 +103,7 @@ JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_createSLEngine(
103103
}
104104

105105
JNIEXPORT jboolean JNICALL
106-
Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv* env, jclass type,
106+
Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv*, jclass,
107107
jint delayInMs,
108108
jfloat decay) {
109109
engine.echoDelay_ = delayInMs;
@@ -116,7 +116,7 @@ Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv* env, jclass type,
116116

117117
JNIEXPORT jboolean JNICALL
118118
Java_com_google_sample_echo_MainActivity_createSLBufferQueueAudioPlayer(
119-
JNIEnv* env, jclass type) {
119+
JNIEnv*, jclass) {
120120
SampleFormat sampleFormat;
121121
memset(&sampleFormat, 0, sizeof(sampleFormat));
122122
sampleFormat.pcmFormat_ = (uint16_t)engine.bitsPerSample_;
@@ -138,16 +138,15 @@ Java_com_google_sample_echo_MainActivity_createSLBufferQueueAudioPlayer(
138138

139139
JNIEXPORT void JNICALL
140140
Java_com_google_sample_echo_MainActivity_deleteSLBufferQueueAudioPlayer(
141-
JNIEnv* env, jclass type) {
141+
JNIEnv*, jclass) {
142142
if (engine.player_) {
143143
delete engine.player_;
144144
engine.player_ = nullptr;
145145
}
146146
}
147147

148148
JNIEXPORT jboolean JNICALL
149-
Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv* env,
150-
jclass type) {
149+
Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv*, jclass) {
151150
SampleFormat sampleFormat;
152151
memset(&sampleFormat, 0, sizeof(sampleFormat));
153152
sampleFormat.pcmFormat_ = static_cast<uint16_t>(engine.bitsPerSample_);
@@ -166,15 +165,14 @@ Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv* env,
166165
}
167166

168167
JNIEXPORT void JNICALL
169-
Java_com_google_sample_echo_MainActivity_deleteAudioRecorder(JNIEnv* env,
170-
jclass type) {
168+
Java_com_google_sample_echo_MainActivity_deleteAudioRecorder(JNIEnv*, jclass) {
171169
if (engine.recorder_) delete engine.recorder_;
172170

173171
engine.recorder_ = nullptr;
174172
}
175173

176174
JNIEXPORT void JNICALL
177-
Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv* env, jclass type) {
175+
Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv*, jclass) {
178176
engine.frameCount_ = 0;
179177
/*
180178
* start player: make it into waitForData state
@@ -187,7 +185,7 @@ Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv* env, jclass type) {
187185
}
188186

189187
JNIEXPORT void JNICALL
190-
Java_com_google_sample_echo_MainActivity_stopPlay(JNIEnv* env, jclass type) {
188+
Java_com_google_sample_echo_MainActivity_stopPlay(JNIEnv*, jclass) {
191189
engine.recorder_->Stop();
192190
engine.player_->Stop();
193191

@@ -197,8 +195,8 @@ Java_com_google_sample_echo_MainActivity_stopPlay(JNIEnv* env, jclass type) {
197195
engine.player_ = NULL;
198196
}
199197

200-
JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_deleteSLEngine(
201-
JNIEnv* env, jclass type) {
198+
JNIEXPORT void JNICALL
199+
Java_com_google_sample_echo_MainActivity_deleteSLEngine(JNIEnv*, jclass) {
202200
delete engine.recBufQueue_;
203201
delete engine.freeBufQueue_;
204202
releaseSampleBufs(engine.bufs_, engine.bufCount_);
@@ -236,7 +234,7 @@ uint32_t dbgEngineGetBufCount(void) {
236234
/*
237235
* simple message passing for player/recorder to communicate with engine
238236
*/
239-
bool EngineService(void* ctx, uint32_t msg, void* data) {
237+
bool EngineService([[maybe_unused]] void* ctx, uint32_t msg, void* data) {
240238
assert(ctx == &engine);
241239
switch (msg) {
242240
case ENGINE_SERVICE_MSG_RETRIEVE_DUMP_BUFS: {

audio-echo/app/src/main/cpp/buf_manager.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,6 @@ class ProducerConsumerQueue {
5050
});
5151
}
5252

53-
// get() is idempotent between calls to commit().
54-
T* getWriteablePtr() {
55-
T* result = nullptr;
56-
57-
bool check __attribute__((unused)); //= false;
58-
59-
check = push([&](T* head) -> bool {
60-
result = head;
61-
return false; // don't increment
62-
});
63-
64-
// if there's no space, result should not have been set, and vice versa
65-
assert(check == (result != nullptr));
66-
67-
return result;
68-
}
69-
70-
bool commitWriteablePtr(T* ptr) {
71-
bool result = push([&](T* head) -> bool {
72-
// this writer func does nothing, because we assume that the caller
73-
// has already written to *ptr after acquiring it from a call to get().
74-
// So just double-check that ptr is actually at the write head, and
75-
// return true to indicate that it's safe to advance.
76-
77-
// if this isn't the same pointer we got from a call to get(), then
78-
// something has gone terribly wrong. Either there was an intervening
79-
// call to push() or commit(), or the pointer is spurious.
80-
assert(ptr == head);
81-
return true;
82-
});
83-
return result;
84-
}
85-
8653
// writer() can return false, which indicates that the caller
8754
// of push() changed its mind while writing (e.g. ran out of bytes)
8855
template <typename F>

0 commit comments

Comments
 (0)