Play: Difference between revisions

From Wiki of ZZT
Jump to navigation Jump to search
(Moved the note about scrolls down to quirks. Added subheadings.)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
''[This article is a stub. You can help by filling it out.]''
''[This article is a stub. You can help by filling it out.]''


The '''#play [sound]''' command in [[ZZT-OOP]] allows [[object|objects]] and [[scroll|scrolls]] to play music and sound effects.
The '''#play''' command in [[ZZT-OOP]] allows [[object|objects]] and [[scroll|scrolls]] to play music and sound effects.
 
== Syntax ==
<code>#play <sound></code>


== Sound Format ==
== Sound Format ==


The general syntax is that parameters come before the notes and drums they modify. The octave and length parameters are reset each line. The default note length is 1 (32nd note), and the default octave is 3 (ranges from 1 to 6 inclusively).
The general syntax is that parameters come before the notes and drums they modify.
 
All characters not listed below are silently ignored (like comments).


=== Parameters ===
=== Parameters ===


{| class="wikitable"
{| class="wikitable"
|+ Parameters
|-
! Symbol !! Denotes !! Length in Ticks
! Symbol !! Denotes !! Length in Ticks
|-
|-
Line 34: Line 37:
| - || Down octave || N/A
| - || Down octave || N/A
|}
|}
The octave and length parameters are reset each line. The default note length is 1 (32nd note), and the default octave is 3 (ranges from 1 to 6 inclusively).


Note that the lengths are measured in PIT ticks, not cycles! The PIT ticks at approximately 18.2 Hz, meaning that a 32nd note lasts approximately 55 milliseconds.
Note that the lengths are measured in PIT ticks, not cycles! The PIT ticks at approximately 18.2 Hz, meaning that a 32nd note lasts approximately 55 milliseconds.
Line 47: Line 52:


=== Drums ===
=== Drums ===
Drums are hardcoded percussion effects, created by rapidly changing the frequency emitted by the PC Speaker. They last for approximately 14 milliseconds each, with the exception of the 1-millisecond tick.


{| class="wikitable"
{| class="wikitable"
|+ Drums
|-
! Symbol !! "Sound"
! Symbol !! "Sound"
|-
|-
Line 76: Line 77:
|}
|}


All other characters are silently ignored (like comments).
Drums are hardcoded percussion effects, created by rapidly changing the frequency emitted by the PC Speaker. They last for approximately 14 milliseconds each, with the exception of the 1-millisecond tick.
 
== Example ==
 
''[TODO: Put a simple thing here and explain it character by character.]''


== Quirks ==
== Quirks ==


* When a scroll uses '''#play''' it does not suppress the default scroll sound effect.
* When a scroll uses <code>#play</code> it does not suppress the default scroll sound effect. Rather, the sound is appended to the end of the sound effect.
* The triplet and time-and-a-half parameters use integer floor division. If the result of the division is 0 (with either ''t3'' or ''s3''), then the length value will underflow, causing ZZT to play a 256-tick-long note - which is also the maximum possible length of a single note.
* The triplet and time-and-a-half parameters use integer floor division. If the result of the division is 0 (with either ''t3'' or ''s3''), then the length value will underflow, causing ZZT to play a 256-tick-long note - which is also the maximum possible length of a single note.
* Drums are timed using Turbo Pascal's built-in ''Delay()'' function. As it was designed for the late 1980s state of the art in computer technology, the frequencies will alternate far too quickly on more modern hardware.
* Drums are timed using Turbo Pascal's built-in ''Delay()'' function. As it was designed for the late 1980s state of the art in computer technology, the frequencies will alternate far too quickly on more modern hardware.

Latest revision as of 17:12, 29 September 2022

[This article is a stub. You can help by filling it out.]

The #play command in ZZT-OOP allows objects and scrolls to play music and sound effects.

Syntax

#play <sound>

Sound Format

The general syntax is that parameters come before the notes and drums they modify.

All characters not listed below are silently ignored (like comments).

Parameters

Symbol Denotes Length in Ticks
t 32nd Note 1
s Sixteenth Note 2
i Eighth Note 4
q Quarter Note 8
h Half Note 16
w Whole Note 32
3 Triplet (n/3)
. Time-and-a-half (n*3)/2
+ Up octave N/A
- Down octave N/A

The octave and length parameters are reset each line. The default note length is 1 (32nd note), and the default octave is 3 (ranges from 1 to 6 inclusively).

Note that the lengths are measured in PIT ticks, not cycles! The PIT ticks at approximately 18.2 Hz, meaning that a 32nd note lasts approximately 55 milliseconds.

The triplet and time-and-a-half modifiers need to be placed somewhere after the length parameters they are modifying (eg w3 or h.). These modifiers also stack (eg. w.3 produces a 16-tick-long note length, equivalent to h).

Notes and Rests

  • X - Rest
  • CDEFGAB - Piano notes, can be followed by:
    • # - Sharp
    • ! - Flat

Drums

Symbol "Sound"
0 Tick
1 Tweet
2 Cowbell
3 N/A -- Denotes Triplet
4 Hi snare
5 Hi woodblock
6 Low snare
7 Low tom
8 Low woodblock
9 Bass drum

Drums are hardcoded percussion effects, created by rapidly changing the frequency emitted by the PC Speaker. They last for approximately 14 milliseconds each, with the exception of the 1-millisecond tick.

Example

[TODO: Put a simple thing here and explain it character by character.]

Quirks

  • When a scroll uses #play it does not suppress the default scroll sound effect. Rather, the sound is appended to the end of the sound effect.
  • The triplet and time-and-a-half parameters use integer floor division. If the result of the division is 0 (with either t3 or s3), then the length value will underflow, causing ZZT to play a 256-tick-long note - which is also the maximum possible length of a single note.
  • Drums are timed using Turbo Pascal's built-in Delay() function. As it was designed for the late 1980s state of the art in computer technology, the frequencies will alternate far too quickly on more modern hardware.
    • The above also means that, on slower hardware, a drum playback actually stalls engine execution for the duration of its sound!

See Also

  • Sound effects - ZZT's built-in sound effects, expressed in #play statements.
  • Duration Table - A programmatically generated list of possible note durations in ZZT-OOP