netmd

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 License: MIT Imports: 13 Imported by: 0

README

go-netmd library

This is a study and re-implementation library of the linux-minidisc and the netmd-js project in to go language.

I tried to simplify most code in a 'go' manner so understanding the NetMD protocol will be a bit easier for the next person who will try and do the same :-)

Usage

go get github.com/enimatek-nl/go-netmd-lib

Example

In this example we send a stereo pcm file to the NetMD device concurrently.

md, err := netmd.NewNetMD(0, false)
if err != nil {
    log.Fatal(err)
}
defer md.Close()

track, err := md.NewTrack("My Song", "song.wav")
if err != nil {
    log.Fatal(err)
}

switch track.Format {
case netmd.WfPCM:
    log.Println("PCM detected")
case netmd.WfLP2:
    log.Println("LP2 detected")
}

c := make(chan netmd.Transfer)
go md.Send(track, c)

for{
    res, ok := <-c
    if !ok {
        break
    }
    if res.Error != nil {
        log.Fatal(res.Error)
    }
    switch res.Type {
    case netmd.TtSend:
        log.Printf("Transferred %d of %d bytes", res.Transferred, track.TotalBytes())
    case netmd.TtTrack:
        log.Printf("Created a new track # %d ", res.Track)
    }
}

TODO

The library has only been tested with my Sony MZ-NH600 and the Sharp IM-DR420.

Some functions (eg. groups parsing of titles) are not implemented yet.

Documentation

Index

Constants

View Source
const (
	EncSP  Encoding = 0x90
	EncLP2 Encoding = 0x92
	EncLP4 Encoding = 0x93

	ChanStereo Channels = 0x00
	ChanMono   Channels = 0x01

	ControlRejected Control = 0x0a
	ControlAccepted Control = 0x09
	ControlInterim  Control = 0x0f
	ControlStub     Control = 0x08

	TrackProtected   TrackProt = 0x03
	TrackUnprotected TrackProt = 0x00
)
View Source
const (
	WfPCM      WireFormat = 0x00
	WfLP2      WireFormat = 0x94
	WfLP4      WireFormat = 0xa8
	DfLP4      DiscFormat = 0
	DfLP2      DiscFormat = 2
	DfMonoSP   DiscFormat = 4
	DfStereoSP DiscFormat = 6
)

Variables

View Source
var (
	ByteArr16 = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
)
View Source
var (
	Devices = [...]Device{
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
		{/* contains filtered or unexported fields */},
	}
)
View Source
var (
	FrameSize = map[WireFormat]int{
		WfPCM: 2048,
		WfLP2: 192,
		WfLP4: 96,
	}
)

Functions

func DESDecrypt

func DESDecrypt(src, key []byte) ([]byte, error)

func DESEncrypt

func DESEncrypt(src, key []byte) ([]byte, error)

Types

type Channels

type Channels byte

type Control

type Control byte

type Device

type Device struct {
	// contains filtered or unexported fields
}

type DiscFormat

type DiscFormat int

type EKB

type EKB struct {
	// contains filtered or unexported fields
}

func NewEKB

func NewEKB() (e *EKB)

func (*EKB) CreateKey

func (ekb *EKB) CreateKey() (dataKey []byte)

func (*EKB) Key16to24

func (ekb *EKB) Key16to24() []byte

func (*EKB) RetailMAC

func (ekb *EKB) RetailMAC() ([]byte, error)

type Encoding

type Encoding byte

type Group

type Group struct {
	Title string
	Start int
	End   int
}

type NetMD

type NetMD struct {
	CDev *gousb.Device
	// contains filtered or unexported fields
}

func NewNetMD

func NewNetMD(index int, debug bool) (md *NetMD, err error)

func (*NetMD) Close

func (md *NetMD) Close()

func (*NetMD) EraseDisc

func (md *NetMD) EraseDisc() error

EraseDisc will erase the whole disc

func (*NetMD) EraseTrack

func (md *NetMD) EraseTrack(trk int) error

EraseTrack will erase the trk number starting from 0

func (*NetMD) MoveTrack

func (md *NetMD) MoveTrack(trk, to int) error

MoveTrack will move the trk number to a new position

