예제 #1
0
int main(int argc, char** args) {
	try { //capture any errors.
		audio_io::initialize();
		audio_io::getLogger()->setLoggingCallback([] (logger_singleton::LogMessage &msg) {
			printf("Log: %s: %s\n", msg.topic.c_str(), msg.message.c_str());
		});
		audio_io::getLogger()->setLoggingLevel(logger_singleton::LoggingLevel::DEBUG);
		if(argc != 7) {
			printf("Usage: output <channels> <sr> <block_size> <minLatency> <startLatency> <maxLatency>\n");
			return 0;
		}
		sscanf(args[1], "%i", &channels);
		sscanf(args[2], "%i", &sr);
		sscanf(args[3], "%i", &block_size);
		sscanf(args[4], "%f", &min_latency);
		sscanf(args[5], "%f", &start_latency);
		sscanf(args[6], "%f", &max_latency);
		printf("Playing with channels=%i, sr=%i, block_size=%i, min_latency=%f, start_latency=%f, max_latency=%f\n",
		channels, sr, block_size, min_latency, start_latency, max_latency);
		auto gen= SineGen(300.0);
		auto factory = audio_io::getOutputDeviceFactory();
		printf("Using factory: %s\n", factory->getName().c_str());
		auto dev = factory->createDevice(gen, -1, channels, sr, block_size, min_latency, start_latency, max_latency);
		std::this_thread::sleep_for(std::chrono::milliseconds(5000));
		//We need to make sure the factory and the device die first.
		dev.reset();
		factory.reset();
		audio_io::shutdown();
	}
	catch(std::exception &e) {
		printf("Exception: %s\n", e.what());
	}
}
uint32_t AudioVIBSPKVsgGen::Process(uint32_t size, void *buffer, uint16_t channels, uint8_t rampcontrol, int32_t gain)
{
   uint32_t I;
   int16_t mr1, ar, vsg_temp_stat, temp_out;
   int32_t outputsample, vsg_temp_phase;
   int16_t *ptr16 = (int16_t*)buffer;
   
   if(mRampControl != rampcontrol)
   {
      if(rampcontrol == 0 || rampcontrol == 1)
         mGain = gain;
      else if(rampcontrol == 2)
         mGain = 0;
      mRampControl = rampcontrol;
   }

   for( I = 0; I < size; I++ )
   {
      mMod_Phase += mMod_PhaseInc;
      
      if( mMod_Phase  > ((1 << VSG_PHASE_BITS) - 1) ) 
      {
         mMod_PhaseStat += mMod_Phase >> VSG_PHASE_BITS;
         mMod_PhaseStat &= 0x3;
         mMod_Phase &= ((1 << VSG_PHASE_BITS) - 1);
      }
      
      ar = SineGen(mMod_Phase, mMod_PhaseStat);     
      mr1 = (int16_t)((int32_t)ar * mMod_Idx >> 15);
      
      mCenter_Phase += mCenter_PhaseInc;
      if( mCenter_Phase > ((1 << VSG_PHASE_BITS) - 1)) 
      {
         mCenter_PhaseStat += mCenter_Phase >> VSG_PHASE_BITS;
         mCenter_PhaseStat &= 0x3;
         mCenter_Phase &= ((1 << VSG_PHASE_BITS) - 1);
      }