How to edit tag info in sound files |
|
The majority of audio formats allows the insertion of metadata, also known as "tags", which helps describing the content of the audio file by inserting information such as the title, artist, album, track number and other information about the audio file to be stored in the file itself.
The TagsEditorMan class of Audio Sound Editor for .NET allows reading and writing the most common tag formats: this can be accomplished by analyzing the audio file loaded inside an editing session, through the TagsEditor.ALL_AnalyzeSoundOnEditor method, or by accessing a sound file directly on the local disk through the TagsEditor.ALL_AnalyzeSoundFile method.
Both methods return a combination of flags which allow determining the specific tag formats embedded inside the audio file; certain audio formats allow embedding more than one tag format; for example, the MP3 format could contain ID3V1, ID3V2 and LYRICS3 formats: the combination of flags allows discriminating which of them are effectively available inside the audio file and to manage them separately; if the returned value should be 0, this would mean that no known tag format is embedded inside the audio file. A small example can be see inside the following code snippets:
Visual Basic .NET |
' perform tags analysis Dim nTagFormat As enumTagAvailable = AudioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor() If nTagFormat = enumTagAvailable.TAG_FLAG_NONE Then ' no tag detected Return End If
' check tags availability: we use bitwise operators because more than one type of tag format could be available If (nTagFormat And enumTagAvailable.TAG_FLAG_ID3V1) <> 0 Then ... do something with ID3V1 ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_ID3V2) <> 0 Then ... do something with ID3V2 ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_WMA) <> 0 Then ... do something with WMA ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_MP4) <> 0 Then ... do something with MP4 ... End If
|
Visual C# |
// perform tags analysis enumTagAvailable nTagFormat = AudioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor(); if (nTagFormat == enumTagAvailable.TAG_FLAG_NONE) // no tag detected return;
// check tags availability: we use bitwise operators because more than one type of tag format could be available if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V1) != 0) { ... do something with ID3V1 ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V2) != 0) { ... do something with ID3V2 ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_WMA) != 0) { ... do something with WMA ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_MP4) != 0) { ... do something with MP4 ... }
|
Some of the tag fields, such as artist, title and album, are common to all of the tag formats so Audio Sound Editor for .NET exposes a set of methods that allows accessing these common frames without the need to know the specific format of the audio file being edited: the combination of the TagsEditor.ALL_CommonFrameGet and TagsEditor.ALL_CommonFrameSet methods allows reading and writing these common frames; once completed, eventual modifications can be stored inside the original audio file through the TagsEditor.ALL_SaveChanges method.
IMPORTANT NOTE:When using the TagsEditor.ALL_AnalyzeSoundOnEditor and TagsEditor.ALL_AnalyzeSoundFile methods, subsequent calls to other methods of the TagsEditorMan class will be related to that specific analysis also if the calls are performed from different instances of the component. If for example you have 2 instances of Audio Sound Editor, named audioSoundEditor1 and audioSoundEditor2 respectively, and you want to obtain the title of the loaded song, after the following call
Dim nTagFormat As enumTagAvailable nTagFormat = audioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor() Dim strTitle as String strTitle = audioSoundEditor1.TagsEditor.ALL_CommonFrameGet (TAG_FIELD_TITLE)
the returned title will be about the sound file loaded inside audioSoundEditor1 while after the following call
nTagFormat = audioSoundEditor2.TagsEditor.ALL_AnalyzeSoundOnEditor() strTitle = audioSoundEditor2.TagsEditor.ALL_CommonFrameGet (TAG_FIELD_TITLE)
the returned title will be about the sound file loaded inside audioSoundEditor2. This means that, in order to read further information about tags stored inside ActiveSoundEditor1, for example the author's name, you will have to perform a new analysis of the sound loaded in audioSoundEditor1 as seen below:
Dim strAuthor as String nTagFormat = audioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor() strAuthor = audioSoundEditor1.TagsReader.ALL_CommonFrameGet (TAG_FIELD_ARTIST)
|
When dealing with specific audio formats, Audio Sound Editor for .NET allows editing the following kind of tags:
• | WMA |
• | MP4 |
• | APE |
• | FLAC |
The ID3V1 tag, intended for usage with MP3 files, occupies 128 bytes beginning with the string TAG and is placed at the end of the file. This tag allows 30 bytes each for the title, artist, album, and a "comment", four bytes for the year, and a byte to identify the genre of the song from a predefined list of 80 values (Winamp later extended this list to 148 values).
One improvement to ID3V1 uses the last two bytes of the comment field to store the track number. Such tags are referred to as ID3V1.1.
A full description of this tagging format can be found on this link.
You can know if the ID3V1 tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_ID3V1 this would mean that the ID3V1 tag is available.
ID3V1 fields can be read through the TagsEditor.ID3V1_FieldGet method and modified through the TagsEditor.ID3V1_FieldSet method. Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.ID3V1_SaveChanges method.
The ID3V1 tag can be removed through the TagsEditor.ID3V1_RemoveTag method: in this case the tag removal is performed directly on the original sound file.
ID3V2 is a tagging system that lets you put enriching and relevant information about your audio files within them. ID3V2 is a chunk of data prepended to the binary audio data. Each ID3V2 tag holds one or more smaller chunks of information, called frames. These frames can contain any kind of information and data you could think of such as title, album, performer, website, lyrics, equalizer presets, pictures etc.
A full description of this tagging format can be found on this link.
Audio Sound Editor for .NET supports 3 different versions of ID3V2:
• | ID3V2.2 |
• | ID3V2.3 |
• | ID3V2.4 |
All of them are currently supported in both reading and writing by the component. This system allows the use of UNICODE characters in UTF-16 format and, when dealing with version ID3V2.4, in UTF-8 format as well.
You can know if the ID3V2 tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_ID3V2 this would mean that the ID3V2 tag is available.
The list of supported ID3V2 frames, with related identifiers and methods to access stored information, can be found on the table below:
Support for other frames not available in the list above may be added in future versions of the component so, in case you should need the support of a specific frame, feel free to contact our technical support team.
The "Multiple" column specifies if more than one frame, having the same identifier, can be available inside the tag; in order to know how many frames are available for a specific identifier, you should use the ID3V2_FrameCountGet method. If for example you should need enumerating pictures stored inside the tag, you could do something similar:
Visual Basic .NET |
' perform tags analysis Dim nTagFormat As enumTagAvailable nTagFormat = AudioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor() If nTagFormat And TAG_FLAG_ID3V2 Then ' check the availability of embedded pictures through the search of "APIC" frames Dim nAvailablePictures as Long nAvailablePictures = AudioSoundEditor1.TagsEditor.ID3V2_FrameCountGet("APIC")
' output each picture's description Dim nIndex as Long = 0 Do While nIndex < nAvailablePictures Debug.Print AudioSoundEditor1.TagsEditor.ID3V2_PictureFrameInfoGet (nIndex, enumId3v2FrameInfo.ID3V2_FRAME_INFO_DESCRIPTION) nIndex += 1 Loop End If
|
Visual C# |
// perform tags analysis enumTagAvailable nTagFormat = AudioSoundEditor1.TagsEditor.ALL_AnalyzeSoundOnEditor(); if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V2) != 0) { // check the availability of embedded pictures through the search of "APIC" frames int nAvailablePictures = AudioSoundEditor1.TagsEditor.ID3V2_FrameCountGet("APIC");
// output each picture's description for (int nIndex = 0; nIndex < nAvailablePictures; nIndex++) Console.WriteLine (AudioSoundEditor1.TagsEditor.ID3V2_PictureFrameInfoGet (nIndex, enumId3v2FrameInfo.ID3V2_FRAME_INFO_DESCRIPTION)); }
|
Identifiers of frames available inside the ID3V2 tag can be enumerated using the combination of the TagsEditor.ID3V2_UniqueFramesCountGet and TagsEditor.ID3V2_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.ID3V2_SaveChanges method: this method allows also specifying the version the ID3V2 standard and the text encoding used to store strings.
The ID3V2 tag can be removed through the TagsEditor.ID3V2_RemoveTag method: in this case the tag removal is performed directly on the original sound file.
The Lyrics3 v2.00 tag resides between the audio and the ID3V1 tag, which must be present. The tag uses only text for everything from content to size descriptors, which are represented as numerical strings.
A full description of this tagging format can be found on this link.
You can know if the Lyrics3 tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_LYRICS3 this would mean that the Lyrics3 tag is available.
Text fields of the Lyrics3 tag can be read through the TagsEditor.LYRICS3_TextFieldGet method and modified through the TagsEditor.LYRICS3_TextFieldSet method.
The lyrics text can be read through the TagsEditor.LYRICS3_LyricsGet method and modified through the TagsEditor.LYRICS3_LyricsSet method.
The link to the image field can be read through the TagsEditor.LYRICS3_ImageLinkGet method and modified through the TagsEditor.LYRICS3_ImageLinkSet method.
Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.LYRICS3_SaveChanges method.
The Lyrics3 tag can be removed through the TagsEditor.LYRICS3_RemoveTag method: in this case the tag removal is performed directly on the original sound file.
You can know if the WMA tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WMA this would mean that the WMA tag is available.
The list of supported WMA frames, with related identifiers and methods to access stored information, can be found on the table below:
Supported frame types |
Frame identifiers |
Multiple |
Related methods |
Text-based frames |
You can use predefined identifiers or, in alternative, your own custom ones: a list of predefined identifiers can be found inside the Windows Media Format SDK. |
No |
|
Picture frames |
WM/Picture |
Yes |
TagsEditor.WMA_PictureFrameAddFromBitmap TagsEditor.WMA_PictureFrameAddFromFile TagsEditor.WMA_PictureFrameAddFromMemoryFile TagsEditor.WMA_PictureFrameBitmapGet TagsEditor.WMA_PictureFrameCountGet TagsEditor.WMA_PictureFrameFileGet TagsEditor.WMA_PictureFrameInfoGet TagsEditor.WMA_PictureFrameMemoryFileGet TagsEditor.WMA_PictureFrameRemove |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsEditor.WMA_PictureFrameCountGet method.
Identifiers of frames available inside the WMA tag can be enumerated using the combination of the TagsEditor.WMA_UniqueFramesCountGet and TagsEditor.WMA_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.WMA_SaveChanges method.
Frames related to metadata can be removed from the WMA tag through the TagsEditor.WMA_RemoveAllFrames method: in this case the removal is performed directly on the original sound file.
Vorbis metadata, called Vorbis comments, supports metadata tags similar to those implemented in the ID3 standard for MP3. All strings are encoded as UTF-8. Music tags are typically implemented as strings of the form "[TAG]=[VALUE]", for instance, "ARTIST=The big band". The tags are case-insensitive, thus typing "ARTIST=The big band" would be the same as "artist=The big band".
You can know if the OGG Vorbis tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_OGG this would mean that the OGG Vorbis tag is available.
Predefined text frames can be read through the TagsEditor.OGG_TextFrameGet method and modified through the TagsEditor.OGG_TextFrameSet method.
User defined text frames can be read through the TagsEditor.OGG_UserFrameGet method and modified through the TagsEditor.OGG_UserFrameSet method.
Identifiers of frames available inside the OGG tag can be enumerated using the combination of the TagsEditor.OGG_UniqueFramesCountGet and TagsEditor.OGG_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.OGG_SaveChanges method.
The OGG Vorbis tag can be removed through the TagsEditor.OGG_RemoveTag method: in this case the tag removal is performed directly on the original sound file.
There is no official MPEG standard on how to embed metadata tags in MP4 files. Apple iTunes therefore started to use their own solution in order to be able to store metadata tags. Those iTunes tags quickly became the de-facto standard for metadata tags within MP4 files. Metadata tags within MP4 files are stored within so-called "boxes" (also known as "atoms").
You can know if the MP4 tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_MP4 this would mean that the MP4 tag is available.
The list of supported MP4 frames, with related identifiers and methods to access stored information, can be found on the table below:
Supported frame types |
Frame identifiers |
Multiple |
Related methods |
Text-based frames |
©alb, ©ART, ©aut, aART, tmpo, catg, dsk, disk, ©cmt, ©wrt, cpil, ©day, ©cpy, ©day, ©des, ©inf, ©dir, ©dis, ©too, ©grp, keyw, ©lyr, ©nam, ©url, ©ope, ©fmt, ©src, ©prf, rate, ©prd, ©wrn |
No |
|
Picture frames |
|
Yes |
TagsEditor.MP4_PictureFrameAddFromBitmap TagsEditor.MP4_PictureFrameAddFromFile TagsEditor.MP4_PictureFrameAddFromMemoryFile TagsEditor.MP4_PictureFrameBitmapGet TagsEditor.MP4_PictureFrameCountGet TagsEditor.MP4_PictureFrameFileGet TagsEditor.MP4_PictureFrameMemoryFileGet TagsEditor.MP4_PictureFrameMimeGet |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsEditor.MP4_PictureFrameCountGet method.
Identifiers of frames available inside the WMA tag can be enumerated using the combination of the TagsEditor.MP4_UniqueFramesCountGet and TagsEditor.MP4_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.MP4_SaveChanges method.
Frames related to metadata can be removed from the MP4 tag through the TagsEditor.MP4_RemoveAllFrames method: in this case the removal is performed directly on the original sound file.
APE tags are closer to Vorbis comments than ID3 tags. Like Vorbis comments, they are unstructured key/value pairs.
You can know if the APE tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_APE this would mean that the APE tag is available.
Predefined text frames can be read through the TagsEditor.APE_TextFieldGet method and modified through the TagsEditor.APE_TextFieldSet method.
User defined text frames can be read through the TagsEditor.APE_UserFieldGet method and modified through the TagsEditor.APE_UserFieldSet method.
Identifiers of frames available inside the APE tag can be enumerated using the combination of the TagsEditor.APE_UniqueFramesCountGet and TagsEditor.APE_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.APE_SaveChanges method.
The APE tag can be removed through the TagsEditor.APE_RemoveTag method: in this case the tag removal is performed directly on the original sound file.
FLAC has it's own native tagging system which is mostly identical to that of OGG Vorbis described above, indeed they are sometime called alternately "FLAC tags" and "Vorbis comments". Respect to the Vorbis tagging system, FLAC allows embedding pictures as well as seen for the ID3V2, WMA and MP4 formats.
You can know if the FLAC tag is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_FLAC this would mean that the FLAC tag is available.
The list of supported FLAC frames can be found on the table below:
Supported frame types |
Multiple |
Related methods |
Text-based frames |
No |
|
Picture frames |
Yes |
TagsEditor.FLAC_PictureFrameAddFromBitmap TagsEditor.FLAC_PictureFrameAddFromFile TagsEditor.FLAC_PictureFrameAddFromMemoryFile TagsEditor.FLAC_PictureFrameAddURL TagsEditor.FLAC_PictureFrameBitmapGet TagsEditor.FLAC_PictureFrameCountGet TagsEditor.FLAC_PictureFrameFileGet TagsEditor.FLAC_PictureFrameInfoGet TagsEditor.FLAC_PictureFrameMemoryFileGet TagsEditor.FLAC_PictureFrameRemove |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsEditor.FLAC_PictureFrameCountGet method.
Identifiers of frames available inside the FLAC tag can be enumerated using the combination of the TagsEditor.FLAC_UniqueFramesCountGet and TagsEditor.FLAC_UniqueFramesIdGet methods.
Modifications performed by modifying an existing frame or by adding a new one only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.FLAC_SaveChanges method.
Frames related to metadata can be removed from the FLAC tag through the TagsEditor.FLAC_RemoveAllFrames method: in this case the removal is performed directly on the original sound file.
WAV files are based upon the RIFF format which consists entirely of "chunks"; some of these chunks allows storing metadata; Audio Sound Editor for .NET supports the reading and writing of the following type of chunks:
• | CART |
• | BEXT |
• | DISP |
You can know if any of the chunks above are available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the combination of any of the following flags, this would mean that the chunks are available: TAG_FLAG_WAV_CART, TAG_FLAG_WAV_BEXT, TAG_FLAG_WAV_DISP and TAG_FLAG_WAV_LIST_INFO.
The CART chunk contains fields and attributes that a large number of broadcast systems use to describe an audio file. Its full specifications can be found inside the CartChunk.org web site.
You can know if the CART chunk is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_CART this would mean that the CART chunk is available.
Text fields can be read through the TagsEditor.WAV_CartChunkTextFieldGet method and modified through the TagsEditor.WAV_CartChunkTextFieldSet method.
Time markers can be read through the TagsEditor.WAV_CartChunkTimeMarkerFieldGet method and modified through the TagsEditor.WAV_CartChunkTimeMarkerFieldSet method.
Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.WAV_SaveChanges method.
The CART chunk can be removed through the TagsEditor.WAV_CartChunkRemove method: in this case the chunk removal is performed directly on the original sound file.
The BEXT chunk (Broadcast Audio Extension) adds to the RIFF format extra parameters needed for the exchange of material between broadcasters.
You can know if the BEXT chunk is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_BEXT this would mean that the BEXT chunk is available.
Text fields can be read through the TagsEditor.WAV_BextChunkTextFieldGet method and modified through the TagsEditor.WAV_BextChunkTextFieldSet method.
Binary fields can be read through the TagsEditor.WAV_BextChunkBinaryFieldGet method and modified through the TagsEditor.WAV_BextChunkBinaryFieldSet method.
Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.WAV_SaveChanges method.
The BEXT chunk can be removed through the TagsEditor.WAV_BextChunkRemove method: in this case the chunk removal is performed directly on the original sound file.
The DISP chunk allows entering a text string to display on the user interface when the WAV file is loaded.
You can know if the DISP chunk is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_DISP this would mean that the DISP chunk is available.
The text field can be read through the TagsEditor.WAV_DisplayChunkTextGet method and modified through the TagsEditor.WAV_DisplayChunkTextSet method.
The DISP chunk can be removed by passing an empty string to the TagsEditor.WAV_DisplayChunkTextSet method.
Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.WAV_SaveChanges method.
The LIST chunk can contain a list of frames (sub-chunks) of type INFO, each of them containing a different text string. As for other kinds of chunks, each INFO frame is defined by a four characters identifier (FOURCC). Some identifier has already been standardized by the EXIF 2.3 specification (for esample 'IART' for 'Artist', 'ICMT' for 'Comments' or 'ICOP' for 'Copyright'), but the user may create new custom ones.
You can know if the LIST INFO chunk is available by checking the value returned by the TagsEditor.ALL_AnalyzeSoundOnEditor or TagsEditor.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_LIST_INFO this would mean that the LIST INFO chunk is available.
Identifiers of INFO frames available inside the LIST chunk can be enumerated using the combination of the TagsEditor.WAV_ListInfoChunkUniqueFramesCountGet and TagsEditor.WAV_ListInfoChunkUniqueFramesIdGet methods.
Single INFO frames can be read through the TagsEditor.WAV_ListInfoChunkFrameGet method and modified through the TagsEditor.WAV_ListInfoChunkFrameSet method.
Single INFO frames can be removed by passing an empty string to the TagsEditor.WAV_ListInfoChunkFrameSet method.
Modifications only happen in memory so, in order to store them inside the original sound file, there is the need to call the TagsEditor.WAV_SaveChanges method.
The LIST INFO chunk can be removed through the TagsEditor.WAV_ListInfoChunkRemove method: in this case the chunk removal is performed directly on the original sound file.
Samples of usage of tags editing through the TagsEditorMan class in Visual C# and Visual Basic.NET can be found inside the following samples installed with the product's setup package:
- TagsEditor
- WavChunkEditor