/// <summary> /// Reads the tag of a file /// </summary> /// <param name="filename"></param> public TagInfo ReadTags(string filename) { FMOD.Sound snd = null; TagInfo tagInfo = null; try { //if ok, create a sound with tag support FMOD.RESULT result; //open the sound for tag reading result = _system.createStream(filename, FMOD.MODE.OPENONLY, out snd); CheckError(result); //if ok, get the number of tags in the fie int numTags; int numTagsUpdated; //get num tags result = snd.getNumTags(out numTags, out numTagsUpdated); CheckError(result); //read the tags tagInfo = ReadTags(snd, numTags); } catch (Exception) { //ignore errors for now } finally { if (snd != null) { //release the sound snd.release(); snd = null; } } //return the tag info return(tagInfo); }
private void timer_Tick(object sender, System.EventArgs e) { FMOD.RESULT result; FMOD.OPENSTATE openstate = 0; if (soundcreated) { uint percentbuffered = 0; bool starving = false; bool busy = false; result = sound.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); ERRCHECK(result); if (openstate == FMOD.OPENSTATE.READY && channel == null) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); } } if (channel != null) { uint ms = 0; bool playing = false; bool paused = false; int tagsupdated = 0; int numtags = 0; result = sound.getNumTags(ref numtags, ref tagsupdated); ERRCHECK(result); if (tagsupdated != 0) { for (;;) { FMOD.TAG tag = new FMOD.TAG(); if (sound.getTag(null, -1, ref tag) != FMOD.RESULT.OK) { break; } if (tag.datatype == FMOD.TAGDATATYPE.STRING) { FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE; int channels = 0; int bits = 0; sound.getFormat(ref gSoundType, ref format, ref channels, ref bits); if (tag.name == "ARTIST") { if (Marshal.PtrToStringAnsi(tag.data) != gCurrentTrackArtist) { gCurrentTrackArtist = Marshal.PtrToStringAnsi(tag.data); gUpdateFileName = true; } } if (tag.name == "TITLE") { if (Marshal.PtrToStringAnsi(tag.data) != gCurrentTrackTitle) { gCurrentTrackTitle = Marshal.PtrToStringAnsi(tag.data); gUpdateFileName = true; } } break; } else { break; } } } result = channel.isPlaying(ref playing); if (result != FMOD.RESULT.OK || !playing) { sound.release(); sound = null; channel = null; } else { result = channel.getPaused(ref paused); ERRCHECK(result); result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS); ERRCHECK(result); statusBar.Text = "Time " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + (paused ? " Paused " : playing ? " Playing" : " Stopped"); } } if (sound != null) { uint percentbuffered = 0; bool starving = false; bool busy = false; sound.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); if (openstate == FMOD.OPENSTATE.ERROR) { sound.release(); sound = null; channel = null; } } if (openstate == FMOD.OPENSTATE.ERROR) { statusBar.Text = "Error occurred or stream ended. Restarting stream.."; result = system.createSound(url, (FMOD.MODE.HARDWARE | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.NONBLOCKING), ref exinfo, ref sound); ERRCHECK(result); } if (system != null) { system.update(); } }
/// <summary> /// Die Informationen (TOC) einer CD auslesen /// </summary> public CDInfo ReadCDInformation(char driveLetter) { if (Settings.Current.UseMCI) { return(ReadCDInformationMCI(driveLetter)); } CDInfo mciCDInfo = ReadCDInformationMCI(driveLetter); if (mciCDInfo.Tracks.Any(x => x.TrackType != TrackType.Audio)) // Bei einer Daten-CD nehmen wir MCI { return(mciCDInfo); } string drive = string.Format("{0}:", driveLetter); FMOD.Sound cdSound = null; FMOD.RESULT result = system.createStream(drive, FMOD.MODE.OPENONLY, ref cdSound); if (result != FMOD.RESULT.OK || cdSound == null) { return(mciCDInfo); } int numberOfTracks = 0; cdSound.getNumSubSounds(ref numberOfTracks); FMOD.CDTOC cdToc = new FMOD.CDTOC(); int numtags = 0; int numtagsupdated = 0; cdSound.getNumTags(ref numtags, ref numtagsupdated); for (int i = 0; i < numtags; i++) { FMOD.TAG tag = new FMOD.TAG(); if (cdSound.getTag(null, i, ref tag) != FMOD.RESULT.OK) { break; } if (tag.datatype == FMOD.TAGDATATYPE.CDTOC) { cdToc = (FMOD.CDTOC)Marshal.PtrToStructure(tag.data, typeof(FMOD.CDTOC)); break; } } CDInfo cdInfo = new CDInfo(); int trackNr = 0; for (; trackNr < numberOfTracks; trackNr++) { CDInfoTrack track = new CDInfoTrack(); track.StartTime = (((cdToc.min[trackNr] * 60 + cdToc.sec[trackNr]) * 75 + cdToc.frame[trackNr]) * 1000 + 74) / 75; if (trackNr > 0) { cdInfo.Tracks[trackNr - 1].Length = track.StartTime - cdInfo.Tracks[trackNr - 1].StartTime; } track.TrackType = TrackType.Audio; cdInfo.Tracks.Add(track); } cdInfo.TotalLength = (((cdToc.min[numberOfTracks] * 60 + cdToc.sec[numberOfTracks]) * 75 + cdToc.frame[numberOfTracks]) * 1000 + 74) / 75; cdInfo.Tracks[trackNr - 1].Length = cdInfo.TotalLength - cdInfo.Tracks[trackNr - 1].StartTime; cdSound.release(); /*StringBuilder volumeName = new StringBuilder(1000); * StringBuilder fileSystemNameBuffer = new StringBuilder(1000); * uint serialNumber = 0; * uint maximumComponentLength = 0; * uint fileSystemFlags = 0; * GetVolumeInformation(drive, volumeName, 1000, ref serialNumber, ref maximumComponentLength, ref fileSystemFlags, fileSystemNameBuffer, 1000); * * cdInfo.Identity = serialNumber.ToString();*/ cdInfo.Identity = mciCDInfo.Identity; return(cdInfo); }
private void ReadTags_Load(object sender, System.EventArgs e) { FMOD.TAG tag = new FMOD.TAG(); int numtags = 0, numtagsupdated = 0; uint version = 0; FMOD.RESULT result; /* * Create a System object and initialize. */ result = FMOD.Factory.System_Create(ref system); ERRCHECK(result); result = system.getVersion(ref version); ERRCHECK(result); if (version < FMOD.VERSION.number) { MessageBox.Show("Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + FMOD.VERSION.number.ToString("X") + "."); Application.Exit(); } result = system.init(100, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); /* * Open the specified file. Use FMOD_CREATESTREAM and FMOD_DONTPREBUFFER so it opens quickly */ result = system.createSound("../../../../../examples/media/wave.mp3", (FMOD.MODE.SOFTWARE | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.OPENONLY), ref sound); ERRCHECK(result); /* * Read and display all tags associated with this file */ for (;;) { /* * An index of -1 means "get the first tag that's new or updated". * If no tags are new or updated then getTag will return FMOD_ERR_TAGNOTFOUND. * This is the first time we've read any tags so they'll all be new but after we've read them, * they won't be new any more. */ if (sound.getTag(null, -1, ref tag) != FMOD.RESULT.OK) { break; } if (tag.datatype == FMOD.TAGDATATYPE.STRING) { listBox.Items.Add(tag.name + " = " + Marshal.PtrToStringAnsi(tag.data) + " (" + tag.datalen + " bytes)"); } else { listBox.Items.Add(tag.name + " = <binary> (" + tag.datalen + " bytes)"); } } listBox.Items.Add(" "); /* * Read all the tags regardless of whether they're updated or not. Also show the tag type. */ result = sound.getNumTags(ref numtags, ref numtagsupdated); ERRCHECK(result); for (int count = 0; count < numtags; count++) { string tagtext = null; result = sound.getTag(null, count, ref tag); ERRCHECK(result); switch (tag.type) { case FMOD.TAGTYPE.UNKNOWN: tagtext = "FMOD_TAGTYPE_UNKNOWN "; break; case FMOD.TAGTYPE.ID3V1: tagtext = "FMOD_TAGTYPE_ID3V1 "; break; case FMOD.TAGTYPE.ID3V2: tagtext = "FMOD_TAGTYPE_ID3V2 "; break; case FMOD.TAGTYPE.VORBISCOMMENT: tagtext = "FMOD_TAGTYPE_VORBISCOMMENT "; break; case FMOD.TAGTYPE.SHOUTCAST: tagtext = "FMOD_TAGTYPE_SHOUTCAST "; break; case FMOD.TAGTYPE.ICECAST: tagtext = "FMOD_TAGTYPE_ICECAST "; break; case FMOD.TAGTYPE.ASF: tagtext = "FMOD_TAGTYPE_ASF "; break; case FMOD.TAGTYPE.FMOD: tagtext = "FMOD_TAGTYPE_FMOD "; break; case FMOD.TAGTYPE.USER: tagtext = "FMOD_TAGTYPE_USER "; break; } if (tag.datatype == FMOD.TAGDATATYPE.STRING) { tagtext += (tag.name + " = " + Marshal.PtrToStringAnsi(tag.data) + "(" + tag.datalen + " bytes)"); } else { tagtext += (tag.name + " = ??? (" + tag.datalen + " bytes)"); } listBox.Items.Add(tagtext); } listBox.Items.Add(" "); /* * Find a specific tag by name. Specify an index > 0 to get access to multiple tags of the same name. */ result = sound.getTag("ARTIST", 0, ref tag); ERRCHECK(result); listBox.Items.Add(tag.name + " = " + Marshal.PtrToStringAnsi(tag.data) + " (" + tag.datalen + " bytes)"); }
public static void GetSoundTags(string filename, SoundFileInformation soundFileInfo) { FMOD.Sound sound = null; FMOD.RESULT res = SoundEngine.Instance.system.createStream(filename, FMOD.MODE.OPENONLY, ref sound); if (sound != null) { int numtags = 0; int num2tags = 0; sound.getNumTags(ref numtags, ref num2tags); for (int i = 0; i < numtags; i++) { FMOD.TAG tag2 = new FMOD.TAG(); res = sound.getTag(null, i, ref tag2); if (res != FMOD.RESULT.ERR_TAGNOTFOUND) { string tagName = tag2.name.ToLower(); if (tagName == "title") { soundFileInfo.Title = Marshal.PtrToStringAnsi(tag2.data); } if (tagName == "author" || tagName == "artist") { soundFileInfo.Artist = Marshal.PtrToStringAnsi(tag2.data); } if (tagName == "wm/tracknumber" || tagName == "tracknumber") { if (tag2.datatype == FMOD.TAGDATATYPE.STRING) { soundFileInfo.TrackNumber = Big3.Hitbase.Miscellaneous.Misc.Atoi(Marshal.PtrToStringAnsi(tag2.data)); } if (tag2.datatype == FMOD.TAGDATATYPE.INT) { soundFileInfo.TrackNumber = Convert.ToInt32(Marshal.ReadInt32(tag2.data)); } } if (tagName == "wm/composer") { soundFileInfo.Composer = Marshal.PtrToStringAnsi(tag2.data); } if (tagName == "wm/albumtitle" || tagName == "album") { soundFileInfo.Album = Marshal.PtrToStringAnsi(tag2.data); } if (tagName == "wm/year") { soundFileInfo.Year = Big3.Hitbase.Miscellaneous.Misc.Atoi(Marshal.PtrToStringAnsi(tag2.data)); } if (tagName == "wm/genre" || tagName == "genre") { soundFileInfo.Genre = Marshal.PtrToStringAnsi(tag2.data); } } } sound.release(); } }