Exemplo n.º 1
0
func play_music(music openal.Source) {
	file := "music" + slash + "1.wav"
	buffer := openal.NewBuffer()
	data, _ := ioutil.ReadFile(file)
	buffer.SetData(openal.FormatStereo16, data, 44100)
	music.SetBuffer(buffer)
	music.Play()
	for true {
		time.Sleep(1 * time.Second)
		if music.State() == openal.Stopped {
			buffer := openal.NewBuffer()
			last := ""
			switch len(tracklist) {
			case 1:
				file = tracklist[0]
				last = file
				tracklist = []string{"music" + slash + "1.wav", "music" + slash + "2.wav", "music" + slash + "3.wav"}
			default:
				i := randomInt(len(tracklist))
				file = tracklist[i]
				for file == last {
					i := randomInt(len(tracklist))
					file = tracklist[i]
				}
				tracklist = append(tracklist[:i], tracklist[i+1:]...)
			}
			data, _ := ioutil.ReadFile(file)
			buffer.SetData(openal.FormatStereo16, data, 44100)
			music.SetBuffer(buffer)
			music.Play()
		}
	}
}
Exemplo n.º 2
0
func (s *Stream) OnAudioPacket(e *gumble.AudioPacketEvent) {
	packet := e.AudioPacket
	samples := len(packet.PositionalAudioBuffer.AudioBuffer)
	if samples*2 > cap(s.buffer) {
		return
	}
	var source openal.Source
	if userSource, ok := s.userStreams[packet.Sender.Session]; !ok {
		source = openal.NewSource()
		s.userStreams[packet.Sender.Session] = source
	} else {
		source = userSource
	}

	for i, value := range packet.PositionalAudioBuffer.AudioBuffer {
		binary.LittleEndian.PutUint16(s.buffer[i*2:], uint16(value))
	}

	var buffer openal.Buffer
	for source.BuffersProcessed() > 0 {
		openal.DeleteBuffer(source.UnqueueBuffer())
	}
	buffer = openal.NewBuffer()
	buffer.SetData(openal.FormatMono16, s.buffer[0:samples*2], gumble.AudioSampleRate)
	source.QueueBuffer(buffer)

	if source.State() != openal.Playing {
		source.Play()
	}
}
Exemplo n.º 3
0
func (o *Options) events(music openal.Source) {
	if control.keys[VK_ESC] {
		o.active = 0
		storage.save_player()
		game.state = MENU
	}
	if control.keys[VK_ENTER] {
		if !control.enter_lock {
			control.enter_lock = true
			switch o.active {
			case 0:
				play_menu_click()
				game.music = !game.music
				if game.music {
					if !musicThread {
						go play_music(music)
						musicThread = true
					} else {
						music.Play()
					}
				} else {
					music.Pause()
				}
			case 1:
				play_menu_click()
				game.sound = !game.sound
			}
		}
	} else {
		control.enter_lock = false
	}
	if control.IsDownPressed() {
		if !control.down_lock {
			play_menu_click()
			control.down_lock = true
			o.active = 2
		}
	} else {
		control.down_lock = false
	}
	if control.IsUpPressed() {
		if !control.up_lock {
			play_menu_click()
			control.up_lock = true
			o.active = 0
		}
	} else {
		control.up_lock = false
	}
	if control.IsLeftPressed() {
		if !control.left_lock {
			control.left_lock = true
			switch o.active {
			case 2:
				if plane.boost != 5 {
					plane.boost--
					play_menu_click()
				}
			default:
				if o.active != 0 {
					play_menu_click()
				}
				o.active = 0
			}
		}
	} else {
		control.left_lock = false
	}
	if control.IsRightPressed() {
		if !control.right_lock {
			control.right_lock = true
			switch o.active {
			case 2:
				if plane.boost != 15 {
					plane.boost++
					play_menu_click()
				}
			default:
				if o.active != 1 {
					play_menu_click()
				}
				o.active = 1
			}

		}
	} else {
		control.right_lock = false
	}
}