Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions audio-echo/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.22.1)
project(echo LANGUAGES C CXX)

add_compile_options(-Wall -Wextra -Werror)

add_library(echo
SHARED
audio_main.cpp
Expand All @@ -18,12 +20,6 @@ target_link_libraries(echo
log
atomic)

target_compile_options(echo
PRIVATE
-Wall
-Werror
)

if (ANDROID_ABI STREQUAL riscv64)
# This sample uses OpenSLES, which was deprecated in API 26. Our
# minSdkVersion is 21, but we also build for riscv64, which isn't a
Expand Down
4 changes: 2 additions & 2 deletions audio-echo/app/src/main/cpp/audio_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ float AudioDelay::getDecayWeight(void) const { return decayWeight_; }
* @param channelCount for liveAudio, must be 2 for stereo
* @param numFrames is length of liveAudio in Frames ( not in byte )
*/
void AudioDelay::process(int16_t* liveAudio, int32_t numFrames) {
void AudioDelay::process(int16_t* liveAudio, uint32_t numFrames) {
if (feedbackFactor_ == 0 || bufSize_ < numFrames) {
return;
}
Expand All @@ -144,7 +144,7 @@ void AudioDelay::process(int16_t* liveAudio, int32_t numFrames) {
}

// process every sample
int32_t sampleCount = channelCount_ * numFrames;
auto sampleCount = channelCount_ * numFrames;
int16_t* samples = &static_cast<int16_t*>(buffer_)[curPos_ * channelCount_];
for (size_t idx = 0; idx < sampleCount; idx++) {
#if 1
Expand Down
2 changes: 1 addition & 1 deletion audio-echo/app/src/main/cpp/audio_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AudioDelay : public AudioFormat {
size_t getDelayTime(void) const;
void setDecayWeight(float weight);
float getDecayWeight(void) const;
void process(int16_t* liveAudio, int32_t numFrames);
void process(int16_t* liveAudio, uint32_t numFrames);

private:
size_t delayTime_ = 0;
Expand Down
26 changes: 12 additions & 14 deletions audio-echo/app/src/main/cpp/audio_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static EchoAudioEngine engine;
bool EngineService(void* ctx, uint32_t msg, void* data);

JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_createSLEngine(
JNIEnv* env, jclass type, jint sampleRate, jint framesPerBuf,
jlong delayInMs, jfloat decay) {
JNIEnv*, jclass, jint sampleRate, jint framesPerBuf, jlong delayInMs,
jfloat decay) {
SLresult result;
memset(&engine, 0, sizeof(engine));

Expand Down Expand Up @@ -103,7 +103,7 @@ JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_createSLEngine(
}

JNIEXPORT jboolean JNICALL
Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv* env, jclass type,
Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv*, jclass,
jint delayInMs,
jfloat decay) {
engine.echoDelay_ = delayInMs;
Expand All @@ -116,7 +116,7 @@ Java_com_google_sample_echo_MainActivity_configureEcho(JNIEnv* env, jclass type,

JNIEXPORT jboolean JNICALL
Java_com_google_sample_echo_MainActivity_createSLBufferQueueAudioPlayer(
JNIEnv* env, jclass type) {
JNIEnv*, jclass) {
SampleFormat sampleFormat;
memset(&sampleFormat, 0, sizeof(sampleFormat));
sampleFormat.pcmFormat_ = (uint16_t)engine.bitsPerSample_;
Expand All @@ -138,16 +138,15 @@ Java_com_google_sample_echo_MainActivity_createSLBufferQueueAudioPlayer(

JNIEXPORT void JNICALL
Java_com_google_sample_echo_MainActivity_deleteSLBufferQueueAudioPlayer(
JNIEnv* env, jclass type) {
JNIEnv*, jclass) {
if (engine.player_) {
delete engine.player_;
engine.player_ = nullptr;
}
}

JNIEXPORT jboolean JNICALL
Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv* env,
jclass type) {
Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv*, jclass) {
SampleFormat sampleFormat;
memset(&sampleFormat, 0, sizeof(sampleFormat));
sampleFormat.pcmFormat_ = static_cast<uint16_t>(engine.bitsPerSample_);
Expand All @@ -166,15 +165,14 @@ Java_com_google_sample_echo_MainActivity_createAudioRecorder(JNIEnv* env,
}

JNIEXPORT void JNICALL
Java_com_google_sample_echo_MainActivity_deleteAudioRecorder(JNIEnv* env,
jclass type) {
Java_com_google_sample_echo_MainActivity_deleteAudioRecorder(JNIEnv*, jclass) {
if (engine.recorder_) delete engine.recorder_;

engine.recorder_ = nullptr;
}

JNIEXPORT void JNICALL
Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv* env, jclass type) {
Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv*, jclass) {
engine.frameCount_ = 0;
/*
* start player: make it into waitForData state
Expand All @@ -187,7 +185,7 @@ Java_com_google_sample_echo_MainActivity_startPlay(JNIEnv* env, jclass type) {
}

JNIEXPORT void JNICALL
Java_com_google_sample_echo_MainActivity_stopPlay(JNIEnv* env, jclass type) {
Java_com_google_sample_echo_MainActivity_stopPlay(JNIEnv*, jclass) {
engine.recorder_->Stop();
engine.player_->Stop();

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

JNIEXPORT void JNICALL Java_com_google_sample_echo_MainActivity_deleteSLEngine(
JNIEnv* env, jclass type) {
JNIEXPORT void JNICALL
Java_com_google_sample_echo_MainActivity_deleteSLEngine(JNIEnv*, jclass) {
delete engine.recBufQueue_;
delete engine.freeBufQueue_;
releaseSampleBufs(engine.bufs_, engine.bufCount_);
Expand Down Expand Up @@ -236,7 +234,7 @@ uint32_t dbgEngineGetBufCount(void) {
/*
* simple message passing for player/recorder to communicate with engine
*/
bool EngineService(void* ctx, uint32_t msg, void* data) {
bool EngineService([[maybe_unused]] void* ctx, uint32_t msg, void* data) {
assert(ctx == &engine);
switch (msg) {
case ENGINE_SERVICE_MSG_RETRIEVE_DUMP_BUFS: {
Expand Down
33 changes: 0 additions & 33 deletions audio-echo/app/src/main/cpp/buf_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,6 @@ class ProducerConsumerQueue {
});
}

// get() is idempotent between calls to commit().
T* getWriteablePtr() {
T* result = nullptr;

bool check __attribute__((unused)); //= false;

check = push([&](T* head) -> bool {
result = head;
return false; // don't increment
});

// if there's no space, result should not have been set, and vice versa
assert(check == (result != nullptr));

return result;
}

bool commitWriteablePtr(T* ptr) {
bool result = push([&](T* head) -> bool {
// this writer func does nothing, because we assume that the caller
// has already written to *ptr after acquiring it from a call to get().
// So just double-check that ptr is actually at the write head, and
// return true to indicate that it's safe to advance.

// if this isn't the same pointer we got from a call to get(), then
// something has gone terribly wrong. Either there was an intervening
// call to push() or commit(), or the pointer is spurious.
assert(ptr == head);
return true;
});
return result;
}

// writer() can return false, which indicates that the caller
// of push() changed its mind while writing (e.g. ran out of bytes)
template <typename F>
Expand Down