~ubuntu-branches/ubuntu/karmic/tangerine/karmic

« back to all changes in this revision

Viewing changes to deps/taglib-sharp/TagLib/Ogg/Vorbis/Properties.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-08-18 21:38:02 UTC
  • mfrom: (2.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090818213802-oqfj7o0bxxu3ti4e
Tags: 0.3.2.2-1
* New upstream release
* debian/watch, debian/control:
  + Update to new homepage
* debian/control:
  + No-change bump to Standards 3.8.3
  + Add myself to Uploaders, and drop some inactive contributors' names
  + Update Vcs-* fields to reflect migration to git
  + Update build depends:
    - Update order to reflect configure.ac order
    - Drop libavahi1.0-cil, libmono-sqlite2.0-cil, cdbs
    - Add banshee, libmono-zeroconf1.0-cil, libndesk-dbus-glib1.0-cil
    - Use DH7
  + Add a debug package, tangerine-dbg
* debian/rules:
  + Rewrite to use DH7
  + Clean up get-orig-source rule
  + Add some custom configure flags
  + Add dh_{,cli}strip overrides to strip into tangerine-dbg
  + Remove /usr/share/doc/tangerine/sample.conf since it's handled by
    dh_installexamples
* debian/compat:
  + Bump to 7
* debian/copyright:
  + Update and use DEP-5
* debian/tangerine*.1, debian/tangerine.manpages:
  + Added manpages for tangerine and tangerine-properties.
* debian/tangerine.examples:
  + Install sample.conf as a sample conf file for ~/.tangerine
* debian/patches:
  + Drop all patches, since they are either applied upstream or no
    longer relevant.
* debian/*.dll.config:
  + Dropped, no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2006 by Brian Nickel
3
 
    email                : brian.nickel@gmail.com
4
 
    based on             : audioproperties.cpp from TagLib
5
 
 ***************************************************************************/
6
 
 
7
 
/***************************************************************************
8
 
 *   This library is free software; you can redistribute it and/or modify  *
9
 
 *   it  under the terms of the GNU Lesser General Public License version  *
10
 
 *   2.1 as published by the Free Software Foundation.                     *
11
 
 *                                                                         *
12
 
 *   This library is distributed in the hope that it will be useful, but   *
13
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
14
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
15
 
 *   Lesser General Public License for more details.                       *
16
 
 *                                                                         *
17
 
 *   You should have received a copy of the GNU Lesser General Public      *
18
 
 *   License along with this library; if not, write to the Free Software   *
19
 
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
 
 *   USA                                                                   *
21
 
 ***************************************************************************/
22
 
 
23
 
using System.Collections;
24
 
using System;
25
 
 
26
 
namespace TagLib.Ogg.Vorbis
27
 
{
28
 
   public class Properties : AudioProperties
29
 
   {
30
 
      //////////////////////////////////////////////////////////////////////////
31
 
      // private properties
32
 
      //////////////////////////////////////////////////////////////////////////
33
 
      private TimeSpan  duration;
34
 
      private int       bitrate;
35
 
      private int       sample_rate;
36
 
      private int       channels;
37
 
      private int       vorbis_version;
38
 
      private int       bitrate_maximum;
39
 
      private int       bitrate_nominal;
40
 
      private int       bitrate_minimum;
41
 
      
42
 
      private static byte [] vorbis_comment_header_id = {0x01, (byte)'v', (byte)'o', (byte)'r', (byte)'b', (byte)'i', (byte)'s'};
43
 
      
44
 
      
45
 
      //////////////////////////////////////////////////////////////////////////
46
 
      // public methods
47
 
      //////////////////////////////////////////////////////////////////////////
48
 
      public Properties (File file, ReadStyle style) : base (style)
49
 
      {
50
 
         duration        = TimeSpan.Zero;
51
 
         bitrate         = 0;
52
 
         sample_rate     = 0;
53
 
         channels        = 0;
54
 
         vorbis_version  = 0;
55
 
         bitrate_maximum = 0;
56
 
         bitrate_nominal = 0;
57
 
         bitrate_minimum = 0;
58
 
         
59
 
         Read (file, style);
60
 
      }
61
 
 
62
 
      public Properties (File file) : this (file, ReadStyle.Average)
63
 
      {
64
 
      }
65
 
      
66
 
      
67
 
      //////////////////////////////////////////////////////////////////////////
68
 
      // public properties
69
 
      //////////////////////////////////////////////////////////////////////////
70
 
      public override TimeSpan Duration       {get {return duration;}}
71
 
      public override int      Bitrate        {get {return (int) ((float)bitrate / 1000f + 0.5);}}
72
 
      public override int      SampleRate     {get {return sample_rate;}}
73
 
      public override int      Channels       {get {return channels;}}
74
 
      public          int      VorbisVersion  {get {return vorbis_version;}}
75
 
      public          int      BitrateMaximum {get {return bitrate_maximum;}}
76
 
      public          int      BitrateNominal {get {return bitrate_nominal;}}
77
 
      public          int      BitrateMinimum {get {return bitrate_minimum;}}
78
 
      
79
 
      
80
 
      //////////////////////////////////////////////////////////////////////////
81
 
      // private methods
82
 
      //////////////////////////////////////////////////////////////////////////
83
 
      private void Read (File file, ReadStyle style)
84
 
      {
85
 
         // Get the identification header from the Ogg implementation.
86
 
 
87
 
         ByteVector data = file.GetPacket (0);
88
 
 
89
 
         int pos = 0;
90
 
 
91
 
         if (data.Mid (pos, 7) != vorbis_comment_header_id)
92
 
         {
93
 
            Debugger.Debug ("Vorbis.Properties.Read() -- invalid Vorbis identification header");
94
 
            return;
95
 
         }
96
 
 
97
 
         pos += 7;
98
 
 
99
 
         vorbis_version = (int) data.Mid(pos, 4).ToUInt (false);
100
 
         pos += 4;
101
 
 
102
 
         channels = data [pos];
103
 
         pos += 1;
104
 
 
105
 
         sample_rate = (int) data.Mid(pos, 4).ToUInt (false);
106
 
         pos += 4;
107
 
 
108
 
         bitrate_maximum = (int) data.Mid(pos, 4).ToUInt (false);
109
 
         pos += 4;
110
 
 
111
 
         bitrate_nominal = (int) data.Mid(pos, 4).ToUInt (false);
112
 
         pos += 4;
113
 
 
114
 
         bitrate_minimum = (int) data.Mid(pos, 4).ToUInt (false);
115
 
 
116
 
         // TODO: Later this should be only the "fast" mode.
117
 
         bitrate = bitrate_nominal;
118
 
 
119
 
         // Find the length of the file.  See http://wiki.xiph.org/VorbisStreamLength/
120
 
         // for my notes on the topic.
121
 
 
122
 
         Ogg.PageHeader first = file.FirstPageHeader;
123
 
         Ogg.PageHeader last = file.LastPageHeader;
124
 
 
125
 
         if (first != null && last != null)
126
 
         {
127
 
            long start = first.AbsoluteGranularPosition;
128
 
            long end = last.AbsoluteGranularPosition;
129
 
 
130
 
            if (start >= 0 && end >= 0 && sample_rate > 0)
131
 
               duration = TimeSpan.FromSeconds (((double)(end - start) / (double) sample_rate));
132
 
            else
133
 
               Debugger.Debug ("Vorbis.Properties.Read() -- Either the PCM " +
134
 
                               "values for the start or end of this file was " +
135
 
                               "incorrect or the sample rate is zero.");
136
 
         }
137
 
         else
138
 
            Debugger.Debug("Vorbis.Properties.Read() -- Could not find valid first and last Ogg pages.");
139
 
      }
140
 
   }
141
 
}