Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaOS Manual: Sounds"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
m
m
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
Sound card configured in the AHI Preferences can be used for playing and recording sound. Modern sound cards allow recording from several sources: through the line in and AUX connectors, microphone connector, CD connector, etc. Your sound card may also provide several outputs to choose from, and in addition you can route the audio output to a file. To select your preferred input and output channels, open the [[AmigaOS Manual:AHI Preferences editor|AHI Preferences editor]] and make your choice.
  +
 
= Playing =
 
= Playing =
  +
== Program 16. Play.rexx ==
 
  +
The '''AUDIO:''' device allows playing raw (SIGNED), AIFF, or AIFC formatted sound samples. The procedure of playing a sound sample is as follows:
  +
  +
# Open the '''AUDIO:''' device for writing.
  +
# Write the sound sample to the device.
  +
# Close the device.
  +
  +
The '''AUDIO:''' device expects to receive an 8 bit mono AIFF or AIFC formatted data stream. It will play the stream at the rate of 8000 Hz, with full volume, using the '''AUDIO:''' device unit 0.
  +
  +
You can change all those parameters when opening the '''AUDIO:''' device. These are the properties you can configure:
  +
  +
{| class="wikitable"
  +
! Keyword !! Template !! Description
  +
|-
  +
| BITS or B || B=BITS/K/N || Number of bits per sample. Default is 8.
  +
|-
  +
| CHANNELS or C || C=CHANNELS/K/N || Number of channels to use: 1 = mono audio, 2 = stereo audio. Default is 1.
  +
|-
  +
| FREQUENCY or F || F=FREQUENCY/K/N || Playback frequency. Default is 8000.
  +
|-
  +
| TYPE or T || T=TYPE/K || Type of the audio stream: SIGNED, AIFF, or AIFC. The '''AUDIO:''' device will detect the stream format automatically if not set.
  +
|-
  +
| VOLUME or V || V=VOLUME/K/N || Playback volume: 0-100. 0 mutes the playback and 100 is the full volume. Default is 100.
  +
|-
  +
| POSITION or P || P=POSITION/K/N || Stereo panning: -100 = far left, 0 = center, 100 = far right. Default is 0.
  +
|-
  +
| PRIORITY or PRI || PRI=PRIORITY/K/N || Playback priority: -128 to 127. If priority of 127 is used, no other playback request can interrupt the current playback. Default is 0.
  +
|-
  +
| LENGTH or L || L=LENGTH/K/N || Limits the number of bytes the '''AUDIO:''' device will receive. Default is no limit.
  +
|-
  +
| SECONDS or S || S=SECONDS/K/N || Limits the time '''AUDIO:''' device will be reading the audio stream. Default is no limit.
  +
|-
  +
| BUFFER or BUF || BUF=BUFFER/K/N || Size of the playback buffer in bytes. Default is 32768.
  +
|-
  +
| UNIT || UNIT/K/N || Device unit to be used. Default is 0.
  +
|}
  +
  +
If you supply several parameters when opening the device, the parameters must be separated with slashes ('''/'''). For example:
  +
<syntaxhighlight lang="rexx">
  +
OPEN( 'audio', 'AUDIO:FREQUENCY=22050/VOLUME=50/PRIORITY=1', 'W' )
  +
</syntaxhighlight>
  +
  +
== Program 27. Play.rexx ==
 
<syntaxhighlight lang="rexx">
 
<syntaxhighlight lang="rexx">
 
/*
 
/*
Line 43: Line 87:
   
 
= Recording =
 
= Recording =
  +
As with playing, three audio formats are available for recording: raw (SIGNED), AIFF, and AIFC. The overall procedure of recording is similar to playing, except instead of writing to the '''AUDIO:''' device you read from the device:
== Program 17. Record.rexx ==
 
  +
  +
# Open the '''AUDIO:''' device for reading.
  +
# Read sound sample from the device.
  +
# Close the device.
  +
  +
By default the '''AUDIO:''' device outputs an 8 bit mono raw (SIGNED) sound through the device unit 0. The used sampling rate is 8000 Hz.
  +
  +
Different recording settings can be requested when opening the '''AUDIO:''' device. The following settings are available:
  +
{| class="wikitable"
  +
! Keyword !! Template !! Description
  +
|-
  +
| BITS or B || B=BITS/K/N || Number of bits per sample. Default is 8.
  +
|-
  +
| CHANNELS or C || C=CHANNELS/K/N || Number of channels to use: 1 = mono audio, 2 = stereo audio. Default is 1.
  +
|-
  +
| FREQUENCY or F || F=FREQUENCY/K/N || Sampling frequency. Default is 8000.
  +
|-
  +
| TYPE or T || T=TYPE/K || Sample format: SIGNED, AIFF, or AIFC. Default is SIGNED.
  +
|-
  +
| LENGTH or L || L=LENGTH/K/N || Limit the sound sample length (number of bytes). The default sample length is extremely long.
  +
|-
  +
| SECONDS or S || S=SECONDS/K/N || Limit the recording time (seconds). The default recording time is very long.
  +
|-
  +
| BUFFER or BUF || BUF=BUFFER/K/N || Size of the recording buffer in bytes. Default is 32768.
  +
|-
  +
| UNIT || UNIT/K/N || Device unit to be used. Default is 0.
  +
|}
  +
  +
If you supply several parameters when opening the device, the parameters must be separated with slashes ('''/'''). For example:
  +
<syntaxhighlight lang="rexx">
  +
OPEN( 'audio', 'AUDIO:BITS=16/CHANNELS=2/FREQUENCY=22050/SECONDS=10', 'R' )
  +
</syntaxhighlight>
  +
  +
== Program 28. Record.rexx ==
 
<syntaxhighlight lang="rexx">
 
<syntaxhighlight lang="rexx">
 
/*
 
/*
Line 76: Line 154:
 
WRITECH( 'console', 'Press enter to start recording.' )
 
WRITECH( 'console', 'Press enter to start recording.' )
 
PARSE PULL input
 
PARSE PULL input
WRITECH( 'console', ' REC ()' || COPIES( d2c( 8 ), 2 ) )
+
WRITECH( 'console', ' REC (·)' || COPIES( d2c( 8 ), 2 ) )
   
 
counter = 0
 
counter = 0
Line 88: Line 166:
 
counter = counter + 1
 
counter = counter + 1
 
IF ( counter // 2 = 0 ) THEN DO
 
IF ( counter // 2 = 0 ) THEN DO
WRITECH( 'console', '' || d2c( 8 ) )
+
WRITECH( 'console', '·' || d2c( 8 ) )
 
counter = 0
 
counter = 0
 
END
 
END
Line 95: Line 173:
 
END
 
END
 
END
 
END
WRITECH( 'console', '' )
+
WRITECH( 'console', '·' )
   
 
/* Close console stream */
 
/* Close console stream */

Latest revision as of 15:16, 27 March 2019

Sound card configured in the AHI Preferences can be used for playing and recording sound. Modern sound cards allow recording from several sources: through the line in and AUX connectors, microphone connector, CD connector, etc. Your sound card may also provide several outputs to choose from, and in addition you can route the audio output to a file. To select your preferred input and output channels, open the AHI Preferences editor and make your choice.

Playing

The AUDIO: device allows playing raw (SIGNED), AIFF, or AIFC formatted sound samples. The procedure of playing a sound sample is as follows:

  1. Open the AUDIO: device for writing.
  2. Write the sound sample to the device.
  3. Close the device.

The AUDIO: device expects to receive an 8 bit mono AIFF or AIFC formatted data stream. It will play the stream at the rate of 8000 Hz, with full volume, using the AUDIO: device unit 0.

You can change all those parameters when opening the AUDIO: device. These are the properties you can configure:

Keyword Template Description
BITS or B B=BITS/K/N Number of bits per sample. Default is 8.
CHANNELS or C C=CHANNELS/K/N Number of channels to use: 1 = mono audio, 2 = stereo audio. Default is 1.
FREQUENCY or F F=FREQUENCY/K/N Playback frequency. Default is 8000.
TYPE or T T=TYPE/K Type of the audio stream: SIGNED, AIFF, or AIFC. The AUDIO: device will detect the stream format automatically if not set.
VOLUME or V V=VOLUME/K/N Playback volume: 0-100. 0 mutes the playback and 100 is the full volume. Default is 100.
POSITION or P P=POSITION/K/N Stereo panning: -100 = far left, 0 = center, 100 = far right. Default is 0.
PRIORITY or PRI PRI=PRIORITY/K/N Playback priority: -128 to 127. If priority of 127 is used, no other playback request can interrupt the current playback. Default is 0.
LENGTH or L L=LENGTH/K/N Limits the number of bytes the AUDIO: device will receive. Default is no limit.
SECONDS or S S=SECONDS/K/N Limits the time AUDIO: device will be reading the audio stream. Default is no limit.
BUFFER or BUF BUF=BUFFER/K/N Size of the playback buffer in bytes. Default is 32768.
UNIT UNIT/K/N Device unit to be used. Default is 0.

If you supply several parameters when opening the device, the parameters must be separated with slashes (/). For example:

OPEN( 'audio', 'AUDIO:FREQUENCY=22050/VOLUME=50/PRIORITY=1', 'W' )

Program 27. Play.rexx

/*
** Play an AIFF audio file
*/
 
fileName   = 'recording.aiff' /* Audio file name */
frequency  = 22050            /* Playback frequency */
volume     = 100              /* Full volume */
unit       = 0                /* Use device unit 0 */
 
