Minecraft
  1. Minecraft
  2. MC-89848

playsound/sound engine pitch algorithm isn't working properly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 15w40b, Minecraft 15w41b, Minecraft 15w43a, Minecraft 15w44a, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47a, Minecraft 15w47b, Minecraft 15w47c, Minecraft 15w49a, Minecraft 15w49b, Minecraft 15w50a, Minecraft 15w51a, Minecraft 15w51b, Minecraft 16w02a, Minecraft 16w03a, Minecraft 16w04a, Minecraft 16w05a, Minecraft 16w05b, Minecraft 16w06a, Minecraft 16w07a, Minecraft 16w07b, Minecraft 1.9 Pre-Release 1, Minecraft 1.9 Pre-Release 2, Minecraft 1.9 Pre-Release 3, Minecraft 1.9 Pre-Release 4, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 1, Minecraft 1.9.1 Pre-Release 2, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.9.1, Minecraft 1.9.2, Minecraft 16w14a, Minecraft 16w15a, Minecraft 16w15b, Minecraft 1.9.3 Pre-Release 1, Minecraft 1.9.3 Pre-Release 2, Minecraft 1.9.3 Pre-Release 3, Minecraft 1.9.3, Minecraft 1.9.4
    • Fix Version/s: Minecraft 16w20a
    • Security Level: Minecraft - Public (Viewable by everyone)
    • Labels:
      None
    • Environment:

      Mac OS X 10.11
      MacBook Pro Late 2011 Edition

    • Confirmation Status:
      Plausible

      Description

      When using the /playsound command to replicate musical notes, it is important that the notes are tuned correctly. However this does not appear to be the case, as sometimes notes are slightly sharp or flat when they shouldn't be.

      To Reproduce:

      1. Create a test world
      2. Place a repeating command block, set to "always active", with the following command:

      /playsound block.note.harp master @p ~ ~ ~ 1 1 1
      

      A note should begin playing.

      3. Change the command to

      /playsound block.note.harp master @p ~ ~ ~ 1 1.05946309436 1
      

      A new note will begin playing. It should be exactly 1 semitone higher, however it is off by more than 20 cents. If you actually wanted to play the note 20 cents lower, you should type

      /playsound block.note.harp master @p ~ ~ ~ 1 1.04729412282 1
      

      You may need an equal-tempered tuner to properly conduct the measurements.

        Issue Links

          Activity

          Hide
          Ely Golden added a comment - - edited

          1 semitone is a musical interval. It is what you get when you play the middle C on a piano and then play a C#. If a note has a frequency f, then the note 1 semitone higher will have a frequency of f*2^(1/12). The problem I'm getting is that when I use that double value, which is very close to 2^(1/12), as my pitch parameter, I get a note that is slightly less than 1 semitone higher; rather I get a note that is about 80 cents (a cent is 1/100 of a semitone) higher than the original frequency, or if the initial frequency is f, the resultant frequency I am getting is closer to f*2^(80/1200).

          There are plenty of tuner apps for android, by the way.

          Show
          Ely Golden added a comment - - edited 1 semitone is a musical interval. It is what you get when you play the middle C on a piano and then play a C#. If a note has a frequency f, then the note 1 semitone higher will have a frequency of f*2^(1/12). The problem I'm getting is that when I use that double value, which is very close to 2^(1/12), as my pitch parameter, I get a note that is slightly less than 1 semitone higher; rather I get a note that is about 80 cents (a cent is 1/100 of a semitone) higher than the original frequency, or if the initial frequency is f, the resultant frequency I am getting is closer to f*2^(80/1200). There are plenty of tuner apps for android, by the way.
          Hide
          [Mojang] Grum (Erik Broes) added a comment -

          So actually found what is going on.

          When we send the pitch over the wire we multiply it by a constant and then when it gets off the wire, we divide again. This all so it fits in a single byte but in process this destroys accuracy on a linear scale.

          The broken version:
          float PITCH_ACCURACY = Byte.MAX_VALUE / 2f;

          The 'working version':
          float PITCH_ACCURACY = Byte.MAX_VALUE / 2;

          For 1.10 I'll remove this completely and just send the raw float we have over the wire, that is far more accurate especially since pitch is not a linear scale.

          Show
          [Mojang] Grum (Erik Broes) added a comment - So actually found what is going on. When we send the pitch over the wire we multiply it by a constant and then when it gets off the wire, we divide again. This all so it fits in a single byte but in process this destroys accuracy on a linear scale. The broken version: float PITCH_ACCURACY = Byte.MAX_VALUE / 2f; The 'working version': float PITCH_ACCURACY = Byte.MAX_VALUE / 2; For 1.10 I'll remove this completely and just send the raw float we have over the wire, that is far more accurate especially since pitch is not a linear scale.
          Hide
          Ely Golden added a comment -

          Thanks! I'll be sure to test this when 1.9.3 comes out and report back.

          Show
          Ely Golden added a comment - Thanks! I'll be sure to test this when 1.9.3 comes out and report back.
          Hide
          Ely Golden added a comment -

          So I tested it in 1.9.3 and it's definitely better than it was before. Some of the notes were still off when testing with noteblocks. When testing with a command block I found that

          /playsound block.note.harp master @p ~ ~ ~ 1 1.05946309436 1

          was still giving me a note that was about 20 cents flat. I suspect that keeping full float precision will fix this, so I'd mark it as fixed for 1.10. When it comes I'll be sure to do more testing.

          Show
          Ely Golden added a comment - So I tested it in 1.9.3 and it's definitely better than it was before. Some of the notes were still off when testing with noteblocks. When testing with a command block I found that /playsound block.note.harp master @p ~ ~ ~ 1 1.05946309436 1 was still giving me a note that was about 20 cents flat. I suspect that keeping full float precision will fix this, so I'd mark it as fixed for 1.10. When it comes I'll be sure to do more testing.
          Hide
          Ely Golden added a comment -

          yes! Tested in 1.10 and it's finally fixed! I'm curious; now that pitch is sent as floating point, are we still limited to just 1 octave? Or will that limit be lifted?

          Show
          Ely Golden added a comment - yes! Tested in 1.10 and it's finally fixed! I'm curious; now that pitch is sent as floating point, are we still limited to just 1 octave? Or will that limit be lifted?

            People

            • Assignee:
              [Mojang] Grum (Erik Broes)
              Reporter:
              Ely Golden
            • Votes:
              8 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: