ebiten icon indicating copy to clipboard operation
ebiten copied to clipboard

audio: hiss with 44.1kHz audio

Open tinne26 opened this issue 2 years ago • 13 comments

Ebitengine Version

v2.6.3

Operating System

  • [X] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] FreeBSD
  • [ ] OpenBSD
  • [ ] Android
  • [ ] iOS
  • [ ] Nintendo Switch
  • [ ] PlayStation 5
  • [ ] Xbox
  • [ ] Web Browsers

Go Version (go version)

go1.21.1

What steps will reproduce the problem?

Playing a 44.1kHz audio file (tried both wav and ogg) on Ebitengine >=v2.6.0.

Example code (basic audio playback, requires placing an audio.wav file in the same directory containing some beautiful music):

package main

import "os"
import "github.com/hajimehoshi/ebiten/v2"
import "github.com/hajimehoshi/ebiten/v2/audio"
import "github.com/hajimehoshi/ebiten/v2/audio/vorbis"
import "github.com/hajimehoshi/ebiten/v2/audio/wav"

var _ vorbis.Stream // prevent compiler warnings
var _ wav.Stream    // prevent compiler warnings

type Game struct {}
func (self *Game) Layout(w, h int) (int, int) { return w, h }
func (self *Game) Update() error { return nil }
func (self *Game) Draw(*ebiten.Image) {}

func main() {
	const SampleRate = 44100
	
	// create audio context, load audio file and create infinite loop
	_ = audio.NewContext(SampleRate)
	reader, err := os.Open("audio.wav") // if ogg, change wav -> vorbis 2 lines below
	if err != nil { panic(err) }
	stream, err := wav.DecodeWithSampleRate(SampleRate, reader)
	if err != nil { panic(err) }
	loop := audio.NewInfiniteLoop(stream, stream.Length())

	// start player
	player, err := audio.NewPlayer(audio.CurrentContext(), loop)
	if err != nil { panic(err) }
	player.Play()

	// create game and whatever
	game := &Game{}
	err = ebiten.RunGame(game)
	if err != nil { panic(err) }
}

What is the expected result?

Beautiful music plays.

What happens instead?

Beautiful music with audible hiss plays.

Anything else you feel useful to add?

The issue doesn't exist on v2.5.10 and earlier, but starts happening at v2.6.0. I only tested on Windows 11, desktop. Notably, the issue is either non-existent or almost inaudible with 48kHz files, so the existing audio example on ebitengine isn't apparently affected by this.

Using a standard media player makes the audio sound indistinguishable from v2.5.0 playback, but when upgrading to v2.6.0 the hiss (high frequency noise) is introduced.

tinne26 avatar Nov 27 '23 17:11 tinne26

Does this happen with any audio files?

hajimehoshi avatar Nov 27 '23 17:11 hajimehoshi

Any audio files that are wav or ogg and 44.1kHz... and are not just silence.

tinne26 avatar Nov 27 '23 17:11 tinne26

Thanks. Is this Windows specific?

hajimehoshi avatar Nov 27 '23 18:11 hajimehoshi

I haven't tested on Linux, so I don't know.

tinne26 avatar Nov 27 '23 19:11 tinne26

I couldn't reproduce the issue. I used jump.ogg by converting the sample rate with sox command.

hajimehoshi avatar Nov 28 '23 04:11 hajimehoshi

Could you give me an audio file to reproduce this?

hajimehoshi avatar Nov 28 '23 04:11 hajimehoshi

Another question: does the audio have to be short enough to loop?

hajimehoshi avatar Nov 28 '23 04:11 hajimehoshi

Any audio file works, but if it's too short you might not notice the hiss. I tested with multiple different files. For example: https://file-examples.com/storage/fe19e15eac6560f8c936c41/2017/11/file_example_OOG_1MG.ogg (first result from googling "ogg example file"). I'll test later on another computer to double check.

tinne26 avatar Nov 28 '23 09:11 tinne26

I've tested on another computer and now I'm even more confused. I got the same problem, but the issue happened even on v2.5.0 and previous versions. So now I'm not sure it's a v2.6.0 change anymore (though on my current computer it only happens on >=v2.6.0, consistently).

Among the files that I've used, this is the one where the hiss is most clear (especially on the second main piano chord, and I recommend using headphones so it's easier to tell): back44.zip

tinne26 avatar Nov 28 '23 10:11 tinne26