Name
SaveMusic -- save music to disk (V11.0)
Synopsis
SaveMusic(id, f$[, fmt, t])
Library
sound

Function
This command saves the music specified by id to the file specified by f$. The optional argument fmt specifies the format in which the music should be exported. 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.

Note that the music specified by id must be neither playing nor paused; it must be in stopped state. Also note that the save operation will begin at the current music position set using SeekMusic().

SaveMusic() accepts an optional table argument that allows you to pass additional arguments to the function. The following tags are currently supported by the optional table argument:

Length:
This tag allows you to specify how many milliseconds of music should be saved to the file. By default, the music will be saved from its current position until its end. In case the music is set to loop infinitely, 10 minutes will be saved by default. You can use this tag to modify this behaviour by setting it to the desired save length in milliseconds.

Bitrate:
If the file format specified in the fmt argument 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 fmt argument 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.

Async:
If this is set to True, SaveMusic() 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 SaveMusic() 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 loaders 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.

Inputs
id
identifier of music to save
f$
output file
fmt
optional: format in which to export the music (defaults to #SNDFMT_WAVE)
t
optional: table containing further options
Example
@MUSIC 1, "test.mp3"
SaveMusic(1, "test.wav")
The code above converts the file test.mp3 from MP3 to WAVE by using the SaveMusic() command.


@MUSIC 1, "test.mp3"
SaveMusic(1, "test.wav")
handle = SaveMusic(1, "test.wav", #SNDFMT_WAVE, {Async = True})
Repeat
    ; ...do something here...
Until ContinueAsyncOperation(handle) = True
The code above does the same as the first example but now runs asynchronously, allowing your script to do something else while saving is in progress.

Show TOC