]> granicus.if.org Git - taglib/commitdiff
more correct S3M parsing and property naming
authorMathias Panzenböck <grosser.meister.morti@gmx.net>
Sun, 19 Jun 2011 20:46:33 +0000 (22:46 +0200)
committerMathias Panzenböck <grosser.meister.morti@gmx.net>
Sun, 19 Jun 2011 20:46:33 +0000 (22:46 +0200)
taglib/s3m/s3mfile.cpp
taglib/s3m/s3mproperties.cpp
taglib/s3m/s3mproperties.h

index d48911d7a7c66cb10e7685cb2e72dda68ba183bc..0752f15dc232ff7fb66aabd618928cbbd47f5aeb 100644 (file)
@@ -24,6 +24,8 @@
 #include "tdebug.h"
 #include "modfileprivate.h"
 
+#include <iostream>
+
 using namespace TagLib;
 using namespace S3M;
 
@@ -146,25 +148,24 @@ void S3M::File::read(bool)
 
   READ_U16L(d->properties.setPatternCount);
   READ_U16L(d->properties.setFlags);
-  READ_U16L(d->properties.setVersion);
-  READ_U16L(d->properties.setSamplesType);
+  READ_U16L(d->properties.setTrackerVersion);
+  READ_U16L(d->properties.setFileFormatVersion);
 
   READ_ASSERT(readBlock(4) == "SCRM");
 
-  READ_BYTE_AS(baseVolume);
-  d->properties.setBaseVolume((int)baseVolume << 1);
-
-  READ_BYTE(d->properties.setTempo);
+  READ_BYTE(d->properties.setGlobalVolume);
   READ_BYTE(d->properties.setBpmSpeed);
+  READ_BYTE(d->properties.setTempo);
 
-  READ_BYTE_AS(stereo);
-  d->properties.setStereo((stereo & 0x80) != 0);
-  READ_BYTE(d->properties.setUltraClick);
+  READ_BYTE_AS(masterVolume);
+  d->properties.setMasterVolume(masterVolume & 0x7f);
+  d->properties.setStereo((masterVolume & 0x80) != 0);
 
-  READ_BYTE_AS(usePanningValues);
-  d->properties.setUsePanningValues(usePanningValues == 0xFC);
+  // I've seen players who call the next two bytes
+  // "ultra click" and "use panning values" (if == 0xFC).
+  // I don't see them in any spec, though.
 
-  seek(10, Current);
+  seek(12, Current);
 
   int channels = 0;
   for(int i = 0; i < 32; ++ i)
@@ -179,30 +180,38 @@ void S3M::File::read(bool)
 
   seek(channels, Current);
 
+  // Note: The S3M spec mentions instruments, but I could
+  //       not figure out where these can be found. They are
+  //       similar to samples, though (SCRI instead of SCRS).
   StringList comment;
   for(ushort i = 0; i < sampleCount; ++ i)
   {
     seek(96L + length + ((long)i << 1));
 
-    READ_U16L_AS(instrumentOffset);
-    seek((long)instrumentOffset << 4);
+    READ_U16L_AS(sampleHeaderOffset);
+    seek((long)sampleHeaderOffset << 4);
 
     READ_BYTE_AS(sampleType);
     READ_STRING_AS(dosFileName, 13);
-    READ_U16L_AS(sampleOffset);
+    READ_U16L_AS(sampleDataOffset);
     READ_U32L_AS(sampleLength);
     READ_U32L_AS(repeatStart);
     READ_U32L_AS(repeatStop);
     READ_BYTE_AS(sampleVolume);
 
-    seek(2, Current);
+    seek(1, Current);
 
+    READ_BYTE_AS(packing);
     READ_BYTE_AS(sampleFlags);
     READ_U32L_AS(baseFrequency);
 
     seek(12, Current);
 
     READ_STRING_AS(sampleName, 28);
+    // The next 4 bytes should be "SCRS", but I've found
+    // otherwise ok files with 4 nils instead.
+    // READ_ASSERT(readBlock(4) == "SCRS");
+
     comment.append(sampleName);
   }
 
index 88ed87970d1f626a26003bafca37b6952f4d3d48..30264f44358d8402bde4cc58c666dbae5e713c12 100644 (file)
@@ -34,13 +34,14 @@ public:
     sampleCount(0),
     patternCount(0),
     flags(0),
-    version(0),
-    samplesType(0),
-    baseVolume(0),
+    trackerVersion(0),
+    fileFormatVersion(0),
+    globalVolume(0),
+    masterVolume(0),
     tempo(0),
-    bpmSpeed(0),
-    ultraClick(0),
-    usePanningValues(false) {}
+    bpmSpeed(0)
+  {
+  }
   
   ushort tableLength;
   int    channels;
@@ -48,13 +49,12 @@ public:
   ushort sampleCount;
   ushort patternCount;
   ushort flags;
-  ushort version;
-  ushort samplesType;
-  int    baseVolume;
+  ushort trackerVersion;
+  ushort fileFormatVersion;
+  uchar  globalVolume;
+  uchar  masterVolume;
   uchar  tempo;
   uchar  bpmSpeed;
