Example #1
0
static int receive(struct sr_input *in, GString *buf)
{
	struct context *inc;
	int ret;

	g_string_append_len(in->buf, buf->str, buf->len);

	if (in->buf->len < MIN_DATA_CHUNK_OFFSET) {
		/*
		 * Don't even try until there's enough room
		 * for the data segment to start.
		 */
		return SR_OK;
	}

	inc = in->priv;
	if (!in->sdi_ready) {
		if ((ret = parse_wav_header(in->buf, inc)) == SR_ERR_NA)
			/* Not enough data yet. */
			return SR_OK;
		else if (ret != SR_OK)
			return ret;

		/* sdi is ready, notify frontend. */
		in->sdi_ready = TRUE;
		return SR_OK;
	}

	ret = process_buffer(in);

	return ret;
}
Example #2
0
static int format_match(GHashTable *metadata)
{
	GString *buf;
	int ret;

	buf = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_HEADER));
	if (strncmp(buf->str, "RIFF", 4))
		return SR_ERR;
	if (strncmp(buf->str + 8, "WAVE", 4))
		return SR_ERR;
	if (strncmp(buf->str + 12, "fmt ", 4))
		return SR_ERR;
	/*
	 * Only gets called when we already know this is a WAV file, so
	 * this parser can log error messages.
	 */
	if ((ret = parse_wav_header(buf, NULL)) != SR_OK)
		return ret;

	return SR_OK;
}
Example #3
0
int main(void) {
	FRESULT res;
	WORD br;

	sei(); // Globally enable interrupts

	hibernate_init();
	DAC_init();
	keys_init();

	if (pf_mount(&fs)) { sound_osch(); }
	else { sound_gut(); }

	while(1) {
		cli(); // disable interrupts to avoid race condition with sleep function
		if (FLAG_CHECK(NEW_SOUND)) {
			hibernate_timer_stop();
			FLAG_CLEAR(NEW_SOUND);
			sei();
			switch (special_mode) {
				case 1:
				if (new_sound_id == old_sound_id - 1) {
					special_mode = 2;
					goto sound_ende;
				} else if (new_sound_id == old_sound_id + 1) {
					special_mode = 4;
					goto sound_ende;
				} else if (new_sound_id == old_sound_id) {
					credits_counter = CREDITS_COUNTER_MAX - 5;
					special_mode = 0;
					goto sound_ende;
				} else special_mode = 0;
				break;
				case 2:
				special_mode = 3;
				break;
				case 4:
				special_mode = 5;
				break;
				default:
				special_mode = 0;
			}
			if (new_sound_id == 36) {
				special_mode = 1;
				goto sound_ende;
			}
			old_sound_id = new_sound_id;
			char* filename;
			if (++credits_counter > CREDITS_COUNTER_MAX) {
				credits_counter = 0;
				filename = "image.hex";
			} else {
				if (new_sound_id == 255) goto sound_ende;
				filename = filenames(bank, new_sound_id);
			}
			uint8_t tries = 3;
			while (pf_open(filename) && pf_open("error1.wav")) {
				if ((tries--) == 0) goto sound_ende;
				_delay_ms(10);
				pf_mount(&fs);
			}
			if (parse_wav_header()) {
				if (pf_open("error2.wav") || parse_wav_header()) goto sound_ende;
			}
			do {
				#define read_length 16384
				if (wavinfo.data_length > read_length) {
					res = pf_read(0, read_length, &br);
					wavinfo.data_length -= read_length;
				} else {
					res = pf_read(0, wavinfo.data_length, &br);
					break;
				}
			} while (res==0 && br==read_length && wavinfo.data_length>0 && !FLAG_CHECK(NEW_SOUND));
			stop_audio();
			sound_ende:
			hibernate_timer_init();
		} else {
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
		}
		hibernate_check();
	}
}