void main(int argc, char** args) { if(argc != 2) { printf("Syntax: %s <path>"); return; } char* path = args[1]; LavHandle node; LavHandle simulation; ERRCHECK(Lav_initialize()); ERRCHECK(Lav_createSimulation(44100, 1024, &simulation)); ERRCHECK(Lav_simulationSetOutputDevice(simulation, -1, 2, 2)); ERRCHECK(Lav_createBufferNode(simulation, &node)); LavHandle buffer; ERRCHECK(Lav_createBuffer(simulation, &buffer)); ERRCHECK(Lav_bufferLoadFromFile(buffer, path)); ERRCHECK(Lav_nodeSetBufferProperty(node, Lav_BUFFER_BUFFER, buffer)); LavHandle limit; ERRCHECK(Lav_createHardLimiterNode(simulation, 2, &limit)); ERRCHECK(Lav_nodeConnect(node, 0, limit, 0)); ERRCHECK(Lav_nodeSetEvent(node, Lav_BUFFER_END_EVENT, endOfBufferCallback, nullptr)); ERRCHECK(Lav_nodeConnectSimulation(limit, 0)); //enter the transducer loop. char command[1024]; printf("Commands: q(q)uit, (s)eek, (v)olume, (p)itch bend\n"); printf("pl(a)y/pause\n"); bool isPlaying = true; while(1) { fgets(command, 1023, stdin); if(command[0] == 'q') break; float value; char* start = &command[1]; while(*start == ' ') start+=1; //skip spaces. sscanf(start, "%f", &value); switch(command[0]) { case 'p': Lav_nodeSetFloatProperty(node, Lav_BUFFER_PITCH_BEND, value); break; case 'v': Lav_nodeSetFloatProperty(node, Lav_NODE_MUL, value); break; case 's': Lav_nodeSetDoubleProperty(node, Lav_BUFFER_POSITION, value); break; case 'a': isPlaying = ! isPlaying; Lav_nodeSetIntProperty(node, Lav_NODE_STATE, isPlaying == false ? Lav_NODESTATE_PAUSED: Lav_NODESTATE_PLAYING); break; default: printf("Unrecognized command.\n"); break; } } return; Lav_shutdown(); }
int main(int argc, char** args) { int threads = 1; if(argc == 2) { sscanf(args[1], "%i", &threads); if(threads < 1) { printf("Threads must be greater 1.\n"); return 1; } } printf("Running profile tests on %i threads\n", threads); ERRCHECK(Lav_initialize()); for(int i = 0; i < to_profile_size; i++) { auto &info = to_profile[i]; printf("Estimate for %s nodes: ", std::get<0>(info).c_str()); LavHandle s; ERRCHECK(Lav_createServer(SR, BLOCK_SIZE, &s)); ERRCHECK(Lav_serverSetThreads(s, threads)); int times=std::get<1>(info); //If it's not at least threads, make it threads. if(times < threads) times = threads; auto handles=std::get<2>(info)(s, times); for(auto h: handles) { ERRCHECK(Lav_nodeConnectServer(h, 0)); } float dur=timeit([&] () { ERRCHECK(Lav_serverGetBlock(s, 2, 1, storage)); }, ITERATIONS); dur /= ITERATIONS; float estimate = (BLOCK_SIZE/(float)SR)/dur*times; printf("%f\n", estimate); for(auto h: handles) { ERRCHECK(Lav_nodeDisconnect(h, 0, 0, 0)); ERRCHECK(Lav_handleDecRef(h)); } ERRCHECK(Lav_handleDecRef(s)); } }
void main(int argc, char** args) { int threads = 1; if(argc == 2) { sscanf(args[1], "%i", &threads); if(threads < 1) { printf("Threads must be greater 1.\n"); return; } } printf("Running profile tests on %i threads\n", threads); ERRCHECK(Lav_initialize()); for(int i = 0; i < to_profile_size; i++) { auto &info = to_profile[i]; printf("Estimate for %s nodes: ", std::get<0>(info).c_str()); LavHandle sim; ERRCHECK(Lav_createSimulation(SR, BLOCK_SIZE, &sim)); ERRCHECK(Lav_simulationSetThreads(sim, threads)); int times=std::get<1>(info); //If it's not at least threads, make it threads. if(times < threads) times = threads; auto handles=std::get<2>(info)(sim, times); for(auto h: handles) { ERRCHECK(Lav_nodeSetIntProperty(h, Lav_NODE_STATE, Lav_NODESTATE_ALWAYS_PLAYING)); } float dur=timeit([&] () { ERRCHECK(Lav_simulationGetBlock(sim, 2, 1, storage)); }, ITERATIONS); dur /= ITERATIONS; float estimate = (BLOCK_SIZE/(float)SR)/dur*times; printf("%f\n", estimate); for(auto h: handles) { ERRCHECK(Lav_handleDecRef(h)); } ERRCHECK(Lav_handleDecRef(sim)); } }