Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaOS Manual: Sounds"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
m
(Added recording example)
Line 43: Line 43:
   
 
= Recording =
 
= Recording =
  +
== Program 17. Record.rexx ==
  +
<syntaxhighlight lang="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' )
  +
</syntaxhighlight>

Revision as of 20:26, 8 August 2017

Playing

Program 16. 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

Program 17. 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' )