fix: app crashed sometimes while converting qso in MP3
This commit is contained in:
@@ -32,6 +32,20 @@ func writeMP3(path string, pcm []byte) error {
|
|||||||
for i, v := range mono32 {
|
for i, v := range mono32 {
|
||||||
stereo[2*i], stereo[2*i+1] = v, v
|
stereo[2*i], stereo[2*i+1] = v, v
|
||||||
}
|
}
|
||||||
|
// Shine's Write() reads a WHOLE frame (samplesPerPass × channels = 1152 × 2 =
|
||||||
|
// 2304 interleaved samples for MPEG-1) per pass via unsafe pointer arithmetic,
|
||||||
|
// regardless of how short the trailing chunk is. If the buffer isn't an exact
|
||||||
|
// multiple of a frame, the final pass reads past the slice and the process
|
||||||
|
// dies with an access violation (0xc0000005) inside windowFilterSubband.
|
||||||
|
// Pad with trailing silence to a whole number of frames so no partial pass
|
||||||
|
// exists. (~36 ms of silence at most — inaudible.)
|
||||||
|
const frameInterleaved = 1152 * 2 // samplesPerPass(MPEG-1) × 2 channels
|
||||||
|
if rem := len(stereo) % frameInterleaved; rem != 0 {
|
||||||
|
stereo = append(stereo, make([]int16, frameInterleaved-rem)...)
|
||||||
|
}
|
||||||
|
if len(stereo) == 0 {
|
||||||
|
return nil // nothing to encode (empty recording)
|
||||||
|
}
|
||||||
enc := mp3.NewEncoder(mp3Rate, 2)
|
enc := mp3.NewEncoder(mp3Rate, 2)
|
||||||
return enc.Write(f, stereo)
|
return enc.Write(f, stereo)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user