Example #1
0
static void tms36xx_sound_update(int param, INT16 *buffer, int length)
{
	struct TMS36XX *tms = tms36xx[param];
	int samplerate = tms->samplerate;

    /* no tune played? */
	if( !tunes[tms->tune_num] || tms->voices == 0 )
	{
		while (--length >= 0)
			buffer[length] = 0;
		return;
	}

	while( length-- > 0 )
	{
		int sum = 0;

		/* decay the twelve voices */
		DECAY( 0) DECAY( 1) DECAY( 2) DECAY( 3) DECAY( 4) DECAY( 5)
		DECAY( 6) DECAY( 7) DECAY( 8) DECAY( 9) DECAY(10) DECAY(11)

		/* musical note timing */
		tms->tune_counter -= tms->speed;
		if( tms->tune_counter <= 0 )
		{
			int n = (-tms->tune_counter / samplerate) + 1;
			tms->tune_counter += n * samplerate;

			if( (tms->note_counter -= n) <= 0 )
			{
				tms->note_counter += VMAX;
				if (tms->tune_ofs < tms->tune_max)
				{
					/* shift to the other 'bank' of voices */
                    tms->shift ^= 6;
					/* restart one 'bank' of voices */
					RESTART(0) RESTART(1) RESTART(2)
					RESTART(3) RESTART(4) RESTART(5)
					tms->tune_ofs++;
				}
			}
		}

		/* update the twelve voices */
		TONE( 0) TONE( 1) TONE( 2) TONE( 3) TONE( 4) TONE( 5)
		TONE( 6) TONE( 7) TONE( 8) TONE( 9) TONE(10) TONE(11)

        *buffer++ = sum / tms->voices;
	}
}
Example #2
0
static STREAM_UPDATE( tms36xx_sound_update )
{
	tms_state *tms = (tms_state *)param;
	int samplerate = tms->samplerate;
	stream_sample_t *buffer = outputs[0];

    /* no tune played? */
	if( !tunes[tms->tune_num] || tms->voices == 0 )
	{
		while (--samples >= 0)
			buffer[samples] = 0;
		return;
	}

	while( samples-- > 0 )
	{
		int sum = 0;

		/* decay the twelve voices */
		DECAY( 0) DECAY( 1) DECAY( 2) DECAY( 3) DECAY( 4) DECAY( 5)
		DECAY( 6) DECAY( 7) DECAY( 8) DECAY( 9) DECAY(10) DECAY(11)

		/* musical note timing */
		tms->tune_counter -= tms->speed;
		if( tms->tune_counter <= 0 )
		{
			int n = (-tms->tune_counter / samplerate) + 1;
			tms->tune_counter += n * samplerate;

			if( (tms->note_counter -= n) <= 0 )
			{
				tms->note_counter += VMAX;
				if (tms->tune_ofs < tms->tune_max)
				{
					/* shift to the other 'bank' of voices */
                    tms->shift ^= 6;
					/* restart one 'bank' of voices */
					RESTART(0) RESTART(1) RESTART(2)
					RESTART(3) RESTART(4) RESTART(5)
					tms->tune_ofs++;
				}
			}
		}

		/* update the twelve voices */
		TONE( 0) TONE( 1) TONE( 2) TONE( 3) TONE( 4) TONE( 5)
		TONE( 6) TONE( 7) TONE( 8) TONE( 9) TONE(10) TONE(11)

        *buffer++ = sum / tms->voices;
	}
}
Example #3
0
void tms36xx_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
	int samplerate = m_samplerate;
	stream_sample_t *buffer = outputs[0];

	/* no tune played? */
	if( !tunes[m_tune_num] || m_voices == 0 )
	{
		while (--samples >= 0)
			buffer[samples] = 0;
		return;
	}

	while( samples-- > 0 )
	{
		int sum = 0;

		/* decay the twelve voices */
		DECAY( 0) DECAY( 1) DECAY( 2) DECAY( 3) DECAY( 4) DECAY( 5)
		DECAY( 6) DECAY( 7) DECAY( 8) DECAY( 9) DECAY(10) DECAY(11)

		/* musical note timing */
		m_tune_counter -= m_speed;
		if( m_tune_counter <= 0 )
		{
			int n = (-m_tune_counter / samplerate) + 1;
			m_tune_counter += n * samplerate;

			if( (m_note_counter -= n) <= 0 )
			{
				m_note_counter += TMS36XX_VMAX;
				if (m_tune_ofs < m_tune_max)
				{
					/* shift to the other 'bank' of voices */
					m_shift ^= 6;
					/* restart one 'bank' of voices */
					RESTART(0) RESTART(1) RESTART(2)
					RESTART(3) RESTART(4) RESTART(5)
					m_tune_ofs++;
				}
			}
		}

		/* update the twelve voices */
		TONE( 0) TONE( 1) TONE( 2) TONE( 3) TONE( 4) TONE( 5)
		TONE( 6) TONE( 7) TONE( 8) TONE( 9) TONE(10) TONE(11)

		*buffer++ = sum / m_voices;
	}
}
Example #4
0
/* Return the required voltage for a MIDI note number.
 * If the note number is negative, IDLE_VOLTS will be returned.
 * If the note number is out of range, it will be octave shifted
 * into range. If the range of the synthesizer is less than one octave,
 * and the note is not present in that octave, it will not be played. */
float note_voltage(int midinote){
	if(midinote < 0)return IDLE_VOLTS;
	if(midinote <= HIGH_MIDI &&
		midinote >= LOW_MIDI){ /* Simple case - we can play the note as-is. */
		return (midinote * M) + B;
	} else { /* Complicated case - octave shifting is needed. */
#if ((HIGH_MIDI - LOW_MIDI) + 1) < 12
		/* If the synthesizer cannot play a complete octave,
		 * notes that it cannot play will be ignored. */
		if(TONE(midinote) >= TONE(LOW_MIDI) && TONE(midinote) <= TONE(HIGH_MIDI)){
			midinote = LOW_MIDI - TONE(LOW_MIDI) + TONE(midinote);
			return (midinote * M) + B;
		} else {
			return IDLE_VOLTS;
		}
#else
		/* If the synthesizer can play a complete octave (or more),
		 * notes that are too high will be shifted to the top of its
		 * range, and notes that are too low will be shifted to the bottom
		 * of its range. */
		 if(midinote > HIGH_MIDI){
			if(TONE(midinote) > TONE(HIGH_MIDI)){
				midinote = HIGH_MIDI - 12 - TONE(HIGH_MIDI) + TONE(midinote);
			} else {
				midinote = HIGH_MIDI - TONE(HIGH_MIDI) + TONE(midinote);
			}
		 } else {
			if(TONE(midinote) < TONE(LOW_MIDI)){
				midinote = LOW_MIDI + 12 - TONE(LOW_MIDI) + TONE(midinote);
			} else {
				midinote = LOW_MIDI - TONE(LOW_MIDI) + TONE(midinote);
			}
		 }
		return (midinote * M) + B;
#endif
	}
}