dsound

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufferSize

func BufferSize() uint

BufferSize returns the size in bytes of the sound buffer that you write to with WriteToSoundBuffer. When DirectSound is not initialized this value is 0.

func Close

func Close()

Close releases all resources that were allocated when initializing DirectSound. It will stop playing the sound, if any.

func GetPlayAndWriteCursors

func GetPlayAndWriteCursors() (play, write uint, err error)

GetPlayAndWriteCursors returns the play and write cursors. These are byte offsets into the sound buffer. The range between the two is commited to the sound card for playing so it is not safe to write into that area. According to the DirectSound documentation this area is usually about 15ms worth of data but a test on Windows 8.1 showed a value of 30ms. Note that the sound buffer is a ring buffer which is why the play cursor, which indicates the start of the commited region, can be a higher value than the write cursor, which indicates the end of the commited region. In the non-border case the play cursor will be less than the write cursor. You can safely write sound data starting at the write cursor and ending at the play cursor.

func Init

func Init(samplesPerSecond int) error

Init sets up DirectSound and creates a sound buffer with 2 channels, 16 bit samples and the given sample frequency. The buffer is not played until you call StartSound. Make sure to call Close when you are done with DirectSound.

func StartSound

func StartSound() error

StartSound must be called after initialization to make the sound buffer audible. It will internally call Play on the DirectSound buffer with the looping option so the sound plays forever (until you call StopSound).

func StopSound

func StopSound() error

StopSound stops playing the sound buffer.

func WriteToSoundBuffer

func WriteToSoundBuffer(data []byte, offset uint) error

WriteToSoundBuffer locks the sound buffer and writes the given data into it, starting at the given byte offset. The buffer is a ring buffer so writing outside the bounds will wrap around and continue writing to the beginning.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL