apu

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CH_HOLD = 1 << 15
)

Variables

This section is empty.

Functions

func Panning

func Panning(pan uint8, in int32) (left, right int32)

1つの音を 2つの音(=左右のスピーカー)に分ける pan: 0..128 (0: 左100%右0%, 64: 両方のスピーカに50%, 128: 左0%右100%) in: 分ける前の音

Types

type APU

type APU struct {
	/*
		SOUNDCNT(0x0400_0500)
		bit:
			0-6:   音量(0: 無音, 127: 最大音量)
			8-9:   Left Output from    (0=Left Mixer, 1=Ch1, 2=Ch3, 3=Ch1+Ch3)
			10-11: Right Output from   (0=Right Mixer, 1=Ch1, 2=Ch3, 3=Ch1+Ch3)
			12:    Output Ch1 to Mixer (0=Yes, 1=No) (both Left/Right)
			13:    Output Ch3 to Mixer (0=Yes, 1=No) (both Left/Right)
			15:    Master Enable       (0=Off, 1=On)
	*/
	Ctrl     uint16
	Bias     uint16 // SOUNDBIAS(0x0400_0504)
	Channels [16]*Channel
	Capture  [2]*Capture
}

APU はARM7からしかアクセスできない (このパッケージのアドレス の アドレス空間は全てARM7のもの)

func New

func New(bus Bus) *APU

func (*APU) Read16

func (a *APU) Read16(addr uint32) uint16

func (*APU) Read32

func (a *APU) Read32(addr uint32) uint32

func (*APU) Read8

func (a *APU) Read8(addr uint32) uint8

func (*APU) Reset

func (a *APU) Reset()

func (*APU) Run

func (a *APU) Run(cycles33MHz int64) (lsample, rsample int16)

Step advances the APU by one sampling cycle, and returns the left and right samples. (sampling cycle is : 1/32768 sec)

func (*APU) Write16

func (a *APU) Write16(addr uint32, data uint16)

func (*APU) Write32

func (a *APU) Write32(addr uint32, data uint32)

func (*APU) Write8

func (a *APU) Write8(addr uint32, data uint8)

type Bus

type Bus interface {
	Read(width int, addr, flag uint32) uint32
	Write(width int, addr, data, _ uint32)
}

type Capture

type Capture struct {

	/*
		SNDCAPxCNT (0x0400_0508, 0x0400_0509)
		bit:
			0: Control of Associated Sound Channels (ANDed with Bit7)
			1: Capture Source Selection
			2: Capture Repeat        (0=Loop, 1=One-shot)
			3: モード (0=PCM16, 1=PCM8)
			7: Capture Start/Status  (0=Stop, 1=Start/Busy)
	*/
	Cnt     uint8
	Dad     uint32 // SNDCAPxDAD (0x0400_0510, 0x0400_0518)
	ByteLen uint32 // SNDCAPxLEN (0x0400_0514, 0x0400_051C)

	Pos int32 // バイト単位

	// キャプチャしたデータを格納するFIFO(チャンネルのFIFOとは別物)
	FIFO struct {
		Buf [4]uint32 // 16バイト, 満タンになると、 .Dad + .DadOffset に書き込まれるっぽいです

		Len  uint8 // FIFOに入っているデータサイズ(バイト単位)
		RPos uint8 // Bufの読み位置(0..3, Bufの読み取りはワード単位でしか行わない)
		WPos uint8 // Bufの書き位置(0..15, Bufの書き込みは 8bit か 16bit 単位で行うのでバイト単位)

		DadOffset uint32 // Dadに書き込む位置のオフセット(バイト単位)
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

func (*Capture) FlushFIFO

func (c *Capture) FlushFIFO()

FlushFIFO は FIFO のサンプルデータをメモリに書き込む

func (*Capture) Reset

func (c *Capture) Reset()

func (*Capture) Run

func (c *Capture) Run(cycles int64, sample int32)

cycles は基本1024固定

func (*Capture) WriteCTRL

func (c *Capture) WriteCTRL(data uint8)

type Channel

type Channel struct {

	/*
		SOUNDxCNT(0x0400_04x0)
		bit:
			0-6:   音量(0: 無音, 127: 最大音量)
			8-9:   Volume div (0: 1/1, 1: 1/2, 2: 1/4, 3: 1/16)
			15:    hold (0=Normal, 1=Hold last sample after one-shot sound)
			16-22: パン (0..127=左..右, 64: 両方のスピーカに50%); パンでは左右のスピーカに音を振り分ける度合いを指定する
			24-26: デューティ比 (0..7) ;HIGH=(N+1)*12.5%, LOW=(7-N)*12.5% (PSG only)
			27-28: リピートモード (0=Manual, 1=Loop Infinite, 2=One-Shot, 3=Prohibited)
			29-30: モード (0=PCM8, 1=PCM16, 2=ADPCM, 3=PSG(矩形波/ノイズ)); PSG(矩形波) は チャンネル8-13のみ、 PSG(ノイズ) は チャンネル14-15のみで使用可能
			31:    実行中かどうか
	*/
	Ctrl uint32

	Src     uint32 // SOUNDxSAD(0x0400_04x4)
	Tmr     uint16 // SOUNDxTMR(0x0400_04x8), 周波数を決定する
	LoopPos uint32 // SOUNDxPNT(0x0400_04xA), バイト単位でのループ位置
	Length  uint32 // SOUNDxLEN(0x0400_04xC), PCM音源のバイト単位での長さ; PSG/ノイズでは使用しない

	// チャンネルによって用途が異なる or 使われない
	Pos  int32 // PCM8, PCM16, ADPCMの再生位置, PSGの音量テーブルの位置
	LFSR uint16

	ADPCM struct {
		// contains filtered or unexported fields
	}

	// PCM音源を読み込むためのFIFO
	FIFO struct {
		Buf [8]uint32 // 32バイト
		Len uint8     // FIFOに入っているデータサイズ(バイト単位)
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

APU はARM7からしかアクセスできない (このパッケージのアドレス の アドレス空間は全てARM7のもの)

func (*Channel) Reset

func (c *Channel) Reset()

func (*Channel) Run

func (c *Channel) Run(cycles int64)

cycles は基本1024固定

func (*Channel) WriteCTRL

func (c *Channel) WriteCTRL(data uint32)

Jump to

Keyboard shortcuts

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