Example #1
0
func (disp *UnscaledDisplay) renderBorder(events []spectrum.BorderEvent) {
	if !spectrum.SameBorderEvents(disp.border, events) {
		if len(events) > 0 {
			firstEvent := &events[0]
			spectrum.Assert(firstEvent.TState == 0)

			lastEvent := &events[len(events)-1]
			spectrum.Assert(lastEvent.TState == spectrum.TStatesPerFrame)

			numEvents := len(events)

			for i := 0; i < numEvents-1; i++ {
				disp.renderBorderBetweenTwoEvents(events[i], events[i+1])
			}

			disp.changedRegions.addBorder( /*scale*/ 1)
		}

		disp.border = events
	}
}
Example #2
0
// Render border in the interval [start,end)
func (disp *UnscaledDisplay) renderBorderBetweenTwoEvents(start spectrum.BorderEvent, end spectrum.BorderEvent) {
	spectrum.Assert(start.TState < end.TState)

	const DISPLAY_START = spectrum.DISPLAY_START
	const TSTATES_PER_LINE = spectrum.TSTATES_PER_LINE

	if start.TState < DISPLAY_START {
		start.TState = DISPLAY_START
	}
	if end.TState-1 < DISPLAY_START {
		return
	}
	if start.TState >= DISPLAY_START+spectrum.TotalScreenHeight*TSTATES_PER_LINE {
		return
	}

	start_y := (start.TState - DISPLAY_START) / TSTATES_PER_LINE
	end_y := (end.TState - 1 - DISPLAY_START) / TSTATES_PER_LINE

	start_x := (start.TState - DISPLAY_START) % TSTATES_PER_LINE
	end_x := (end.TState - 1 - DISPLAY_START) % TSTATES_PER_LINE

	start_x = (start_x << spectrum.PIXELS_PER_TSTATE_LOG2) &^ 7
	end_x = (end_x << spectrum.PIXELS_PER_TSTATE_LOG2) &^ 7
	end_x += 7

	// Clip to visible screen area
	{
		if end_y >= spectrum.TotalScreenHeight {
			end_x = spectrum.TotalScreenWidth - 1
			end_y = spectrum.TotalScreenHeight - 1
		}
	}

	// Fill scanlines from (start_x,start_y) to (end_x,end_y)
	color := start.Color
	if start_y == end_y {
		y := start_y
		disp.scanlineFill(start_x, end_x, y, color)
	} else {
		// Top scanline (start_y)
		disp.scanlineFill(start_x, spectrum.TotalScreenWidth-1, start_y, color)

		// Scanlines (start_y+1) ... (end_y-1)
		for y := (start_y + 1); y < end_y; y++ {
			disp.scanlineFill(0, spectrum.TotalScreenWidth-1, y, color)
		}

		// Bottom scanline (end_y)
		disp.scanlineFill(0, end_x, end_y, color)
	}
}
Example #3
0
func (audio *SDLAudio) render(audioData *spectrum.AudioData) {
	var events []spectrum.BeeperEvent

	if len(audioData.BeeperEvents) > 0 {
		var firstEvent *spectrum.BeeperEvent = &audioData.BeeperEvents[0]
		spectrum.Assert(firstEvent.TState == 0)

		var lastEvent *spectrum.BeeperEvent = &audioData.BeeperEvents[len(audioData.BeeperEvents)-1]
		spectrum.Assert(lastEvent.TState == spectrum.TStatesPerFrame)

		events = audioData.BeeperEvents
	} else {
		events = make([]spectrum.BeeperEvent, 2)
		events[0] = spectrum.BeeperEvent{TState: 0, Level: 0}
		events[1] = spectrum.BeeperEvent{TState: spectrum.TStatesPerFrame, Level: 0}
	}

	/*
		// A test signal
		const D = spectrum.TStatesPerFrame/128
		events = make([]spectrum.BeeperEvent, spectrum.TStatesPerFrame/D+1)
		for i:=uint(0); i<128; i++ {
			events[i] = spectrum.BeeperEvent{TState: i*D, Level: uint8(i%2)}
		}
		events[len(events)-1] = spectrum.BeeperEvent{TState: spectrum.TStatesPerFrame, Level: 0}
	*/

	numEvents := len(events)

	spread := float64(audio.freq) / RESPONSE_FREQUENCY
	spread1 := 1 / spread

	var numSamples int
	var samples []float64
	var samples_int16 []int16
	var overflow []float64
	{
		audio.mutex.Lock()

		numSamples_float := float32(audio.virtualFreq) / audioData.FPS
		numSamples = int(numSamples_float)

		len_overflow := int(math.Ceil(spread)) + 2

		audio.numSamples_cummulativeFraction += numSamples_float - float32(numSamples)
		if audio.numSamples_cummulativeFraction >= 1.0 {
			numSamples += 1
			audio.numSamples_cummulativeFraction -= 1.0
		}

		if len(audio.samples) < numSamples+len_overflow {
			audio.samples = make([]float64, numSamples+len_overflow)
		}
		samples = audio.samples

		if len(audio.samples_int16) < numSamples {
			audio.samples_int16 = make([]int16, numSamples)
		}
		samples_int16 = audio.samples_int16

		if len(audio.overflow) < len_overflow {
			new_overflow := make([]float64, len_overflow)
			copy(new_overflow, overflow)
			audio.overflow = new_overflow
		}
		overflow = audio.overflow

		audio.mutex.Unlock()
	}

	var k float64 = float64(numSamples) / spectrum.TStatesPerFrame

	{
		for i := 0; i < len(samples); i++ {
			samples[i] = 0
		}

		copy(samples[:], overflow[:])

		for i := 0; i < numEvents-1; i++ {
			start := events[i]
			end := events[i+1]

			level := float64(spectrum.Audio16_Table[start.Level])

			var position0 float64 = float64(start.TState) * k
			var position1 float64 = float64(end.TState) * k

			if audio.hqAudio {
				add_hq(samples, position0+1, position1-position0, level, spread, spread1)
			} else {
				add_lq(samples, position0+1, position1-position0, level)
			}
		}

		copy(overflow[:], samples[numSamples:])
	}

	for i := 0; i < numSamples; i++ {
		const VOLUME_ADJUSTMENT = 0.5
		samples_int16[i] = int16(VOLUME_ADJUSTMENT * samples[i])
	}

	audio.frame++
	sdl_audio.SendAudio_int16(samples_int16[0:numSamples])
}