A downloadable NextBASIC PCM Player

Download NowName your own price

Using this library has three steps to it

  1. Install the player
  2. Load the samples (up to 16 samples, you can replace a sample at any time)
  3. Send the player commands to start/stop playback and get the current status of the player

Install the player

Installing the player is as simple as executing the .playraw DOT command. This will install the player and setup the environment ready to start playing

10 .playraw

Executing .playraw multiple times will not cause any issues, however you will need to reload your samples.

Load samples

Next we need to load some samples to play. This is done using the .loadraw DOT command. This command will check that the player is installed and give an error if not. The loader will allocate banks from NextOS and load the sound data into the banks. You can load audio data into one of 16 slots (0..15). Slots can be reused simply by loading a new sample into the target slot, this will replace the previous audio data with the newly loaded data.

20 .loadraw 0 "andnow.raw" : REM Load sample into slot 0
30 .loadraw 1 "problem.raw" : REM Load sample into slot 1

Start/Stop Playback

Starting and stopping playback is done by sending commands to the player.

There are 3 addresses used to trigger the actions in the player

CommandAddressArgumentsDescription
Start Playback23768 ($5cd8)slot number (0..15)Starts the playback of the audio in the specified slot.
NOTE:If the high bit of the slot number is set, the sample will loop until stopped.
Stop Playback23771 ($5cdb)N/AStops the current playback
Get Status23774 ($5cde)N/AReturns 1 if the player is currently playing audio, 0 if not

Playback flags

The high bits of the slot number act as special flags that you can use to control the playback.

Bit flagDescription
Bit 7 (128)Loop the playback until you explicitly stop it or start another playback
Bit 6 (64)Increase the playback rate to 8000 Hz. This is ideal for samples converted to 8000 Hz, but you can use it to create effects for samples at lower/higher bit rates

To make this easier to use, you can use the following code

    1000 DEFPROC StartPlayback(slot,loop=0,hires=0)
    1010   IF loop THEN slot |= 128
    1020   IF hires THEN slot |= 64
    1030   RANDOMIZE USR (23768,slot)
    1040 ENDPROC
    1050 DEFPROC StopPlayback()
    1060   RANDOMIZE USR 23771
    1070 ENDPROC
    1080 DEF FN IsPlaying()= USR 23774

Create your own audio files

The downloadable zip file contains 5 sample audio clips. Using Audcity you can load an audio clip and export it using the following setting

OptionSetting
FormatOther uncompressed files
ChannelsMono
Sample Rate4000 Hz (Custom) or 8000 Hz
HeaderRAW (header-less)
EncodingUnsigned 8-bit PCM

Exporting using the above settings will give you a file that can be directly loaded using .loadraw.

NOTE:The file must not be larger than 64K (65535 bytes)

Download

Download NowName your own price

Click download now to get access to the following files:

playraw.zip 65 kB