Name
RecordAudio -- record audio to file (V11.0)
Synopsis
RecordAudio(file$, length[, table])
Library
sound

Function
This function starts to capture audio from the default audio recording device and writes it to the file specified by file$. The length parameter must be set to the desired recording length in milliseconds. For example, to record 10 seconds of audio pass 10000 in the length parameter.

The optional table argument table allows you to configure further parameters of the recording operation. The following tags are currently recognized in the table argument:

Frequency:
The desired recording frequency. Defaults to 44100.

Channels:
Number of channels that shall be recorded. This must be 1 for mono or 2 for stereo recording. Defaults to 2.

Bits:
The desired bit depth of the PCM samples that are recorded. This must be either 8 or 16. Defaults to 16.

Format:
The file format that should be used when saving the audio data to file$. Note that on slower systems like 68k AmigaOS 3 it's recommended to use an output audio format that doesn't use any compression (e.g. uncompressed RIFF WAVE) to make sure the file saver can keep up with the audio recorder and there is no buffer underrun. Thus, on slower systems you could first record to an uncompressed RIFF WAVE file and then convert this file to a compressed audio format using SaveMusic() after recording has finished. By default, Hollywood supports the following two sound formats:

#SNDFMT_WAVE:
Use the RIFF WAVE format. This is the default.

#SNDFMT_SVX:
Use the IFF 8SVX (8-bit) or IFF 16SV (16-bit) format.

Additional sound formats can be made available by plugins.

Bitrate:
If the file format specified in the Format tag supports audio compression using a specific bitrate, this tag can be used to specify that bitrate. For the #SNDFMT_WAVE and #SNDFMT_SVX formats this tag doesn't have any effect.

Quality:
If the file format specified in the Format tag supports audio compression using a specific quality setting, this tag can be used to specify that quality. For the #SNDFMT_WAVE and #SNDFMT_SVX formats this tag doesn't have any effect.

Throttle:
By default, RecordAudio() will throttle itself to avoid consuming 100% of the CPU cycles. On very slow systems (e.g. 68k AmigaOS 3), however, this throttle could lead to a decline in performance. If that is the case, you can set this tag to False to tell RecordAudio() not to throttle anything. Defaults to True.

Async:
If this is set to True, RecordAudio() will operate in asynchronous mode. This means that it will return immediately, passing an asynchronous operation handle to you. You can then use this asynchronous operation handle to finish the operation by repeatedly calling ContinueAsyncOperation() until it returns True. This is very useful in case your script needs to do something else while the operation is in progress, e.g. displaying a status animation or something similar. By putting RecordAudio() into asynchronous mode, it is easily possible for your script to do something else while the operation is being processed. See ContinueAsyncOperation for details. Defaults to False.

Adapter:
This tag allows you to specify one or more file adapters that should be asked if they want to save the specified file. If you use this tag, you must set it to a string containing the name(s) of one or more adapter(s). Defaults to the adapter set using SetDefaultAdapter(). See Loaders and adapters for details.

UserTags:
This tag can be used to specify additional data that should be passed to savers and adapters. If you use this tag, you must set it to a table of key-value pairs that contain the additional data that should be passed to plugins. See User tags for details.

Note that on AmigaOS and compatibles audio recording requires exclusive access to the audio hardware so if you've accessed the audio hardware before you need to call CloseAudio() to shut it down first before you can call RecordAudio() and of course no other programs that are using the audio hardware may be running when you call RecordAudio() on Amiga.

Inputs
file$
desired output file
length
desired recording length in milliseconds
table
optional: table argument containing further parameters (see above)
Example
RecordAudio("test.wav", 10000, {Channels = 1})
The code above records 10 seconds worth of audio data and saves them to the file test.wav. The audio data will be recorded in 44.1khz, 16-bit mono format.

Show TOC