diff --git a/android/jni/Application.mk b/android/jni/Application.mk index eab2761..3d53443 100644 --- a/android/jni/Application.mk +++ b/android/jni/Application.mk @@ -1,3 +1,2 @@ -APP_STL := stlport_static -APP_ABI := armeabi-v7a +APP_ABI := all diff --git a/cpp/src/dx7note.cc b/cpp/src/dx7note.cc index 6550640..7392cff 100644 --- a/cpp/src/dx7note.cc +++ b/cpp/src/dx7note.cc @@ -14,7 +14,9 @@ * limitations under the License. */ +#ifdef VERBOSE #include +#endif #include #include "synth.h" #include "freqlut.h" @@ -66,14 +68,14 @@ const uint8_t velocity_data[64] = { // See "velocity" section of notes. Returns velocity delta in microsteps. int ScaleVelocity(int velocity, int sensitivity) { - int clamped_vel = std::max(0, std::min(127, velocity)); + int clamped_vel = max(0, min(127, velocity)); int vel_value = velocity_data[clamped_vel >> 1] - 239; int scaled_vel = ((sensitivity * vel_value + 7) >> 3) << 4; return scaled_vel; } int ScaleRate(int midinote, int sensitivity) { - int x = std::min(31, std::max(0, midinote / 3 - 7)); + int x = min(31, max(0, midinote / 3 - 7)); int qratedelta = (sensitivity * x) >> 3; #ifdef SUPER_PRECISE int rem = x & 7; @@ -99,7 +101,7 @@ int ScaleCurve(int group, int depth, int curve) { } else { // exponential int n_scale_data = sizeof(exp_scale_data); - int raw_exp = exp_scale_data[std::min(group, n_scale_data - 1)]; + int raw_exp = exp_scale_data[min(group, n_scale_data - 1)]; scale = (raw_exp * depth * 329) >> 15; } if (curve < 2) { @@ -129,17 +131,21 @@ Dx7Note::Dx7Note(const char patch[128], int midinote, int velocity) { levels[i] = patch[off + 4 + i]; } int outlevel = patch[off + 14]; +#ifdef VERBOSE for (int j = 8; j < 12; j++) { cout << (int)patch[off + j] << " "; } +#endif int level_scaling = ScaleLevel(midinote, patch[off + 8], patch[off + 9], patch[off + 10], patch[off + 11] & 3, patch[off + 11] >> 2); outlevel += level_scaling; - outlevel = std::min(99, outlevel); + outlevel = min(99, outlevel); +#ifdef VERBOSE cout << op << ": " << level_scaling << " " << outlevel << endl; +#endif outlevel = outlevel << 5; outlevel += ScaleVelocity(velocity, patch[off + 13] >> 2); - outlevel = std::max(0, outlevel); + outlevel = max(0, outlevel); int rate_scaling = ScaleRate(midinote, patch[off + 12] & 7); env_[op].init(rates, levels, outlevel, rate_scaling); diff --git a/cpp/src/env.cc b/cpp/src/env.cc index bb54014..65b736c 100644 --- a/cpp/src/env.cc +++ b/cpp/src/env.cc @@ -14,7 +14,6 @@ * limitations under the License. */ -#include #include "synth.h" #include "env.h" @@ -92,7 +91,7 @@ void Env::advance(int newix) { // rate int qrate = (rates_[ix_] * 41) >> 6; qrate += rate_scaling_; - qrate = std::min(qrate, 63); + qrate = min(qrate, 63); inc_ = (4 + (qrate & 3)) << (2 + LG_N + (qrate >> 2)); } } diff --git a/cpp/src/fm_core.cc b/cpp/src/fm_core.cc index 874164c..7f5ed60 100644 --- a/cpp/src/fm_core.cc +++ b/cpp/src/fm_core.cc @@ -1,4 +1,23 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef VERBOSE #include +#endif + #include "synth.h" #include "fm_op_kernel.h" #include "fm_core.h" @@ -68,6 +87,7 @@ int n_out(const FmAlgorithm &alg) { } void FmCore::dump() { +#ifdef VERBOSE for (int i = 0; i < 32; i++) { cout << (i + 1) << ":"; const FmAlgorithm &alg = algorithms[i]; @@ -84,6 +104,7 @@ void FmCore::dump() { cout << " " << n_out(alg); cout << endl; } +#endif } void FmCore::compute(int32_t *output, FmOpParams *params, int algorithm, diff --git a/cpp/src/fm_op_kernel.cc b/cpp/src/fm_op_kernel.cc index 29f42d6..867ea26 100644 --- a/cpp/src/fm_op_kernel.cc +++ b/cpp/src/fm_op_kernel.cc @@ -15,9 +15,6 @@ */ #include -#include - -using namespace std; #include "synth.h" diff --git a/cpp/src/freqlut.cc b/cpp/src/freqlut.cc index cf8afeb..931ef67 100644 --- a/cpp/src/freqlut.cc +++ b/cpp/src/freqlut.cc @@ -19,12 +19,9 @@ // The LUT is just a global, and we'll need the init function to be called before // use. -#include // for debugging #include #include -using namespace std; - #include "freqlut.h" #define LG_N_SAMPLES 10 diff --git a/cpp/src/ringbuffer.cc b/cpp/src/ringbuffer.cc index 387b373..e0b1328 100644 --- a/cpp/src/ringbuffer.cc +++ b/cpp/src/ringbuffer.cc @@ -16,7 +16,6 @@ #include #include -#include #include "synth.h" #include "ringbuffer.h" @@ -33,7 +32,7 @@ int RingBuffer::BytesAvailable() { 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 = std::min(size, kBufSize - rd_ix); + int fragment_size = min(size, kBufSize - rd_ix); memcpy(bytes, buf_ + rd_ix, fragment_size); if (size > fragment_size) { memcpy(bytes + fragment_size, buf_, size - fragment_size); @@ -55,8 +54,8 @@ int RingBuffer::Write(const uint8_t *bytes, int size) { sleepTime.tv_nsec = 1000000; nanosleep(&sleepTime, NULL); } else { - int wr_size = std::min(remaining, space_available); - int fragment_size = std::min(wr_size, kBufSize - wr_ix); + int wr_size = min(remaining, space_available); + 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); diff --git a/cpp/src/sawtooth.cc b/cpp/src/sawtooth.cc index 0be01c9..aa78018 100644 --- a/cpp/src/sawtooth.cc +++ b/cpp/src/sawtooth.cc @@ -15,8 +15,6 @@ */ #include -#include -using namespace std; #include "module.h" #include "sawtooth.h" diff --git a/cpp/src/sin.cc b/cpp/src/sin.cc index 5839528..56e06f3 100644 --- a/cpp/src/sin.cc +++ b/cpp/src/sin.cc @@ -15,8 +15,6 @@ */ #include -#include -using namespace std; #include "sin.h" diff --git a/cpp/src/synth.h b/cpp/src/synth.h index 8074ac6..2d310d8 100644 --- a/cpp/src/synth.h +++ b/cpp/src/synth.h @@ -40,4 +40,14 @@ #define SynthMemoryBarrier() #endif +template +inline static T min(const T& a, const T& b) { + return a < b ? a : b; +} + +template +inline static T max(const T& a, const T& b) { + return a > b ? a : b; +} + #endif // __SYNTH_H diff --git a/cpp/src/synth_unit.cc b/cpp/src/synth_unit.cc index 448c66a..6121167 100644 --- a/cpp/src/synth_unit.cc +++ b/cpp/src/synth_unit.cc @@ -14,7 +14,11 @@ * limitations under the License. */ +#ifdef VERBOSE #include +#endif + +#include #include "synth.h" #include "synth_unit.h" @@ -37,7 +41,7 @@ SynthUnit::SynthUnit(RingBuffer *ring_buffer) { active_note_[note].dx7_note = NULL; } input_buffer_index_ = 0; - std::memcpy(patch_data_, epiano, sizeof(epiano)); + memcpy(patch_data_, epiano, sizeof(epiano)); current_patch_ = 0; current_note_ = 0; } @@ -48,7 +52,7 @@ SynthUnit::SynthUnit(RingBuffer *ring_buffer) { // optimizing for simplicity of implementation. void SynthUnit::TransferInput() { size_t bytes_available = ring_buffer_->BytesAvailable(); - int bytes_to_read = std::min(bytes_available, + int bytes_to_read = min(bytes_available, sizeof(input_buffer_) - input_buffer_index_); if (bytes_to_read > 0) { ring_buffer_->Read(bytes_to_read, input_buffer_ + input_buffer_index_); @@ -58,7 +62,7 @@ void SynthUnit::TransferInput() { void SynthUnit::ConsumeInput(int n_input_bytes) { if (n_input_bytes < input_buffer_index_) { - std::memmove(input_buffer_, input_buffer_ + n_input_bytes, + memmove(input_buffer_, input_buffer_ + n_input_bytes, input_buffer_index_ - n_input_bytes); } input_buffer_index_ -= n_input_bytes; @@ -97,12 +101,14 @@ int SynthUnit::ProcessMidiMessage(const uint8_t *buf, int buf_size) { if (buf_size >= 2) { // program change int program_number = buf[1]; - current_patch_ = std::min(program_number, 31); + current_patch_ = min(program_number, 31); char name[11]; - std::memcpy(name, patch_data_ + 128 * current_patch_ + 118, 10); + memcpy(name, patch_data_ + 128 * current_patch_ + 118, 10); name[10] = 0; +#ifdef VERBOSE std::cout << "Loaded patch " << current_patch_ << ": " << name << "\r"; std::cout.flush(); +#endif return 2; } return 0; @@ -112,7 +118,7 @@ int SynthUnit::ProcessMidiMessage(const uint8_t *buf, int buf_size) { buf[4] == 0x20 && buf[5] == 0x00) { if (buf_size >= 4104) { // TODO: check checksum? - std::memcpy(patch_data_, buf + 6, 4096); + memcpy(patch_data_, buf + 6, 4096); return 4104; } return 0; @@ -120,8 +126,10 @@ int SynthUnit::ProcessMidiMessage(const uint8_t *buf, int buf_size) { } // TODO: more robust handling +#ifdef VERBOSE std::cout << "Unknown message " << std::hex << (int)cmd << ", skipping " << std::dec << buf_size << " bytes" << std::endl; +#endif return buf_size; }