How to convert the format of sound files |
|
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:
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.
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 can be notified about current advancement through the CallbackConvertFilePerc delegate set through the CallbackConvertFilePercSet method.
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 conversion, the container application can be notified about current advancement through the CallbackConvertFilePerc delegate set through the CallbackConvertFilePercSet method.
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.
Special notes
• | If you need dealing with Windows Media Audio files (WMA, ASF, WMV, etc.), the Microsoft Windows Media Format modules must already be installed on the target PC: for Windows XP and previous versions the Windows Media Format modules can be installed using the redistribution setup package (wmfdist.exe) provided by Microsoft. For Windows Vista and later versions there is the need to install the Microsoft's Windows Media Player application (which is usually installed by default). |
• | For encoding of MP3 files, the Lame encoder (Lame.exe) must be available on the target system. |
• | For encoding of MP2 files, the TwoLame encoder (TwoLame.exe) must be available on the target system. |
• | For encoding of OGG Vorbis files, the OggEnc encoder (OggEnc.exe) must be available on the target system. |
• | For encoding of AAC and MP4 files, the Faac encoder (Faac.exe) must be available on the target system. |
• | For encoding of AAC+ files, the FdkAac encoder (FdkAac.exe) must be available on the target system. |
• | For encoding of OPUS files, the OPUS encoder (OpusEnc.exe) must be available on the target system. |