int main (void) {

    // Initialize the MCU
    Initialize();

    led_board(0);
    delay_ms(100);              // flash LEDs
    led_board(1);
    delay_ms(100);
    led_board(0);
    delay_ms(100);
    led_board(1);  
    
    synth_init();               // initialize synthesis
    
    synth_amp(255);             // full volume
    
    synth_freq(440);            // play 440 Hz for 2 seconds
    delay_ms(2000);             
    
    for (;;){                   
      
        synth_freq(200);        // play four notes over and over
        delay_ms(500);
        synth_freq(400);
        delay_ms(500);
        synth_freq(600); 
        delay_ms(500);
        synth_freq(800);
        delay_ms(500);
        
        
	} 
	
} // main()
Example #2
0
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
        return -1;
    atexit(SDL_Quit);

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

    SDL_Surface *screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL);
    if(!screen)
        return -1;

    if(glewInit() != GLEW_OK)
        return -1;

    audio_callback_userdata_t audio_callback_userdata;

    SDL_AudioSpec desired_audio_spec, obtained_audio_spec;
    desired_audio_spec.freq = 44100;
    desired_audio_spec.format = AUDIO_U16SYS;
    desired_audio_spec.channels = 1;
    desired_audio_spec.samples = 1024;
    desired_audio_spec.callback = audio_callback;
    desired_audio_spec.userdata = &audio_callback_userdata;

    if(SDL_OpenAudio(&desired_audio_spec, &obtained_audio_spec) != 0)
        return -1;
    atexit(SDL_CloseAudio);

    synth_t synth;
    synth_init(&synth, obtained_audio_spec.freq);

    audio_callback_userdata.synth = &synth;
    audio_callback_userdata.audiospec = obtained_audio_spec;

    SDL_PauseAudio(0);

    int err = main_loop(&synth);

    SDL_PauseAudio(1);

    synth_cleanup(&synth);

    SDL_CloseAudio();
    SDL_Quit();

    return err;
}
Example #3
0
int main(void) {
	/* Basic chip initialization is taken care of in SystemInit() called
	 * from the startup code. SystemInit() and chip settings are defined
	 * in the CMSIS system_<part family>.c file.
	 */

	/* Initialize 32-bit timer 0. TIME_INTERVAL is defined as 10mS */
	/* You may also want to use the Cortex SysTick timer to do this */
	init_timer32(0, TIME_INTERVAL);
	/* Enable timer 0. nOur interrupt handler will begin incrementing
	 * the TimeTick global each time timer 0 matches and resets.
	 */
	enable_timer32(0);

	/* Initialize GPIO (sets up clock) */
	GPIOInit();


	LPC_IOCON->R_PIO0_11 |= 1;

	/* Set LED port pin to output */
	GPIOSetDir(LED_PORT, LED_BIT, 1);




	synth_init();


	int i;
	for (i = 0; i < 6; i++) {
		synth_channels[i].freq = 100 * i;
		synth_channels[i].amp = 1 << (16 - i);
		synth_channels[i].func = SYNTH_SAW;
	}

	while (1) {
		int tmp = 500 * ADCValue[1]/512;
		for (i = 0; i < 6; i++)
			synth_channels[i].freq = tmp*(i+1);

	}
	while (1) /* Loop forever */
	{
		/* Each time we wake up... */
		/* Check TimeTick to see whether to set or clear the LED I/O pin */
		if ((timer32_0_counter % LED_TOGGLE_TICKS) < (LED_TOGGLE_TICKS / 2)) {
			GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);
		} else {
			GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		}
		/* Go to sleep to save power between timer interrupts */
		__WFI();
	}
}
Example #4
0
int main()
{

	// Peripheral initialisation
	I2C_init();
	LCD_init();
	LCD_write("Loading...");
	DEBUG_init();	
	
	// Function initialisation
	WAVE_init();
	synth_init();
	CAN_init();

	
	menu_display();	

	while (1)
	{
		menu_update();
	}
	
	// Keypad for synth debugging
	/*int down = 0;
	int key = -1;
	
	while(1)
	{
		key = KEYPAD_get_key();

		if ((key != -1) && !down)
		{
			int note = 69+key;
			synth_note_on(note_to_freq(note),1.0);
			LCD_write_int("%d",note_to_freq(note));
			down = 1;
		}
		if ((key == -1) && down)
		{
			synth_note_off(1.0);
			LCD_clear();
			down = 0;
		}
	}*/
	
	// Loop to allow interupts
	while(1);
	return(1);
	
}
Example #5
0
static int EMSCRIPTEN_KEEPALIVE playTune(int selectedTrack) {
	sActualSubsong= selectedTrack;

	reInitEngine();
	
    synth_init(sSampleRate);	
	initClockSpeed();
	initSampleBuffer();
	initC64Rom();
		
	// reset & init
	memcpy(memory, sMemorySnapshot, MEMORY_SIZE);		// restore original mem content.. previous "sInitAddr" run may have corrupted the state

	// CIA 1 defaults	(by default C64 is configured with CIA1 timer / not raster irq)
	setIO(0xdc0d, 0x81);	// interrupt control	(interrupt through timer A)
	setIO(0xdc0e, 0x01); 	// control timer A: start - must already be started (e.g. Phobia, GianaSisters, etc expect it)
	setIO(0xdc0f, 0x08); 	// control timer B (start/stop) means auto-restart
	setIO(0xdc04, sTotalCyclesPerScreen&0xff); 	// timer A (1x pro screen refresh)
	setIO(0xdc05, sTotalCyclesPerScreen>>8);
	
	if (isRsid()) {	
		// by default C64 is configured with CIA1 timer / not raster irq
		setIO(0xd01a, 0x00); 	// raster irq not active
		setIO(0xd011, 0x1B);
		setIO(0xd012, 0x00); 	// raster at line x

		// CIA 2 defaults
		setIO(0xdd0e, 0x08); 	// control timer 2A (start/stop)
		setIO(0xdd0f, 0x08); 	// control timer 2B (start/stop)		
	}
	
	setupInitMemoryBank();
		
	initCia();
	initVic();
	
	sOverflowDigiCount=0;	
	sDigiCount=0;
	
	hackIfNeeded();
	
	sMainProgStatus= callMain(sInitAddr, sActualSubsong, 0, CYCLELIMIT);		// if it does not complete then it is likely in an endless loop / maybe digi player
		
	initBuffers();
	setupPsidPlayMemoryBank();
	return 0;
}
Example #6
0
/*
 * This is called when a user requests to change synthesizers.
 */
