mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 02:34:42 +00:00
Stretch samples a bit better with the GBA's 32768Hz
This commit is contained in:
parent
6bb82b2204
commit
f54089e072
2 changed files with 9 additions and 5 deletions
|
|
@ -82,8 +82,9 @@ func DefaultOpus() (*opus.Encoder, error) {
|
|||
}
|
||||
|
||||
// frame calculates an audio stereo frame size, i.e. 48k*frame/1000*2
|
||||
// with round(x / 2) * 2 for the closest even number
|
||||
func frame(hz int, frame float32) int {
|
||||
return int(math.Round(float64(hz) * float64(frame) / 1000 * 2))
|
||||
return int(math.Round(float64(hz)*float64(frame)/1000/2) * 2 * 2)
|
||||
}
|
||||
|
||||
// stretch does a simple stretching of audio samples.
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ func TestBufferWrite(t *testing.T) {
|
|||
buf.write(samplesOf(w.sample, w.len), func(s samples) { lastResult = s })
|
||||
}
|
||||
if !reflect.DeepEqual(test.expect, lastResult) {
|
||||
t.Errorf("not expted buffer, %v != %v", lastResult, test.expect)
|
||||
t.Errorf("not expted buffer, %v != %v, %v", lastResult, test.expect, buf.s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -217,17 +217,20 @@ func samplesOf(v int16, len int) (s samples) {
|
|||
return
|
||||
}
|
||||
|
||||
func Test_frame(t *testing.T) {
|
||||
func TestFrame(t *testing.T) {
|
||||
type args struct {
|
||||
hz int
|
||||
frame int
|
||||
frame float32
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
}{
|
||||
{name: "mGBA", args: args{hz: 32768, frame: 10}, want: 654},
|
||||
{name: "mGBA", args: args{hz: 32768, frame: 10}, want: 656},
|
||||
{name: "mGBA", args: args{hz: 32768, frame: 5}, want: 328},
|
||||
{name: "mGBA", args: args{hz: 32768, frame: 2.5}, want: 164},
|
||||
{name: "nes", args: args{hz: 48000, frame: 2.5}, want: 240},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue