KOS example using new maple system?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1808
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has liked: 0
Been liked: 0
Contact:

KOS example using new maple system?

Post by GyroVorbis » Fri Aug 05, 2005 11:06 am

Apparently, I've been using an outdated system. Thanks to BlueCrab, I've been set straight. The only problem is, I seem to not be getting input. Is there a KOS example that I can check against my code to see what I'm not doing/doing wrong?
Elysian Shadows - "Next-Gen" 2D/3D RPG coming to Sega Dreamcast, Steam, OUYA, and Smartphones
Image
http://www.elysianshadows.com
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5370
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 0
Been liked: 0
Contact:

Post by BlueCrab » Fri Aug 05, 2005 11:11 am

Hold on a sec.... lemme get one together....

Code: Select all

/* Microphone test program */

#include <kos.h>
#include <dc/maple/sip.h>

void draw_string(const char *str, int o)	{
	bfont_draw_str(vram_s + o, 640, 0, str);
}

void blank_screen()	{
	int i;
	for(i = 0; i < 640 * 480; i++)	{
		vram_s[i] = 0x00f;
	}
}

int main(int argc, char *argv[])	{
	maple_device_t *sip, *cont;
	cont_state_t *cont_state;
	sip_state_t *sip_state;
	int is_sampling = 0;

	sip = maple_enum_type(0, MAPLE_FUNC_MICROPHONE);
	cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

	if(sip == NULL)	{
		printf("cannot find mic\n");
		return -1;
	}

	printf("Got a mic!\n");

	sip_set_gain(sip, 0x1F);
	printf("set gain\n");

	while(1)	{
		cont_state = (cont_state_t *) maple_dev_status(cont);
		sip_state = (sip_state_t *) maple_dev_status(sip);

		if(cont_state)	{
			if(cont_state->buttons & CONT_Y)	{
				if(!is_sampling)	{
					printf("starting sampling\n");
					sip_start_sampling(sip);
					printf("sampling started\n");
					is_sampling = 1;
				}
			}
			else	{
				if(is_sampling)	{
					printf("stopping sampling\n");
					sip_stop_sampling(sip);
					printf("sampling stopped\n");
					is_sampling = 0;
				}
			}

			if(cont_state->buttons & CONT_A)	{
				if(!is_sampling)	{
					FILE *fp = fopen("/pc/rawout.raw", "wb");
					fwrite(sip_state->samples_buf, 1, sip_state->buf_pos, fp);
					fclose(fp);
					printf("Wrote %d bytes\n", sip_state->buf_pos);
					thd_sleep(1000);
					sip_clear_samples(sip);
				}
			}

			if(cont_state->buttons & CONT_START)	{
				break;
			}
		}
	}
	return 0;
}
Pay no attention to the oddness of the program, it kinda demonstrates the use of the Microphone Driver. Other than that, I think its mostly self explanitory. (And yes, I know that the two functions at the top aren't used, don't bug me about that)
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1808
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has liked: 0
Been liked: 0
Contact:

Post by GyroVorbis » Fri Aug 05, 2005 1:25 pm

Thanks Crabby. It works fine now.

Now to make some sort of maraca.h so I don't have to keep doing stuff like this:

Code: Select all

    if(Input[0].joyy < 255 && Input[0].joyy > 175 && Input[0].b && Input[0].joyx > 178) circle[5].shake = 1;
    else if (Input[0].joyy < 255 && Input[0].joyy > 175 && Input[0].b && Input[0].joyx <= 178) circle[4].shake = 1;
Elysian Shadows - "Next-Gen" 2D/3D RPG coming to Sega Dreamcast, Steam, OUYA, and Smartphones
Image
http://www.elysianshadows.com
Post Reply