-  uchar  ultraClick;
-  bool   usePanningValues;
 };
 
 S3M::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
@@ -113,19 +113,24 @@ ushort S3M::Properties::flags() const
   return d->flags;
 }
 
-ushort S3M::Properties::version() const
+ushort S3M::Properties::trackerVersion() const
 {
-  return d->version;
+  return d->trackerVersion;
 }
 
-ushort S3M::Properties::samplesType() const
+ushort S3M::Properties::fileFormatVersion() const
 {
-  return d->samplesType;
+  return d->fileFormatVersion;
 }
 
-int S3M::Properties::baseVolume() const
+uchar S3M::Properties::globalVolume() const
 {
-  return d->baseVolume;
+  return d->globalVolume;
+}
+
+uchar S3M::Properties::masterVolume() const
+{
+  return d->masterVolume;
 }
 
 uchar S3M::Properties::tempo() const
@@ -138,16 +143,6 @@ uchar S3M::Properties::bpmSpeed() const
   return d->bpmSpeed;
 }
 
-uchar S3M::Properties::ultraClick() const
-{
-  return d->ultraClick;
-}
-
-bool S3M::Properties::usePanningValues() const
-{
-  return d->usePanningValues;
-}
-
 void S3M::Properties::setTableLength(ushort tableLength)
 {
   d->tableLength = tableLength;
@@ -178,19 +173,24 @@ void S3M::Properties::setFlags(ushort flags)
   d->flags = flags;
 }
 
-void S3M::Properties::setVersion(ushort version)
+void S3M::Properties::setTrackerVersion(ushort trackerVersion)
 {
-  d->version = version;
+  d->trackerVersion = trackerVersion;
 }
 
-void S3M::Properties::setSamplesType(ushort samplesType)
+void S3M::Properties::setFileFormatVersion(ushort fileFormatVersion)
 {
-  d->samplesType = samplesType;
+  d->fileFormatVersion = fileFormatVersion;
 }
 
-void S3M::Properties::setBaseVolume(int baseVolume)
+void S3M::Properties::setGlobalVolume(uchar globalVolume)
 {
-  d->baseVolume = baseVolume;
+  d->globalVolume = globalVolume;
+}
+
+void S3M::Properties::setMasterVolume(uchar masterVolume)
+{
+  d->masterVolume = masterVolume;
 }
 
 void S3M::Properties::setTempo(uchar tempo)
@@ -202,13 +202,3 @@ void S3M::Properties::setBpmSpeed(uchar bpmSpeed)
 {
   d->bpmSpeed = bpmSpeed;
 }
-
-void S3M::Properties::setUltraClick(uchar ultraClick)
-{
-  d->ultraClick = ultraClick;
-}
-
-void S3M::Properties::setUsePanningValues(bool usePanningValues)
-{
-  d->usePanningValues = usePanningValues;
-}
index 80ab4aa266b7f4c8c2886681d616417a1ee63d60..8721477071ab049123daf6f1c5cf9c7ddd052068 100644 (file)
@@ -38,34 +38,32 @@ namespace TagLib {
       int sampleRate() const;
       int channels()   const;
 
-      ushort tableLength()  const;
-      bool   stereo()       const;
-      ushort sampleCount()  const;
-      ushort patternCount() const;
-      ushort flags()        const;
-      ushort version()      const;
-      ushort samplesType()  const;
-      int    baseVolume()   const;
-      uchar  tempo()        const;
-      uchar  bpmSpeed()     const;
-      uchar  ultraClick()   const;
-      bool   usePanningValues() const;
+      ushort tableLength()       const;
+      bool   stereo()            const;
+      ushort sampleCount()       const;
+      ushort patternCount()      const;
+      ushort flags()             const;
+      ushort trackerVersion()    const;
+      ushort fileFormatVersion() const;
+      uchar  globalVolume()      const;
+      uchar  masterVolume()      const;
+      uchar  tempo()             const;
+      uchar  bpmSpeed()          const;
 
     protected:
       void setTableLength(ushort tableLength);
       void setChannels(int channels);
 
-      void setStereo      (bool stereo);
-      void setSampleCount (ushort sampleCount);
-      void setPatternCount(ushort patternCount);
-      void setFlags       (ushort flags);
-      void setVersion     (ushort version);
-      void setSamplesType (ushort samplesType);
-      void setBaseVolume  (int baseVolume);
-      void setTempo       (uchar tempo);
-      void setBpmSpeed    (uchar bpmSpeed);
-      void setUltraClick  (uchar ultraClick);
-      void setUsePanningValues(bool usePanningValues);
+      void setStereo           (bool stereo);
+      void setSampleCount      (ushort sampleCount);
+      void setPatternCount     (ushort patternCount);
+      void setFlags            (ushort flags);
+      void setTrackerVersion   (ushort trackerVersion);
+      void setFileFormatVersion(ushort fileFormatVersion);
+      void setGlobalVolume     (uchar globalVolume);
+      void setMasterVolume     (uchar masterVolume);
+      void setTempo            (uchar tempo);
+      void setBpmSpeed         (uchar bpmSpeed);
 
     private:
       Properties(const Properties&);