func (*NetMD) NewTrack

func (md *NetMD) NewTrack(title string, fileName string) (trk *Track, err error)

func (*NetMD) RecordingParameters

func (md *NetMD) RecordingParameters() (encoding Encoding, channels Channels, err error)

RecordingParameters current default recording parameters set on the NetMD

func (*NetMD) RequestDiscCapacity

func (md *NetMD) RequestDiscCapacity() (recorded uint64, total uint64, available uint64, err error)

RequestDiscCapacity returns the totals in seconds

func (*NetMD) RequestDiscHeader

func (md *NetMD) RequestDiscHeader() (string, error)

RequestDiscHeader returns the raw title of the disc

func (*NetMD) RequestStatus

func (md *NetMD) RequestStatus() (disk bool, err error)

RequestStatus returns known status flags

func (*NetMD) RequestTrackCount

func (md *NetMD) RequestTrackCount() (c int, err error)

func (*NetMD) RequestTrackEncoding

func (md *NetMD) RequestTrackEncoding(trk int) (encoding Encoding, err error)

RequestTrackEncoding returns the Encoding of the trk starting from 0

func (*NetMD) RequestTrackFlag

func (md *NetMD) RequestTrackFlag(trk int) (flag TrackProt, err error)

func (*NetMD) RequestTrackLength

func (md *NetMD) RequestTrackLength(trk int) (duration uint64, err error)

RequestTrackLength returns the duration in seconds of the trk starting from 0

func (*NetMD) RequestTrackTitle

func (md *NetMD) RequestTrackTitle(trk int) (t string, err error)

RequestTrackTitle returns the raw title of the trk number starting from 0

func (*NetMD) Send

func (md *NetMD) Send(trk *Track, c chan Transfer)

Send will transmit the Track data encrypted (concurrent) to the NetMD the Transfer channel will receive different TransferType's so the process can be followed closely from a different process

func (*NetMD) SetDiscHeader

func (md *NetMD) SetDiscHeader(t string) error

SetDiscHeader will write a raw title to the disc

func (*NetMD) SetDiscTitle

func (md *NetMD) SetDiscTitle(t string) error

SetDiscTitle will write the disc title

func (*NetMD) SetTrackTitle

func (md *NetMD) SetTrackTitle(trk int, t string, isNew bool) (err error)

SetTrackTitle set the title of the trk number starting from 0, isNew can be be true if it's a newadded track

func (*NetMD) Wait

func (md *NetMD) Wait() error

Wait makes sure the device is truly finished, needed to prevent crashes on the SHARP IM-DR410/IM-DR420 and the Sony MZ-N420D

type Nonce

type Nonce struct {
	Host []byte
	Dev  []byte
}

func NewNonce

func NewNonce() (n *Nonce)

func (*Nonce) Merged

func (n *Nonce) Merged() []byte

type Packet

type Packet struct {
	// contains filtered or unexported fields
}

type Root

type Root struct {
	Title  string
	Groups []*Group
}

func NewRoot

func NewRoot(raw string) (fs *Root)

func (*Root) AddGroup

func (fs *Root) AddGroup(title string, start, end int) *Group

func (*Root) SearchGroup

func (fs *Root) SearchGroup(trk int) *Group

SearchGroup will return the group of the trk number starting from 0 it belongs to or nil if none matched. the Group will contain non-zero based indexes of the tracks (0->1)

func (*Root) ToString

func (fs *Root) ToString() string

type Track

type Track struct {
	Title      string
	Format     WireFormat
	DiscFormat DiscFormat
	Frames     int
	Padding    int
	Packets    []*Packet
	// contains filtered or unexported fields
}

func (*Track) TotalBytes

func (trk *Track) TotalBytes() int

type TrackProt

type TrackProt byte

type Transfer

type Transfer struct {
	Type        TransferType
	Track       int
	Transferred int
	Error       error
}

type TransferType

type TransferType string
const (
	TtSetup TransferType = "setup"
	TtSend  TransferType = "send"
	TtPoll  TransferType = "poll"
	TtTrack TransferType = "track"
)

type WireFormat

type WireFormat byte

Jump to

Keyboard shortcuts

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