/* Playback properties */
properties = 'TYPE=AIFF/'
properties = properties || 'FREQUENCY=' || frequency || '/'
properties = properties || 'VOLUME=' || volume || '/'
properties = properties || 'UNIT=0'
 
/* Open audio stream */
IF ( ~OPEN( 'audio', 'AUDIO:' || properties, 'W' ) ) THEN DO
    SAY 'Failed to open audio stream.'
    exit 0
END
 
/* Open audio file */
IF ( OPEN( 'file', fileName, 'R' ) ) THEN DO
    /* Play */
    DO UNTIL ( EOF( 'file' ) = 1 )
        buffer = READCH( 'file', 4096 )
        WRITECH( 'audio', buffer )
    END
 
    /* Close audio file */
    CLOSE( 'file' )
END
ELSE DO
    SAY 'Failed to open file "' || fileName || '".'
END
 
/* Close stream */
CLOSE( 'audio' )

Recording

As with playing, three audio formats are available for recording: raw (SIGNED), AIFF, and AIFC. The overall procedure of recording is similar to playing, except instead of writing to the AUDIO: device you read from the device:

  1. Open the AUDIO: device for reading.
  2. Read sound sample from the device.
  3. Close the device.

By default the AUDIO: device outputs an 8 bit mono raw (SIGNED) sound through the device unit 0. The used sampling rate is 8000 Hz.

Different recording settings can be requested when opening the AUDIO: device. The following settings are available:

Keyword Template Description
BITS or B B=BITS/K/N Number of bits per sample. Default is 8.
CHANNELS or C C=CHANNELS/K/N Number of channels to use: 1 = mono audio, 2 = stereo audio. Default is 1.
FREQUENCY or F F=FREQUENCY/K/N Sampling frequency. Default is 8000.
TYPE or T T=TYPE/K Sample format: SIGNED, AIFF, or AIFC. Default is SIGNED.
LENGTH or L L=LENGTH/K/N Limit the sound sample length (number of bytes). The default sample length is extremely long.
SECONDS or S S=SECONDS/K/N Limit the recording time (seconds). The default recording time is very long.
BUFFER or BUF BUF=BUFFER/K/N Size of the recording buffer in bytes. Default is 32768.
UNIT UNIT/K/N Device unit to be used. Default is 0.

If you supply several parameters when opening the device, the parameters must be separated with slashes (/). For example:

OPEN( 'audio', 'AUDIO:BITS=16/CHANNELS=2/FREQUENCY=22050/SECONDS=10', 'R' )

Program 28. Record.rexx

/*
** Record an AIFF audio file
*/
 
fileName   = 'recording.aiff' /* Audio file name */
duration   = 5                /* Recording time (seconds) */
frequency  = 22050            /* Sampling frequency */
unit       = 0                /* Use device unit 0 */
 
/* Recording properties */
properties = 'TYPE=AIFF/'
properties = properties || 'SECONDS=' || duration || '/'
properties = properties || 'FREQUENCY=' || frequency || '/'
properties = properties || 'BITS=16' || '/'
properties = properties || 'CHANNELS=2' || '/'
properties = properties || 'UNIT=0'
 
/* Open audio stream */
IF ( ~OPEN( 'audio', 'AUDIO:' || properties, 'R' ) ) THEN DO
    SAY 'Failed to open audio stream.'
    EXIT 0
END
 
/* Open audio file */
IF ( OPEN( 'file', fileName, 'W' ) ) THEN DO
    /* Open console stream for printing */
    OPEN( 'console', '*', 'W' )
 
    /* Wait for enter */
    WRITECH( 'console', 'Press enter to start recording.' )
    PARSE PULL input
    WRITECH( 'console', '    REC (·)' || COPIES( d2c( 8 ), 2 ) )
 
    counter = 0
 
    /* Record */
    DO UNTIL ( EOF( 'audio' ) = 1 )
        buffer = READCH( 'audio', 4096 )
        WRITECH( 'file', buffer )
 
        /* Animate recording indicator */
        counter = counter + 1
        IF ( counter // 2 = 0 ) THEN DO
            WRITECH( 'console', '·' || d2c( 8 ) )
            counter = 0
        END
        ELSE DO
            WRITECH( 'console', 'x' || d2c( 8 ) )
        END
    END
    WRITECH( 'console', '·' )
 
    /* Close console stream */
    CLOSE( 'console ' )
 
    /* Close audio file */
    CLOSE( 'file' )
 
    SAY ''
    SAY 'Recorded ' || duration || ' seconds to file "' || fileName || '".'
END
ELSE DO
    SAY 'Failed to open file "' || fileName || '" for writing.'
END
 
/* Close stream */
CLOSE( 'audio' )