private BassCDTrackInputSource(char drive, uint trackNo) { _drive = drive; _trackNo = trackNo; int bassDrive = BassUtils.Drive2BassID(_drive); // Note: CD audio is always 44100hz stereo 16-bit. That's 176400 bytes per second. So dividing the track length by 176400 gives the length in seconds. int cdLength = BassCd.BASS_CD_GetTrackLength(bassDrive, BassTrackNo); _length = TimeSpan.FromSeconds((double)cdLength / 176400); }
public static bool GetDiscMatchAndUpdate(string fileName, TrackInfo trackInfo) { int trackNo = 1; //TODO: Detect track from filename? if (trackInfo.TrackNum > 0) { trackNo = trackInfo.TrackNum; } string root = Path.GetPathRoot(fileName); if (string.IsNullOrEmpty(root)) { return(false); } char rootLetter = root[0]; if (PHYSICAL_DISK_ROOTS.Contains(rootLetter) == false) { int drive = BassUtils.Drive2BassID(rootLetter); if (drive > -1) { string cdDbId = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_CDDB); string musicBrainzId = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_MUSICBRAINZ); string upc = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_UPC); string irsc = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_ISRC + (trackNo - 1)); BassCd.BASS_CD_Release(drive); if (!string.IsNullOrEmpty(cdDbId)) { trackInfo.AlbumCdDdId = cdDbId; } if (!string.IsNullOrEmpty(musicBrainzId)) { trackInfo.AlbumMusicBrainzDiscId = musicBrainzId; } if (!string.IsNullOrEmpty(upc)) { trackInfo.AlbumUpcEanId = upc; } if (!string.IsNullOrEmpty(irsc)) { trackInfo.IsrcId = irsc; } return(true); } else { PHYSICAL_DISK_ROOTS.Add(rootLetter); } } return(false); }
public string GetCDDBDiscIDInfo(char driveLetter, char separator) { string retval = null; int drive = BassUtils.Drive2BassID(driveLetter); if (drive > -1) { string id = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_CDDB); retval = id.Replace(' ', separator); BassCd.BASS_CD_Release(drive); } return(retval); }
public string GetCDDBDiscID(char driveLetter) { string retval = null; int drive = BassUtils.Drive2BassID(driveLetter); if (drive > -1) { string id = BassCd.BASS_CD_GetID(drive, BASSCDId.BASS_CDID_CDDB); retval = id.Substring(0, 8); BassCd.BASS_CD_Release(drive); } return(retval); }
/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassCDTrackInputSource.Initialize()"); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_CD_FREEOLD, false); const BASSFlag flags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; int bassDrive = BassUtils.Drive2BassID(_drive); int handle = BassCd.BASS_CD_StreamCreate(bassDrive, BassTrackNo, flags); if (handle == 0) { if (Bass.BASS_ErrorGetCode() == BASSError.BASS_ERROR_ALREADY) { // Drive is already playing - stream must be lazily initialized return; } throw new BassLibraryException("BASS_CD_StreamCreate"); } _bassStream = BassStream.Create(handle); }
/// <summary> /// Detects if an audio CD/DVD/BD is contained in the given <paramref name="drive"/>. /// </summary> /// <param name="drive">The drive to be examined.</param> /// <param name="tracks">Returns a collection of audio tracks for the audio CD in the given <paramref name="drive"/>.</param> /// <param name="extractedMIATypeIDs">IDs of the media item aspect types which were extracted from the returned <paramref name="tracks"/>.</param> /// <returns><c>true</c>, if an audio CD was identified, else <c>false</c>.</returns> public static bool DetectAudioCD(DriveInfo driveInfo, out ICollection <MediaItem> tracks, out ICollection <Guid> extractedMIATypeIDs) { tracks = null; extractedMIATypeIDs = null; string drive = driveInfo.Name; if (string.IsNullOrEmpty(drive) || drive.Length < 2) { return(false); } drive = drive.Substring(0, 2); // Clip potential '\\' at the end try { IList <BassUtils.AudioTrack> audioTracks = BassUtils.GetAudioTracks(drive); // BassUtils can report wrong audio tracks for some devices, we filter out "Duration = -1" here audioTracks = audioTracks?.Where(t => t.Duration > 0).ToList(); if (audioTracks == null || audioTracks.Count == 0) { return(false); } ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>(); string systemId = systemResolver.LocalSystemId; tracks = new List <MediaItem>(audioTracks.Count); char driveChar = drive[0]; int driveId = BassUtils.Drive2BassID(driveChar); if (driveId > -1) { BASS_CD_INFO info = BassCd.BASS_CD_GetInfo(driveId); if (info.cdtext) { string[] tags = BassCd.BASS_CD_GetIDText(driveId); string album = GetCDText(tags, "TITLE"); string albumArtist = GetCDText(tags, "PERFORMER"); foreach (BassUtils.AudioTrack track in audioTracks) { tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId, album, albumArtist, album, albumArtist, irsc: BassCd.BASS_CD_GetISRC(driveId, track.TrackNo - 1))); } } else { foreach (BassUtils.AudioTrack track in audioTracks) { tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId, irsc: BassCd.BASS_CD_GetISRC(driveId, track.TrackNo - 1))); } } BassCd.BASS_CD_Release(driveId); } else { foreach (BassUtils.AudioTrack track in audioTracks) { tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId)); } } extractedMIATypeIDs = new List <Guid> { ProviderResourceAspect.ASPECT_ID, MediaAspect.ASPECT_ID, AudioAspect.ASPECT_ID, ExternalIdentifierAspect.ASPECT_ID, }; } catch (IOException) { ServiceRegistration.Get <ILogger>().Warn("Error enumerating tracks of audio CD in drive {0}", drive); tracks = null; return(false); } return(true); }