static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr,
			   const char *buf, size_t count)
{
	int len;
	char new_synth_name[10];

	len = strlen(buf);
	if (len < 2 || len > 9)
		return -EINVAL;
	strncpy(new_synth_name, buf, len);
	if (new_synth_name[len - 1] == '\n')
		len--;
	new_synth_name[len] = '\0';
	spk_strlwr(new_synth_name);
	if (synth && !strcmp(new_synth_name, synth->name)) {
		pr_warn("%s already in use\n", new_synth_name);
	} else if (synth_init(new_synth_name) != 0) {
		pr_warn("failed to init synth %s\n", new_synth_name);
		return -ENODEV;
	}
	return count;
}
Example #7
0
int main(int argc, char **argv)
{
  int err;
#ifdef __APPLE__
  char *cfrespath;
  CFBundleRef mainBundle;
  CFURLRef res;
  CFStringRef respathref;
#endif

  // load config file from user's homedir
  dotfile_load();

  // calculate tables for supersaw
  calc_supersaw_tables();

  // init data on all pages to defaults
  synth_init();
  patch_init();
  pattern_init();
  sequencer_init();

  // init glut
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(DS_WIDTH,DS_HEIGHT);
  glutCreateWindow("komposter");
  glutIgnoreKeyRepeat(1);
  
  

#ifdef __APPLE__
  // get application bundle base path
  mainBundle=CFBundleGetMainBundle();
  res=CFBundleCopyBundleURL(mainBundle);
  respathref=CFURLCopyFileSystemPath(res, 0);
  cfrespath=(char*)CFStringGetCStringPtr(respathref, kCFStringEncodingISOLatin1);
  if (!cfrespath) {
    cfrespath=malloc(512);
    CFStringGetCString(respathref, cfrespath, 511, kCFStringEncodingISOLatin1);
    strncpy(respath, cfrespath, 511);
    free(cfrespath);
  } else {
    strncpy(respath, cfrespath, 511);  
  }
  strncat(respath, "/Contents/Resources/", 511); // append the resource dir
#else
#ifdef RESOURCEPATH
	if(is_dir(RESOURCEPATH))
	{
		strncpy(respath, RESOURCEPATH, 511);
	}
	else
	{
		fprintf(stderr, "'%s' not found, trying relative path\n", RESOURCEPATH);
		strncpy(respath, "resources/", 511);
	}
#else
  strncpy(respath, "resources/", 512);
#endif
#endif
  printf("Resource path is %s\n", respath);

  // init freetype
  err=font_init();
  if (!err) {
    printf("Error initializing Freetype!\n");
    return 0;
  }

  // set glut callbacks
  glutKeyboardFunc(keyboardfunc);
  glutKeyboardUpFunc(keyboardupfunc);
  glutMouseFunc(mouse_clickfunc);
  glutMotionFunc(mouse_dragfunc);
  glutSpecialFunc(specialkeyfunc);
  glutPassiveMotionFunc(mouse_hoverfunc);

  // init memory manager
  kmm_init();

  // set up screen and fire up the update timer
  cpage=MAIN_PAGE4;
  glutDisplayFunc(display);
  glutTimerFunc(20, update, 1);
  dialog_open(&about_draw, &about_hover, &about_click);

  // start audio and opengl mainloop
  atexit(cleanup);
  if (!audio_initialize()) {
    printf("Failed to initialize audio playback - sound is disabled.\n");
  } else {
    err = pthread_create(&audiothread, NULL, audio_playback, (void *)NULL);
  }
  err = pthread_create(&renderthread, NULL, audio_renderer, (void *)NULL);
  glutMainLoop();
  return 0;
}