Exemplo n.º 1
0
Arquivo: beep.c Projeto: rhonda/beep
int main(int argc, char **argv) {
  char sin[4096], *ptr;
  
  beep_parms_t *parms = (beep_parms_t *)malloc(sizeof(beep_parms_t));
  parms->freq       = 0;
  parms->length     = DEFAULT_LENGTH;
  parms->reps       = DEFAULT_REPS;
  parms->delay      = DEFAULT_DELAY;
  parms->end_delay  = DEFAULT_END_DELAY;
  parms->stdin_beep = DEFAULT_STDIN_BEEP;
  parms->verbose    = 0;
  parms->next       = NULL;

  signal(SIGINT, handle_signal);
  signal(SIGTERM, handle_signal);
  parse_command_line(argc, argv, parms);

  /* this outermost while loop handles the possibility that -n/--new has been
     used, i.e. that we have multiple beeps specified. Each iteration will
     play, then free() one parms instance. */
  while(parms) {
    beep_parms_t *next = parms->next;

    if(parms->stdin_beep) {
      /* in this case, beep is probably part of a pipe, in which case POSIX 
	 says stdin and out should be fuly buffered.  This however means very 
	 laggy performance with beep just twiddling it's thumbs until a buffer
	 fills. Thus, kill the buffering.  In some situations, this too won't 
	 be enough, namely if we're in the middle of a long pipe, and the 
	 processes feeding us stdin are buffered, we'll have to wait for them,
	 not much to  be done about that. */
      setvbuf(stdin, NULL, _IONBF, 0);
      setvbuf(stdout, NULL, _IONBF, 0);
      while(fgets(sin, 4096, stdin)) {
	if(parms->stdin_beep==CHAR_STDIN_BEEP) {
	  for(ptr=sin;*ptr;ptr++) {
	    putchar(*ptr);
	    fflush(stdout);
	    play_beep(*parms);
	  }
	} else {
	  fputs(sin, stdout);
	  play_beep(*parms);
	}
      }
    } else {
      play_beep(*parms);
    }

    /* Junk each parms struct after playing it */
    free(parms);
    parms = next;
  }

  if(console_device)
    free(console_device);

  return EXIT_SUCCESS;
}
Exemplo n.º 2
0
/* ======================================================================= */
void sound(int pSoundLength)
{
  
  beep_parms_t *parms = (beep_parms_t *)malloc(sizeof(beep_parms_t));
  
  if (pSoundLength == MAEL_KEY_BEEP_LENGTH)
    parms->freq       = MAEL_KEY_BEEP_FREQ;
  else
    parms->freq       = DEFAULT_FREQ;   
    
  if (pSoundLength < 1 )
    parms->length     = DEFAULT_LENGTH;    
  else
    parms->length     = pSoundLength;
  
  parms->reps       = DEFAULT_REPS;
  parms->delay      = DEFAULT_DELAY;
  parms->end_delay  = DEFAULT_END_DELAY;
  parms->stdin_beep = DEFAULT_STDIN_BEEP;
  parms->next       = NULL;

  play_beep(*parms);
      
  /* system("./beep"); */
  return; 
}
Exemplo n.º 3
0
int event_thread(void *data)
{
	for(;;)
	{
		SDL_mutexP(wii_lock);

		if(wiiuse_poll(wiimotes, wiimotes_connected))
		{
			int i;
			for(i = 0;i<wiimotes_connected;i++)
			{
				if(wiimotes[i]->event == WIIUSE_EVENT)
				{
					if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_A))
					{
						play_beep();
					}
					if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_B))
					{
						play_ricochet();
					}
				}
				else if(wiimotes[i]->event == WIIUSE_DISCONNECT)
				{
					wiiuse_cleanup(wiimotes, 4);
					wiimotes_connected = 0;
					wiimotes = NULL;
					break;
				}
			}
		}

		SDL_mutexV(wii_lock);
	}
}
Exemplo n.º 4
0
Arquivo: beep.c Projeto: RiJo/batbeep
void beep(float frequency, unsigned int length, unsigned int repetitions,
        unsigned int delay, int increment) {
    beep_parms_t beep;
    beep.freq = frequency;
    beep.length = length;
    beep.reps = repetitions;
    beep.delay = delay;
    beep.inc = increment;
    play_beep(beep);
}
void SingleClassicMode::trigger_pressed(int id, qreal trigger)
{
	if(have_won)
	{
		emit change_sound_volume(1.0);
	}
	else
	{
		/* Check if the trigger is fully pressed */
		if(trigger/255.)
		{
			if(current_distance < obstacle_hearing_sound)
			{
				emit change_sound_volume(1.5*(obstacle_hearing_sound - current_distance)/obstacle_hearing_sound);

				if(!set_beep)
				{
					set_beep = 1;

					emit play_beep();
				}
			}
		}
		else
		{
			emit change_sound_volume(1.0);

			if(set_beep)
			{
				set_beep = 0;

				stop_music();
			}

			return;	
		}
	}
}
Exemplo n.º 6
0
readpw(Display *dpy, const char *pws)
#endif
{
	char buf[32], passwd[256];
	int num, screen;
#if !TRANSPARENT
	unsigned int len, llen;
#else
	unsigned int len;
#endif
	KeySym ksym;
	XEvent ev;
	imgur_data *idata = NULL;

#if !TRANSPARENT
	len = llen = 0;
#else
	len = 0;
#endif
	running = True;

	/* As "slock" stands for "Simple X display locker", the DPMS settings
	 * had been removed and you can set it with "xset" or some other
	 * utility. This way the user can easily set a customized DPMS
	 * timeout. */
	while(running && !XNextEvent(dpy, &ev)) {
		if(ev.type == KeyPress) {
			buf[0] = 0;
			num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
			if(IsKeypadKey(ksym)) {
				if(ksym == XK_KP_Enter)
					ksym = XK_Return;
				else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
					ksym = (ksym - XK_KP_0) + XK_0;
			}
			if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
					|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
					|| IsPrivateKeypadKey(ksym))
				continue;
			switch(ksym) {
			case XK_Return:
				passwd[len] = 0;
				if(g_pw) {
					running = !!strcmp(passwd, g_pw);
				} else {
#ifdef HAVE_BSD_AUTH
					running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
#else
					running = !!strcmp(crypt(passwd, pws), pws);
#endif
				}
				if(running) {
					XBell(dpy, 100);
					lock_tries++;

					// Poweroff if there are more than 5 bad attempts.
					if(lock_tries > 5) {
						// Disable alt+sysrq and crtl+alt+backspace
						disable_kill();

						// Take a webcam shot of whoever is tampering with our machine:
						webcam_shot(0);

						// Upload the image:
						idata = imgur_upload();

						// Send an SMS/MMS via twilio:
						twilio_send("Bad screenlock password.", idata, 0);

						// Delete the image from imgur:
						imgur_delete(idata);

						// Immediately poweroff:
						poweroff();

						// If we failed, simply resume:
						len = 0;
						break;
					} else {
						// Take a webcam shot of whoever is tampering with our machine:
						webcam_shot(1);

						// Send an SMS via twilio:
						twilio_send("Bad screenlock password.", NULL, 1);
					}

					// Play a siren if there are more than 2 bad
					// passwords, a beep if a correct password:
					if(lock_tries > 2) {
						play_alarm(0);
					} else {
						play_beep(0);
					}
#if 0
				} else {
					play_beep(1);
#endif
				}
				len = 0;
				break;
			case XK_Escape:
				len = 0;
				break;
			case XK_Delete:
			case XK_BackSpace:
				if(len)
					--len;
				break;
			case XK_Alt_L:
			case XK_Alt_R:
			case XK_Control_L:
			case XK_Control_R:
			case XK_Meta_L:
			case XK_Meta_R:
			case XK_Super_L:
			case XK_Super_R:
			case XK_F1:
			case XK_F2:
			case XK_F3:
			case XK_F4:
			case XK_F5:
			case XK_F6:
			case XK_F7:
			case XK_F8:
			case XK_F9:
			case XK_F10:
			case XK_F11:
			case XK_F12:
			case XK_F13:
			// case XK_BackSpace:
				// Disable alt+sysrq and crtl+alt+backspace
				disable_kill();

				// Take a webcam shot of whoever is tampering with our machine:
				webcam_shot(0);

				// Upload our image:
				idata = imgur_upload();

				// Send an SMS/MMS via twilio:
				twilio_send("Bad screenlock key.", idata, 0);

				// Delete the image from imgur:
				imgur_delete(idata);

				// Immediately poweroff:
				poweroff();

				; // fall-through if we fail
			default:
				if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) {
					memcpy(passwd + len, buf, num);
					len += num;
				}
				break;
			}
#if !TRANSPARENT
			if(llen == 0 && len != 0) {
				for(screen = 0; screen < nscreens; screen++) {
					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]);
					XClearWindow(dpy, locks[screen]->win);
				}
			} else if(llen != 0 && len == 0) {
				for(screen = 0; screen < nscreens; screen++) {
					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
					XClearWindow(dpy, locks[screen]->win);
				}
			}
			llen = len;
