Native code cleanups

Changed toolchain to "clang", set "-Ofast" so that the code is
compiled with proper optimization, and fixed some code errors
uncovered by clang's more aggressive optimization.
master
Raph Levien 8 years ago
parent cd8d8fbbaa
commit 40a6b2d753
  1. 2
      app/build.gradle
  2. 4
      app/src/main/jni/neon_fir.s
  3. 12
      app/src/main/jni/ringbuffer.cc
  4. 4
      app/src/main/jni/ringbuffer.h

@ -20,6 +20,8 @@ model {
}
ndk {
moduleName "synth"
toolchain "clang"
cppFlags.add('-Ofast')
ldLibs.addAll(['log', 'OpenSLES'])
}
abis {

@ -334,7 +334,7 @@ neon_halfrate_split1:
pop {r4}
bx lr
.size neon_halfrate_split, .-.neon_halfrate_split
.size neon_halfrate_split, .-neon_halfrate_split
.align 2
.global neon_halfrate_combine
@ -364,4 +364,4 @@ neon_halfrate_combine1:
pop {r4}
bx lr
.size neon_halfrate_combine, .-.neon_halfrate_combine
.size neon_halfrate_combine, .-neon_halfrate_combine

@ -36,7 +36,7 @@ int RingBuffer::WriteBytesAvailable() {
int RingBuffer::Read(int size, uint8_t *bytes) {
int rd_ix = rd_ix_;
SynthMemoryBarrier(); // read barrier, make sure data is committed before ix
int fragment_size = min(size, kBufSize - rd_ix);
unsigned int fragment_size = min((unsigned int)size, kBufSize - rd_ix);
memcpy(bytes, buf_ + rd_ix, fragment_size);
if (size > fragment_size) {
memcpy(bytes + fragment_size, buf_, size - fragment_size);
@ -46,20 +46,20 @@ int RingBuffer::Read(int size, uint8_t *bytes) {
return size;
}
int RingBuffer::Write(const uint8_t *bytes, int size) {
int remaining = size;
void RingBuffer::Write(const uint8_t *bytes, int size) {
unsigned int remaining = (unsigned int)size;
while (remaining > 0) {
int rd_ix = rd_ix_;
int wr_ix = wr_ix_;
int space_available = (rd_ix - wr_ix - 1) & (kBufSize - 1);
unsigned int space_available = (rd_ix - wr_ix - 1) & (kBufSize - 1);
if (space_available == 0) {
struct timespec sleepTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = 1000000;
nanosleep(&sleepTime, NULL);
} else {
int wr_size = min(remaining, space_available);
int fragment_size = min(wr_size, kBufSize - wr_ix);
unsigned int wr_size = min(remaining, space_available);
unsigned int fragment_size = min(wr_size, kBufSize - wr_ix);
memcpy(buf_ + wr_ix, bytes, fragment_size);
if (wr_size > fragment_size) {
memcpy(buf_, bytes + fragment_size, wr_size - fragment_size);

@ -33,9 +33,9 @@ class RingBuffer {
// Writes bytes into the buffer. If the buffer is full, the method will
// block until space is available.
int Write(const uint8_t *bytes, int size);
void Write(const uint8_t *bytes, int size);
private:
static const int kBufSize = 8192;
static const unsigned int kBufSize = 65536;
uint8_t buf_[kBufSize];
volatile unsigned int rd_ix_;
volatile unsigned int wr_ix_;

Loading…
Cancel
Save