firmware/bell.c
uint16_t write_audio(const uint8_t* audio, uint16_t offset,
		uint16_t len, uint8_t is_ram, uint8_t loop) {
	/* Wait until the interrupt handler switches buffers */
	while(buffer_ready);

	/* Pick the buffer not being read */
	uint8_t buf_num = buffer_sel ? 0 : 1;
	uint16_t buf_rem = BUFFER_SZ;
	uint16_t buf_ptr = 0;
	uint16_t in_rem = len - offset;
	volatile uint8_t* out = pwm_buffer[buf_num];
	const uint8_t* in = &audio[offset];

	while(buf_rem && in_rem) {
		if (is_ram)
			*out = *in;
		else
			*out = pgm_read_byte(in);
		out++;
		buf_rem--;
		in++;
		in_rem--;
		if (loop && (!in_rem)) {
			in_rem = len;
			in = audio;
		}
	}
	/* Mark the buffer as ready */
	buffer_ready = 1;
	/* Return where we got to */
	return len - in_rem;
}
/* Write audio to the output buffer */
Write audio to the output buffer
Write audio to the output buffer
uint16_t write_audio(const uint8_t* audio, uint16_t offset,
		uint16_t len, uint8_t is_ram, uint8_t loop) {
	while(buffer_ready);
	uint8_t buf_num = buffer_sel ? 0 : 1;
	uint16_t buf_rem = BUFFER_SZ;
	uint16_t buf_ptr = 0;
	uint16_t in_rem = len - offset;
	volatile uint8_t* out = pwm_buffer[buf_num];
	const uint8_t* in = &audio[offset];
	while(buf_rem && in_rem) {
		if (is_ram)
			*out = *in;
		else
			*out = pgm_read_byte(in);
		out++;
		buf_rem--;
		in++;
		in_rem--;
		if (loop && (!in_rem)) {
			in_rem = len;
			in = audio;
		}
	}
	buffer_ready = 1;
	return len - in_rem;
}
uint16_t write_audio ( const uint8_t * audio , uint16_t offset , uint16_t len , uint8_t is_ram , uint8_t loop ) { while ( buffer_ready ) ; uint8_t buf_num = buffer_sel ? 0 : 1 ; uint16_t buf_rem = BUFFER_SZ ; uint16_t buf_ptr = 0 ; uint16_t in_rem = len - offset ; volatile uint8_t * out = pwm_buffer [ buf_num ] ; const uint8_t * in = & audio [ offset ] ; while ( buf_rem && in_rem ) { if ( is_ram ) * out = * in ; else * out = pgm_read_byte ( in ) ; out ++ ; buf_rem -- ; in ++ ; in_rem -- ; if ( loop && ( ! in_rem ) ) { in_rem = len ; in = audio ; } } buffer_ready = 1 ; return len - in_rem ; }
Write audio to the output buffer
Write audio to the output buffer
/* Wait until the interrupt handler switches buffers */ /* Pick the buffer not being read */ /* Mark the buffer as ready */ /* Return where we got to */