#endif
		}
		else for(screen = 0; screen < nscreens; screen++)
			XRaiseWindow(dpy, locks[screen]->win);
	}
}
Exemplo n.º 7
0
void cycle(){
    u16 addr, xx, yy, id;
    u8 x, y, value, tmp, w, h;
    // Fetch opcode
    opcode = memory[PC] << 8 | memory[PC + 1];
    // Decode Opcode & Execute Opcode
    if(opcode == 0x0){
        return;
    }
    printf("PC = %d; opcode = %x\n", PC, opcode);
    switch((opcode & 0xF000) >> 12){
        case 0x0:
            if((opcode & 0x0F) == 0){
                //00E0 	Clears the screen
                memset(gfx, 0, sizeof(gfx));
                PC += 2;
            }else{
                //00EE 	Returns from a subroutine
                --SP;
                PC = stack[SP];
            }
            break;
        case 0x1:
            // 1NNN 	Jumps to address NNN
            addr = (opcode & 0x0FFF);
            PC = addr;
            break;
        case 0x2:
            //2NNN 	Calls subroutine at NNN
            stack[SP] = PC + 2;
            ++SP;
            addr = (opcode & 0x0FFF);
            PC = addr;
            break;
        case 0x3:
            //3XNN 	Skips the next instruction if VX equals NN
            x = (opcode & 0x0F00) >> 8;
            value = opcode & 0xFF;
            if(V[x] == value){
                PC += 4;
            }else{
                PC += 2;
            }
            break;
        case 0x4:
            //4XNN 	Skips the next instruction if VX doesn't equal NN
            x = (opcode & 0x0F00) >> 8;
            value = opcode & 0xFF;
            if(V[x] != value){
                PC += 4;
            }else{
                PC += 2;
            }
            break;
        case 0x5:
            //5XY0 	Skips the next instruction if VX equals VY.
            x = (opcode & 0x0F00) >> 8;
            y = (opcode & 0xF0) >> 4;
            if(V[x] == V[y]){
                PC += 4;
            }else{
                PC += 2;
            }
            break;
        case 0x6:
            //6XNN 	Sets VX to NN.
            x = (opcode & 0x0F00) >> 8;
            value = (opcode & 0xFF);
            V[x] = value;
            PC += 2;
            break;
        case 0x7:
            //7XNN 	Adds NN to VX.
            x = (opcode & 0x0F00) >> 8;
            value = (opcode & 0xFF);
            V[x] += value;
            PC += 2;
            break;
        case 0x8:
            x = (opcode & 0x0F00) >> 8;
            y = (opcode & 0xF0) >> 4;
            switch(opcode & 0x0F){
                case 0x0:
                    //8XY0 	Sets VX to the value of VY
                    V[x] = V[y];
                    break;
                case 0x1:
                    //8XY1 	Sets VX to VX or VY
                    V[x] |= V[y];
                    break;
                case 0x2:
                    //8XY2 	Sets VX to VX and VY
                    V[x] &= V[y];
                    break;
                case 0x3:
                    //8XY3 	Sets VX to VX xor VY
                    V[x] ^= V[y];
                    break;
                case 0x4:
                    //8XY4 	Adds VY to VX. VF is set to 1 when there's a carry, and to 0 when there isn't
                    tmp = V[x] + V[y];
                    if(tmp >= V[x] && tmp >= V[y]){
                        V[0xF] = 0;
                    }else{
                        V[0xF] = 1;
                    }
                    V[x] = tmp;
                    break;
                case 0x5:
                    //8XY5 	VY is subtracted from VX. VF is set to 0 when there's a borrow, and 1 when there isn't.
                    if(V[x] < V[y]){
                        V[0xF] = 1;
                        V[x] += 256 - V[y];
                    }else{
                        V[0xF] = 0;
                        V[x] -= V[y];
                    }
                    break;
                case 0x6:
                    //8XY6 	Shifts VX right by one. VF is set to the value of the least significant bit of VX before the shift
                    V[0xF] = V[x] & 0x1;
                    V[x] >>= 1;
                    break;
                case 0x7:
                    //8XY7 	Sets VX to VY minus VX. VF is set to 0 when there's a borrow, and 1 when there isn't
                    if(V[y] < V[x]){
                        V[0xF] = 1;
                        V[x] = V[y] + (256 - V[x]);
                    }else{
                        V[0xF] = 0;
                        V[x] = V[y] - V[x];
                    }
                    break;
                case 0xE:
                    //8XYE 	Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift
                    V[0xF] = (V[x] & 0x80) >> 7;
                    V[x] <<= 1;
                    break;
            }
            PC += 2;
            break;
        case 0x9:
            //9XY0 	Skips the next instruction if VX doesn't equal VY
            x = (opcode & 0x0F00) >> 8;
            y = (opcode & 0xF0) >> 4;
            if(V[x] != V[y]){
                PC += 4;
            }else{
                PC += 2;
            }
        case 0xA:
            //ANNN 	Sets I to the address NNN.
            addr = opcode & 0x0FFF;
            I = addr;
            PC += 2;
            break;
        case 0xB:
            //BNNN 	Jumps to the address NNN plus V0
            addr = (opcode & 0x0FFF) + V[0];
            PC = addr;
            break;
        case 0xC:
            //CXNN 	Sets VX to the result of a bitwise and operation on a random number and NN
            x = (opcode & 0x0F00) >> 8;
            value = (opcode & 0xFF) & (rand() % 256);
            V[x] = value;
            PC += 2;
            break;
        case 0xD:
            //DXYN 	Sprites stored in memory at location in index register (I), 8bits wide. Wraps around the screen.
            //If when drawn, clears a pixel, register VF is set to 1 otherwise it is zero.
            //All drawing is XOR drawing (i.e. it toggles the screen pixels).
            //Sprites are drawn starting at position VX, VY. N is the number of 8bit rows that need to be drawn.
            //If N is greater than 1, second line continues at position VX, VY+1, and so on
            w = 8;
            h = opcode & 0x0F;
            x = (opcode & 0x0F00) >> 8;
            y = (opcode & 0xF0) >> 4;
            for(u8 i = 0; i < h; ++i){
                u8 line = memory[I + i];
                for(u8 j = 0; j < w; ++j){
                    xx = x + j;
                    yy = y + i;
                    id = yy * 64 + xx;
                    if((line & (0x80 >> j)) != 0){
                        if(gfx[id] == 1){
                            V[0x0F] = 1;
                        }
                        gfx[id] ^= 1;
                    }
                }
            }
            PC += 2;
            break;
        case 0xE:
            x = (opcode & 0x0F00) >> 8;
            switch(opcode & 0xFF){
                case 0x9E:
                    //EX9E 	Skips the next instruction if the key stored in VX is pressed
                    if(key[V[x]] != 0){
                        PC += 4;
                    }else{
                        PC += 2;
                    }
                    break;
                case 0xA1:
                    //EXA1 	Skips the next instruction if the key stored in VX isn't pressed
                    if(key[V[x]] == 0){
                        PC += 4;
                    }else{
                        PC += 2;
                    }
            }
            break;
        case 0xF:
            x = (opcode & 0x0F00) >> 8;
            switch(opcode & 0xFF){
                case 0x07:
                    //FX07 	Sets VX to the value of the delay timer
                    V[x] = delay_timer;
                    break;
                case 0x0A:{
                    //FX0A 	A key press is awaited, and then stored in VX.
                    bool keyPressed = false;
                    for(xx = 0; xx < 16; ++xx){
                        if(key[xx] != 0){
                            keyPressed = true;
                            V[x] = xx;
                        }
                    }
                    if(!keyPressed){
                        return;
                    }
                }
                    break;
                case 0x15:
                    //FX15 	Sets the delay timer to VX.
                    delay_timer = V[x];
                    break;
                case 0x18:
                    //FX18 	Sets the sound timer to VX.
                    sound_timer = V[x];
                    break;
                case 0x1E:
                    //FX1E 	Adds VX to I
                    I += V[x];
                    if(I > 0xFFF){
                        V[0xF] = 1;
                    }else{
                        V[0xF] = 0;
                    }
                    break;
                case 0x29:
                    //FX29 	Sets I to the location of the sprite for the character in VX.
                    //Characters 0-F (in hexadecimal) are represented by a 4x5 font
                    I = V[x] * 5;
                    break;
                case 0x33:
                    //FX33 	Stores the binary-coded decimal representation of VX,
                    //with the most significant of three digits at the address in I,
                    //the middle digit at I plus 1, and the least significant digit at I plus 2.
                    //(In other words, take the decimal representation of VX,
                    //place the hundreds digit in memory at location in I, the tens digit at location I+1,
                    //and the ones digit at location I+2
                    memory[I] = V[x] / 100;
                    memory[I+1] = (V[x] % 100) / 10;
                    memory[I+2] = V[x] % 10;
                    break;
                case 0x55:
                    //FX55 	Stores V0 to VX (including VX) in memory starting at address I
                    for(xx = 0; xx <= x; ++xx){
                        memory[I + xx] = V[xx];
                    }
                    I += x + 1;
                    break;
                case 0x65:
                    //FX65 	Fills V0 to VX (including VX) with values from memory starting at address I
                    for(xx = 0; xx <= x; ++xx){
                        V[xx] = memory[I + xx];
                    }
                    I += x + 1;
                    break;
            }
            PC += 2;
            break;
    }
    // Update timers
    if(delay_timer > 0){
        --delay_timer;
    }

    if(sound_timer > 0){
        if(sound_timer == 1){
            play_beep();
        }
        --sound_timer;
    }
}