text
stringlengths 0
2.2M
|
---|
// Created by Nick Donaldson on 5/21/13.
|
//
|
#ifndef TonicDemo_ArbitraryTableLookupDemo_h
|
#define TonicDemo_ArbitraryTableLookupDemo_h
|
#include "Tonic.h"
|
using namespace Tonic;
|
class ArbitraryTableLookupSynth : public Synth
|
{
|
public:
|
ArbitraryTableLookupSynth(){
|
// Build a table of arbitrary length. TableLookupOsc requires power-of-two+1 length tables, but they will be resized if necessary.
|
// Try changing this to 2049 and compare the sound. Should be perceptually almost identical.
|
const unsigned int tablesize = 2500;
|
// You can register this in a collection if you want to use it in a few oscillators
|
SampleTable lookupTable = SampleTable(tablesize, 1);
|
TonicFloat norm = 1.0f / tablesize;
|
TonicFloat * tableData = lookupTable.dataPointer();
|
for (unsigned int i=0; i<tablesize; i++){
|
// sum a few sine waves
|
TonicFloat phase = TWO_PI * i * norm;
|
*tableData++ = 0.75f * sinf(phase) + 0.5f * sinf( phase * 2 ) + 0.25f * sinf(phase * 5);
|
}
|
TableLookupOsc osc = TableLookupOsc().setLookupTable(lookupTable).freq( 100 + 40 * SineWave().freq(0.1) );
|
setOutputGen(osc * 0.25);
|
}
|
};
|
TONIC_REGISTER_SYNTH(ArbitraryTableLookupSynth);
|
#endif
|
#include <android/log.h>
|
#include <pthread.h>
|
#include <unistd.h>
|
#include <cassert>
|
#include <cmath>
|
#include <vector>
|
#define ALOGI(...) \
|
__android_log_print(ANDROID_LOG_INFO, "PyTorchTestAppJni", __VA_ARGS__)
|
#define ALOGE(...) \
|
__android_log_print(ANDROID_LOG_ERROR, "PyTorchTestAppJni", __VA_ARGS__)
|
#include "jni.h"
|
#include <torch/script.h>
|
namespace pytorch_testapp_jni {
|
namespace {
|
template <typename T>
|
void log(const char* m, T t) {
|
std::ostringstream os;
|
os << t << std::endl;
|
ALOGI("%s %s", m, os.str().c_str());
|
}
|
struct JITCallGuard {
|
c10::InferenceMode guard;
|
torch::jit::GraphOptimizerEnabledGuard no_optimizer_guard{false};
|
};
|
} // namespace
|
static void loadAndForwardModel(JNIEnv* env, jclass, jstring jModelPath) {
|
const char* modelPath = env->GetStringUTFChars(jModelPath, 0);
|
assert(modelPath);
|
// To load torchscript model for mobile we need set these guards,
|
// because mobile build doesn't support features like autograd for smaller
|
// build size which is placed in `struct JITCallGuard` in this example. It may
|
// change in future, you can track the latest changes keeping an eye in
|
// android/pytorch_android/src/main/cpp/pytorch_jni_jit.cpp
|
JITCallGuard guard;
|
torch::jit::Module module = torch::jit::load(modelPath);
|
module.eval();
|
torch::Tensor t = torch::randn({1, 3, 224, 224});
|
log("input tensor:", t);
|
c10::IValue t_out = module.forward({t});
|
log("output tensor:", t_out);
|
env->ReleaseStringUTFChars(jModelPath, modelPath);
|
}
|
} // namespace pytorch_testapp_jni
|
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
|
JNIEnv* env;
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.