|
7 | 7 | // Sound effects and music can be changed using functions: SetSfx and SetMusic.
|
8 | 8 | package audio
|
9 | 9 |
|
| 10 | +import "fmt" |
| 11 | + |
10 | 12 | // Sfx starts playing sound effect with given sfxNo on specified channel.
|
11 | 13 | //
|
12 | 14 | // sfxNo is the number of sound effect to play (0-63). sfxNo=-1 stops
|
@@ -47,36 +49,6 @@ func GetStat() Stat {
|
47 | 49 | return system.Stat()
|
48 | 50 | }
|
49 | 51 |
|
50 |
| -// SetSfx updates the sound effect. sfxNo is 0-63. Updating sfx number which |
51 |
| -// is higher than 63 does not do anything. |
52 |
| -// |
53 |
| -// SoundEffect parameters are clamped when out of range. |
54 |
| -// For example, sfx note volume equal 8 will be silently clamped to 7. |
55 |
| -func SetSfx(sfxNo int, e SoundEffect) { |
56 |
| - system.SetSfx(sfxNo, e) |
57 |
| -} |
58 |
| - |
59 |
| -// GetSfx returns sfx with given number. sfxNo is 0-63. Trying to get |
60 |
| -// sfx number higher than 63 will result in returning empty SoundEffect (zero-value). |
61 |
| -func GetSfx(sfxNo int) SoundEffect { |
62 |
| - return system.GetSfx(sfxNo) |
63 |
| -} |
64 |
| - |
65 |
| -// SetMusic updates the music pattern. patternNo is 0-63. Updating pattern number which |
66 |
| -// is higher than 63 does not do anything. |
67 |
| -// |
68 |
| -// Pattern parameters are clamped when out of range. |
69 |
| -// For example, pattern sfx number equal 64 will be silently clamped to 63. |
70 |
| -func SetMusic(patternNo int, p Pattern) { |
71 |
| - system.SetMusic(patternNo, p) |
72 |
| -} |
73 |
| - |
74 |
| -// GetMusic returns music pattern with given number. patterNo is 0-63. Trying to get |
75 |
| -// pattern number higher than 63 will result in returning empty Pattern (zero-value). |
76 |
| -func GetMusic(patterNo int) Pattern { |
77 |
| - return system.GetMusic(patterNo) |
78 |
| -} |
79 |
| - |
80 | 52 | // SaveAudio stores audio system state to byte slice. State is stored in binary form.
|
81 | 53 | // The format is described in Synthesizer.Save source code.
|
82 | 54 | func SaveAudio() ([]byte, error) {
|
@@ -122,6 +94,12 @@ type SoundEffect struct {
|
122 | 94 | Buzz bool // Not implemented yet.
|
123 | 95 | }
|
124 | 96 |
|
| 97 | +func (s SoundEffect) String() string { |
| 98 | + return fmt.Sprintf( |
| 99 | + "{Speed:%d LoopStart:%d LoopStop:%d Detune:%d Reverb:%d Dampen:%d Noiz:%t Buzz:%t Notes:(%d)[%+v %+v %+v ...]}", |
| 100 | + s.Speed, s.LoopStart, s.LoopStop, s.Detune, s.Reverb, s.Dampen, s.Noiz, s.Buzz, len(s.Notes), s.Notes[0], s.Notes[1], s.Notes[2]) |
| 101 | +} |
| 102 | + |
125 | 103 | func (s SoundEffect) noteAt(no int) Note {
|
126 | 104 | var note Note
|
127 | 105 | if no < len(s.Notes) {
|
@@ -278,9 +256,23 @@ type System interface {
|
278 | 256 | Sfx(sfxNo int, channel Channel, offset, length int)
|
279 | 257 | Music(patterNo int, fadeMs int, channelMask byte)
|
280 | 258 | Stat() Stat
|
| 259 | + // SetSfx updates the sound effect. sfxNo is 0-63. Updating sfx number which |
| 260 | + // is higher than 63 does not do anything. |
| 261 | + // |
| 262 | + // SoundEffect parameters are clamped when out of range. |
| 263 | + // For example, sfx note volume equal 8 will be silently clamped to 7. |
281 | 264 | SetSfx(sfxNo int, e SoundEffect)
|
| 265 | + // GetSfx returns sfx with given number. sfxNo is 0-63. Trying to get |
| 266 | + // sfx number higher than 63 will result in returning empty SoundEffect (zero-value). |
282 | 267 | GetSfx(sfxNo int) SoundEffect
|
| 268 | + // SetMusic updates the music pattern. patternNo is 0-63. Updating pattern number which |
| 269 | + // is higher than 63 does not do anything. |
| 270 | + // |
| 271 | + // Pattern parameters are clamped when out of range. |
| 272 | + // For example, pattern sfx number equal 64 will be silently clamped to 63. |
283 | 273 | SetMusic(patternNo int, _ Pattern)
|
| 274 | + // GetMusic returns music pattern with given number. patterNo is 0-63. Trying to get |
| 275 | + // pattern number higher than 63 will result in returning empty Pattern (zero-value). |
284 | 276 | GetMusic(patterNo int) Pattern
|
285 | 277 | Save() ([]byte, error)
|
286 | 278 | Load([]byte) error
|
|
0 commit comments