You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is one last usage of the unsafe package. It would be pretty cool to get rid of it :)
The Unsafe Pointer
In l3subband.go, pointer arithmetic is used in windowFilterSubband:
func (enc*Encoder) windowFilterSubband(buffer**int16, s*[SUBBAND_LIMIT]int32, chint64, strideint64) {
y:=make([]int32, 64)
ptr:=*buffer// replace 32 oldest samples with 32 new samplesfori:=int64(31); i>=0; i-- {
enc.subband.X[ch][i+enc.subband.Off[ch]] =int32(*ptr) <<16ptr= (*int16)(unsafe.Add(unsafe.Pointer(ptr), unsafe.Sizeof(int16(0))*uintptr(stride)))
}
*buffer=ptr// Rest of function
The most straightforward thing to do is pass a 2d array instead of a double pointer, and that requires a type change in the Encoder struct and a couple other function edits:
// l3mdct.gofork:=0; k<18; k+=2 {
enc.windowFilterSubband(&enc.buffer[ch], &enc.l3SubbandSamples[ch][gr+1][k], ch, stride)
enc.windowFilterSubband(&enc.buffer[ch], &enc.l3SubbandSamples[ch][gr+1][k+1], ch, stride)
// Compensate for inversion in the analysis filter// (every odd index of band AND k)forband:=1; band<32; band+=2 {
enc.l3SubbandSamples[ch][gr+1][k+1][band] *=-1
}
}
// types.gotypeEncoderstruct {
buffer [MAX_CHANNELS]*int16
}
// layer3.gofunc (enc*Encoder) EncodeBufferInterleaved(data []int16) ([]uint8, int) {
enc.buffer[0] =&data[0]
ifenc.Wave.Channels==2 {
enc.buffer[1] =&data[1]
}
returnenc.encodeBufferInternal(int(enc.Wave.Channels))
}
I've tried the following types for buffer:
buffer [MAX_CHANNELS][]int16
buffer *[MAX_CHANNELS][]int16
The odd and interesting thing is this simple change drastically changes the quality of the encoded file. I've heard weird things:
Good quality, but noticeably lower volume
High pitch scratching mixed with music
Low garbled noises mixed with music
Screeching garbage
And everything in between 😵💫
The text was updated successfully, but these errors were encountered:
There is one last usage of the
unsafe
package. It would be pretty cool to get rid of it :)The Unsafe Pointer
In
l3subband.go
, pointer arithmetic is used inwindowFilterSubband
:The most straightforward thing to do is pass a 2d array instead of a double pointer, and that requires a type change in the Encoder struct and a couple other function edits:
I've tried the following types for
buffer
:buffer [MAX_CHANNELS][]int16
buffer *[MAX_CHANNELS][]int16
The odd and interesting thing is this simple change drastically changes the quality of the encoded file. I've heard weird things:
The text was updated successfully, but these errors were encountered: