forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_fifo.go
53 lines (43 loc) · 1.29 KB
/
audio_fifo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package astiav
//#include <libavutil/audio_fifo.h>
import "C"
import "unsafe"
// https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavutil/audio_fifo.c#L37
type AudioFifo struct {
c *C.AVAudioFifo
}
func newAudioFifoFromC(c *C.AVAudioFifo) *AudioFifo {
if c == nil {
return nil
}
return &AudioFifo{c: c}
}
func AllocAudioFifo(sampleFmt SampleFormat, channels int, nbSamples int) *AudioFifo {
return newAudioFifoFromC(C.av_audio_fifo_alloc(C.enum_AVSampleFormat(sampleFmt), C.int(channels), C.int(nbSamples)))
}
func (a *AudioFifo) Realloc(nbSamples int) error {
return newError(C.av_audio_fifo_realloc(a.c, C.int(nbSamples)))
}
func (a *AudioFifo) Size() int {
return int(C.av_audio_fifo_size(a.c))
}
func (a *AudioFifo) Space() int {
return int(C.av_audio_fifo_space(a.c))
}
func (a *AudioFifo) Write(f *Frame) (int, error) {
ret := C.av_audio_fifo_write(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
return 0, err
}
return int(ret), nil
}
func (a *AudioFifo) Read(f *Frame) (int, error) {
ret := C.av_audio_fifo_read(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
return 0, err
}
return int(ret), nil
}
func (a *AudioFifo) Free() {
C.av_audio_fifo_free(a.c)
}