--- linuxsampler/trunk/src/linuxsampler.cpp 2004/12/25 21:58:58 328 +++ linuxsampler/trunk/src/linuxsampler.cpp 2005/03/05 07:27:48 425 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -24,6 +25,7 @@ #include #include "Sampler.h" +#include "engines/EngineFactory.h" #include "drivers/midi/MidiInputDeviceFactory.h" #include "drivers/audio/AudioOutputDeviceFactory.h" #include "engines/gig/Profiler.h" @@ -36,6 +38,7 @@ Sampler* pSampler = NULL; LSCPServer* pLSCPServer = NULL; pthread_t main_thread; +bool bPrintStatistics = false; bool profile = false; bool tune = true; @@ -71,18 +74,34 @@ dmsg(1,("LinuxSampler %s\n", VERSION)); dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n")); + dmsg(1,("Copyright (C) 2005 Christian Schoenebeck\n")); if (tune) { - // detect and print system / CPU specific features - String sFeatures; - Features::detect(); + // detect and print system / CPU specific features + String sFeatures; + Features::detect(); #if ARCH_X86 - if (Features::supportsMMX()) sFeatures += " MMX"; - if (Features::supportsSSE()) sFeatures += " SSE"; + if (Features::supportsMMX()) sFeatures += " MMX"; + if (Features::supportsSSE()) sFeatures += " SSE"; + if (Features::supportsSSE2()) { + sFeatures += " SSE2"; + + // enable denormals-are-zeros mode + int x; + __asm__ __volatile__ ( + "stmxcsr %0\n\t" + "movl %0, %%eax\n\t" + "orl $0x40, %%eax\n\t" + "movl %%eax, %0\n\t" + "ldmxcsr %0\n\t" + :: "m" (x) + : "%eax" + ); + } #endif // ARCH_X86 - if (!sFeatures.size()) sFeatures = " None"; - dmsg(1,("Detected features:%s\n",sFeatures.c_str())); + if (!sFeatures.size()) sFeatures = " None"; + dmsg(1,("Detected features:%s\n",sFeatures.c_str())); } // create LinuxSampler instance @@ -102,30 +121,63 @@ if (profile) { - dmsg(1,("Calibrating profiler...")); - gig::Profiler::Calibrate(); - gig::Profiler::Reset(); - dmsg(1,("OK\n")); + dmsg(1,("Calibrating profiler...")); + gig::Profiler::Calibrate(); + gig::Profiler::Reset(); + dmsg(1,("OK\n")); } printf("LinuxSampler initialization completed.\n"); - while(true) { - /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r", - pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax, - pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams()); - fflush(stdout);*/ + std::list rtEvents; + rtEvents.push_back(LSCPEvent::event_voice_count); + rtEvents.push_back(LSCPEvent::event_stream_count); + rtEvents.push_back(LSCPEvent::event_buffer_fill); + + while (true) { + if (bPrintStatistics) { + std::set engines = EngineFactory::EngineInstances(); + std::set::iterator itEngine = engines.begin(); + for (int i = 0; itEngine != engines.end(); itEngine++, i++) { + Engine* pEngine = *itEngine; + printf("Engine %d) Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d)\n", i, + pEngine->VoiceCount(), pEngine->VoiceCountMax(), + pEngine->DiskStreamCount(), pEngine->DiskStreamCountMax() + ); + fflush(stdout); + } + } + sleep(1); if (profile) { - unsigned int samplingFreq = 48000; //FIXME: hardcoded for now - unsigned int bv = gig::Profiler::GetBogoVoices(samplingFreq); - if (bv != 0) - { - printf(" BogoVoices: %i \r", bv); - fflush(stdout); - } + unsigned int samplingFreq = 48000; //FIXME: hardcoded for now + unsigned int bv = gig::Profiler::GetBogoVoices(samplingFreq); + if (bv != 0) + { + printf(" BogoVoices: %i \r", bv); + fflush(stdout); + } } + + if (LSCPServer::EventSubscribers(rtEvents)) + { + LSCPServer::LockRTNotify(); + std::map channels = pSampler->GetSamplerChannels(); + std::map::iterator iter = channels.begin(); + for (; iter != channels.end(); iter++) { + SamplerChannel* pSamplerChannel = iter->second; + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) continue; + Engine* pEngine = pEngineChannel->GetEngine(); + if (!pEngine) continue; + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, iter->first, pEngine->VoiceCount())); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, iter->first, pEngine->DiskStreamCount())); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, iter->first, pEngine->DiskStreamBufferFillPercentage())); + } + LSCPServer::UnlockRTNotify(); + } + } return EXIT_SUCCESS; @@ -189,11 +241,16 @@ {"version",0,0,0}, {"profile",0,0,0}, {"no-tune",0,0,0}, + {"statistics",0,0,0}, {0,0,0,0} }; while (true) { - res = getopt_long_only(argc, argv, "", long_options, &option_index); + /* + Stephane Letz : letz@grame.fr + getopt_long_only does not exist on OSX : replaced by getopt_long for now. + */ + res = getopt_long(argc, argv, "", long_options, &option_index); if(res == -1) break; if (res == 0) { switch(option_index) { @@ -203,6 +260,7 @@ printf("--version prints version information\n"); printf("--profile profile synthesis algorithms\n"); printf("--no-tune disable assembly optimization\n"); + printf("--statistics prints periodically statistics\n"); exit(EXIT_SUCCESS); break; case 1: // --version @@ -210,10 +268,13 @@ exit(EXIT_SUCCESS); break; case 2: // --profile - profile = true; + profile = true; break; case 3: // --no-tune - tune = false; + tune = false; + break; + case 4: // --statistics + bPrintStatistics = true; break; } }