Archive

Posts Tagged ‘editor’

How to Read / Write ID3 Tags in MP3 Files

December 15th, 1999 m3Rlin 3 comments

The thing that makes MPEG Layer 3 files good (besides their size:) are ID3 tags. Thanks to them you can save information about the song. Here’s the ID3 tag structure and information on reading/modifying them. Enjoy!
The ID3 tag is saved in the last 128 bytes of a MPEG Layer 3 file. It starts with a “TAG” string. If this string is absent that means that ID3 information has been removed. But don’t worry – all you have to do is append it to the file.
In newer versions of Delphi if you are going to use this code you may want to use the packed keyword with arrays and records.
The MPEG Layer 3 ID3 tag structure:

  ID3Struct = record
    Signature: array[0..2] of Char; { Should be: "TAG" }
    Title,
    Artist,
    Album: array[0..29] of Char;
    Year: array[0..3] of Char;
    Comment: array[0..29] of Char;
    Genre: Byte;
  end;

Here’s the genre (Max. 256 entries).

  ID3Genre: array[0..126] of string = (
    'Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge',
    'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B',
    'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska',
    'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient',
    'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical',
    'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel',
    'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative',
    'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic',
    'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk',
    'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta',
    'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American',
    'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer',
    'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro',
    'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock',
    'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival',
    'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock',
    'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band',
    'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson',
    'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus',
    'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba',
    'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle',
    'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall'
  );

This is the ID3 Tag read code:

var
  fMP3: file of Byte;
  Tag: ID3Struct;
begin
  try
    (* sFileName - (string) The full file name with path. *)
    AssignFile(fMP3, sFileName);
    Reset(fMP3);
    try
      Seek(fMP3, FileSize(fMP3) - 128);
      BlockRead(fMP3, Tag, SizeOf(Tag));
    finally
    end;
  finally
    CloseFile(fMP3);
  end;
  if fMP3.Signature <> 'TAG' then begin
    ...
    { Doesn't have an ID3 tag }
  end else begin
    ...
    { Do something with the tag }
  end;
end;

(* WriteID3Tag() function
**
** Copyright (c) 2000 Jacob Dybala (m3Rlin)
** Freeware.
**
** Created : January 7 2000
** Modified: January 7 2000
** Please leave this copyright notice.
*)
procedure WriteID3Tag(id3NewTag: ID3Struct; sFileName: string);
var
  fMP3: file of Byte;
  Tag : ID3Struct;
begin
  try
    AssignFile(fMP3, sFileName);
    Reset(fMP3);
    try
      Seek(fMP3, FileSize(fMP3) - ID3OffsetFromEnd);
      BlockRead(fMP3, Tag, SizeOf(Tag));
      if fMP3.Signature = 'TAG' then
        { Replace old tag }
        Seek(fMP3, FileSize(fMP3) - ID3OffsetFromEnd)
      else
        (* Append tag to file because it doesn't exist.
        * Cannot use Append() function. It's only for text files.
        *)
        Seek(fMP3, FileSize(fMP3));
      BlockWrite(fMP3, id3NewTag, SizeOf(id3NewTag));
    finally
    end;
  finally
    CloseFile(fMP3);
  end;
end;

What is Delphi?

December 15th, 1999 m3Rlin No comments

Delphi is the descendant of Turbo Pascal, which was first released in 1983 for the CP/M operating system. Turbo Pascal was ported to MS-DOS in early 1984. During the early history of the IBM PC, Turbo Pascal was arguably the most popular language for serious development work – mostly because it was a real compiler, including the program editor and everything, that cost $19.95 and would run on a 128Kb machine. Borland introduced Turbo Pascal for Windows in 1990. In the early days of DOS, programmers had a choice between productive-but-slow BASIC or efficient-but-complex assembly language. Turbo Pascal, which offered the simplicity of a structured language and the performance of a real compiler, bridged that gap. Windows programmers face a similar choice today – a choice primarily between a powerful yet unwieldy language such as C++, or a simple but limiting and slow languages such as Visual Basic. Delphi offers you a great deal: visual development and code generation, compiled executables, DLLs; databases and much more. The latest release of Borland Pascal (as it is now called), not including Delphi, was version 7.0 in late 1992.

Delphi had an unusually long development cycle – somewhere between 18 months and two years, depending on who you talk to. Various beta-test and prerelease copies have been circulated, including several hundred “early experience” copies which were given away at the trade show Software Development ’95. Delphi was officially announced in the U.S. on Feb. 14, 1995, and the first release-level copies were shipped on February 28.

Delphi is and an object-oriented, visual programming environment for rapid application development (RAD). Using Delphi, you can create applications for Microsoft Windows 3.1x, 95/98/NT/2000, ME and XP.

Database development refers to the fact that Delphi is an ideal tool to design database client applications that communicate with a variety of local or remote databases. The standard version of Delphi has the capability to connect to local Paradox, dBase and ODBC tables, and Delphi Client/Server comes with SQL Links drivers for a variety of networked SQL server databases. If you are a “regular programmer”, this means you finally have a database engine built seamlessly into your development environments. Programmers don?t have to rely on third-party database library?s when they need the data-management capability of a true database in their applications.

Programs compiled in Delphi 1 are 8-15 times faster than if they were compiled by Microsoft Visual Basic 3/4. This is due to the fact that programs created with Delphi do not need any runtime libraries and the generated is code is not translated during the program execution. Delphi also has built-in x86 assembler support (286 for Delphi 1.0 and 386 for Delphi 2+) so you can write your time-critical functions in pure assembler. Also Delphi supports VCL (Visual Component Libray). These are visual and non-visual components (buttons, frames, edit boxes, …) They are available all over the Internet and they are very easy to write yourself. Delphi itself is said to be written in a combination of Delphi and assembler. Delphi is created by Borland International.