[id] = GetMusicSample(srcid, id, length[, t])
srcid. It will create the new Hollywood sample object specified
by id which will contain the audio data just extracted from the music.
If you pass Nil in id, GetMusicSample() will automatically
select an identifier and return it to you. Audio data extraction will start
from the current music position which can be modified by SeekMusic().
GetMusicSample() will also advance the current music position by the number
of samples read.
The length argument must contain the number of samples to extract, e.g. if
you wish to extract 10 seconds of sound data from a music whose playback
frequency is 44100hz, you'd have to pass 441000 in length (44100 * 10).
Note that since sample data is quite memory hungry you should only extract
a reasonable amount of samples per call to avoid running out of memory.
The music specified by srcid must not be playing. It must be in stopped state.
Also note that calling GetMusicSample() will put the music object into a special
read state which will block all other functions on the music object except SeekMusic().
If you want to start playback of the music object you have used GetMusicSample()
on, you first have to close and re-open it.
There is also an optional table argument t allowing you to configure further options.
This table argument accepts the following tags:
Hardware:False to create a software sample. Software samples are more
efficient because they are completely independent of the audio hardware because
they will never be played. Defaults to True.
Nil
is passed in the first argumentfreq = GetAttribute(#MUSIC, 1, #ATTRPITCH) GetMusicSample(1, 1, freq * 10)The code above extracts 10 seconds of audio data from music 1 and stores it in sample 1.