Copyright © 2008-2014 MultiMedia Soft

How to convert the format of sound files

Previous pageReturn to chapter overviewNext page

Inside the tutorial How to export edited sounds we have already seen how to export contents of an editing session into an output file having a specific audio format; in many situations you could simply need to perform a conversion from a certain audio format to a different audio format, for example from WAV to MP3, without the need to effectively load the sound contained inside the source file into the editor component: this task can be completed through the following conversion capabilities available inside the Audio Sound Editor component:

 

Conversion of single files
Conversion of multiple files in one single shot through "Conversion Automation"

 

In both cases the audio format of the converted file(s) will be determined by the EncodeFormats.FormatToUse property to one of the available encoding formats.

 

Each encoding format set into the EncodeFormats.FormatToUse property has its own settings which can be controlled through sub-properties of the EncodeFormats property: for example, if the chosen encoding format should be ENCODING_FORMAT_WAV, you would have to modify settings of the EncodeFormats.WAV property, if chosen encoding format should be ENCODING_FORMAT_MP3 you would have to modify settings of the EncodeFormats.MP3 property and so on for the remaining accepted encoding formats.

 

The most important property for choosing a specific encode mode for a certain encoding format is to set the EncodeMode sub-property: for example, if the chosen encoding format should be ENCODING_FORMAT_WAV, you would have to modify the EncodeFormats.WAV.EncodeMode property, if chosen encoding format should be ENCODING_FORMAT_MP3 you would have to modify the EncodeFormats.MP3.EncodeMode property and so on for the remaining accepted encoding formats.

 

For each encoding format, available encoding modes can be enumerated using the GetEncodeModesCount and GetEncodeModeDesc methods available inside each format related sub-property: for example, if the chosen encoding format should be ENCODING_FORMAT_WAV, you would have to use the EncodeFormats.WAV.GetEncodeModesCount method and the EncodeFromats.WAV.GetEncodeModeDesc method, if chosen encoding format should be ENCODING_FORMAT_MP3 you would have to use the EncodeFormats.MP3.GetEncodeModesCount method and the EncodeFormats.MP3.GetEncodeModeDesc method and so on for the remaining accepted encoding formats.

 

 

 

Conversion of single files

 

Before start conversion of a source file into a destination file having a different audio format, you should predispose some important setting that will allow the converter to manage output files as needed.

 

The ConvertFileDestOptionsSet method allows defining options regarding the way the destination file will be optionally renamed, the folder where it will be stored and the possibility to keep existing tag information.
The ConvertFileDestEffectsSet method allows applying normalization and DC Offset removal effects during conversion.
The ConvertFileDestResamplingSet method allows defining eventual resampling during conversion.

 

At this point you may start the sound file conversion using the ConvertFile or ConvertFileRaw methods; the file conversion can be stopped at any time using the ConvertFileCancel method.

During the execution of the conversion, the container application will receive the following set of events:

 

one ConvertSoundFileStarted event when the session is started
a number of ConvertSoundFilePerc events that allows to know the percentage of advancement of the file conversion
one ConvertSoundFileDone event when the session is completed

 

 

 

Conversion of multiple files in one single shot through "Conversion Automation"

 

"Conversion automation" is a feature which allows converting many files, not necessarily having the same audio format, to corresponding output sound files having the format predisposed inside the EncodeFormats.FormatToUse property.

 

You can start adding single sound files to the automation procedure through the ConvertAutomationAddFile method or entire folders (and optionally related sub-folders) through the ConvertAutomationAddFolder method: after adding sound files contained inside a folder, current contents of the automation procedure can be enumerated using the combination of ConvertAutomationGetFilesCount and ConvertAutomationGetFilePathname methods.

 

Contents of the automation procedure can be totally removed through the ConvertAutomationReset method

 

As seen above for conversion of single, before starting the conversion automation you should predispose some important setting that will allow the converter to manage output files as needed.

 

The ConvertFileDestOptionsSet method allows defining options regarding the way the destination file will be optionally renamed, the folder where it will be stored and the possibility to keep existing tag information.
The ConvertFileDestEffectsSet method allows applying normalization and DC Offset removal effects during conversion.
The ConvertFileDestResamplingSet method allows defining eventual resampling during conversion.

 

At this point you may start the conversion automation session by calling the ConvertAutomationExecute method; the conversion automation session can be stopped at any time using the ConvertFileCancel method.

During the execution of the convert automation session, the container application will receive the following set of events:

 

one ConvertSoundFileStarted event each time the conversion of a single file is started
a number of ConvertSoundFilePerc events that allows to know the percentage of advancement for each file conversion
one ConvertSoundFileDone event when the conversion of a single file is completed

 

Each of the events described above comes with a parameter named nFileIndex defining the zero-based index of the single file being converted; in case you should need to drive a progress bar defining the overall percentage of advancement of the conversion session, you may apply the following simple proportion:

 

nSessionPercentage = (nFileIndex * 100) / nTotalFiles

 

where nTotalFiles is obtained by calling the ConvertAutomationGetFilesCount method.