drum

package
v0.0.0-...-e04bdec Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Submission to go-challenge #1

See FAQ for more info about the go-challenge.

The goal of this challenge is to write a binary decoder that given a binary backup, outputs the same printouts as in the challenge defined. See http://golang-challenge.com/go-challenge1/ for full description.

Getting started

This example does not provide or generate any executable. To run the tests:

go test -v

Should return

=== RUN TestDecodeFile
--- PASS: TestDecodeFile (0.00s)
PASS
ok  	...

Assumptions and design decisions

  • File Format
|SPLICE (6 bytes)|Payload size (8 bytes)|                              => File Header
|Version (32 byte)| Tempo (4 bytes)|                                   => Pattern
|Id (4 bytes)|Name length (1 byte)| Name (n bytes)| Steps (16 bytes)|  => First Track
|Id (4 bytes)|Name length (1 byte)| Name (n bytes)| Steps (16 bytes)|  => Next Track
...
  • Files might be large. Therefore payload size uses 8 bytes (big endian) instead of empty bytes and smaller type in the header.
  • For simplicity Pattern.String() is used for the printout although this would be too verbose when used with logging.
  • The Pattern.String() implementation may not be as readable as a text/template but performed better in benchmarks.

Author

Documentation

Overview

Package drum is supposed to implement the decoding of .splice drum machine files. See golang-challenge.com/go-challenge1/ for more information

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedFileFormat = errors.New("unsupported file format")

ErrUnsupportedFileFormat is returned when the file to decode does not match the expected format.

Functions

This section is empty.

Types

type Pattern

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

Pattern is the high level representation of the drum pattern contained in a .splice file.

func DecodeFile

func DecodeFile(path string) (*Pattern, error)

DecodeFile decodes the drum machine file found at the provided path and returns a pointer to a parsed pattern which is the entry point to the rest of the data.

func (Pattern) String

func (p Pattern) String() string

String returns the Pattern in the printout format as a string.

type Steps

type Steps [stepsLength]bool

Steps are one of the parts of the measure that are being programmed (the programmed measure is known as a pattern). The measure (also called a bar) is divided in Steps. The drum machine only supports 16 step measure patterns played in 4/4 time. The measure is comprised of 4 quarter notes, each quarter note is comprised of 4 sixteenth notes and each sixteenth note corresponds to a step.

type Track

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

A Track represents an audio sample loaded by the drum machine, allowing the programmer to schedule the playback of the sound. The scheduling of the playback is done using the concept of steps.

Jump to

Keyboard shortcuts

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