Media_DrawWaveform ( container; trackID; width; height { ; startTime { ; endTime { ; fgcolor { ; bgcolor } } } } )
Media_DrawWaveform creates a waveform image of a sound file and places it into a container field. The image is generated in the colors and dimensions you specify. You can focus the waveform on a specific time segment of the audio file or cover its full length.
Parameter | Description |
---|---|
container | Sound location ( container field or file path ) |
trackID | Track of the audio file to be graphed (typically “1”). | width | Width of the waveform image to be generated (in pixels). | height | Height of the waveform image to be generated (in pixels). | startTime | Optional parameter. Time in sound file to begin graph (HH:MM:SS.S). | endTime | Optional parameter. Time in sound file to end graph (HH:MM:SS.S). | fgcolor | Optional parameter. Foreground color for the sound graph (in hexadecimal). | bgcolor | Optional parameter. Background color for the sound graph (in hexadecimal). |
The result must be returned to a container field.
The resulting image shows two waveform graphs, one above the other. The top waveform is for the left channel, the bottom is the right channel.
Graphing the Full Sound File
If you want to graph the entire sound file, set both the startTime and endTime parameters to “00:00:00”.
Use Media_GetLastError to get possible error of this function.
Examples
To create a waveform at 500×200 pixels for an audio file in a field named soundContainer:
Set Field [ MyTable::WaveFormImage ;
Media_DrawWaveform (
myTable::soundContainer ;
1 ;# track number
500 ;# 500 pixels wide
200 ;# 200 pixels tall
"00:00:00" ;# start
"00:00:00" ;# end
"#000000" ;# black waveform
"#FFFFFF"# white background
) ]
To get the same waveform for an audio file on the desktop named song.mp3:
Set Field [ MyTable::WaveFormImage ;
Media_DrawWaveform (
".D/song.mp3" ;
1 ;# track number
500 ; 200 ;# 500 x 200 pixels
"00:00:00" ;# start
"00:00:00" ;# end
"#000000" ;# black waveform
"#FFFFFF" # white background
) ]
To create a waveform graph covering the first 10 seconds of the sound file:
Set Field [ MyTable::WaveFormImage ;
Media_DrawWaveform (
".D/song.mp3" ;
1 ;# track number
500 ; 200 ;# 500 x 200 pixels
"00:00:00" ;# start
"00:00:10" ;# end
"#000000" ;# black waveform
"#FFFFFF" # white background
) ]
To generate a waveform with a green foreground and dark violet background:
Set Field [ MyTable::WaveFormImage ;
Media_DrawWaveform (
".D/song.mp3" ;
1 ;# track number
500 ; 200 ;# 500 x 200 pixels
"00:00:00" ;# start
"00:00:10" ;# end
"#00FF00" ;# green waveform
"#660099" # violet background
) ]