SoundMonitor.java
     1: //========================================================================================
     2: //  SoundMonitor.java
     3: //    en:Sound monitor
     4: //    ja:音声モニタ
     5: //  Copyright (C) 2003-2024 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: package xeij;
    14: 
    15: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,FlowLayout,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
    16: import java.awt.event.*;  //ActionEvent,ActionListener,ComponentAdapter,ComponentEvent,ComponentListener,FocusAdapter,FocusEvent,FocusListener,InputEvent,KeyAdapter,KeyEvent,KeyListener,MouseAdapter,MouseEvent,MouseListener,MouseMotionAdapter,MouseWheelEvent,WindowAdapter,WindowEvent,WindowListener,WindowStateListener
    17: import java.awt.image.*;  //BufferedImage,DataBuffer,DataBufferByte,DataBufferInt,IndexColorModel
    18: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
    19: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,Timer,TimerTask,TreeMap
    20: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JApplet,JButton,JCheckBox,JCheckBoxMenuItem,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
    21: 
    22: public class SoundMonitor {
    23: 
    24:   //パネル
    25:   public static final int SMN_WIDTH = 4 + 8 + 4 * (14 * 8 + 6) + 4;  //鍵盤の幅に合わせる。4の倍数に限る。488
    26:   public static final int SMN_OFFSET = SMN_WIDTH + 3 >> 2;
    27: 
    28:   //色
    29:   public static final byte SMN_BLACK  = (byte) 0b00000000;  //  0  0xff000000  黒  背景
    30:   public static final byte SMN_BLUE   = (byte) 0b01010101;  //  1  0xff2020ff  青  文字,黒鍵
    31:   public static final byte SMN_ORANGE = (byte) 0b10101010;  //  2  0xffff8740  橙  ハイライト
    32:   public static final byte SMN_WHITE  = (byte) 0b11111111;  //  3  0xffffffff  白  文字,白鍵
    33: 
    34:   //フォント
    35:   public static final byte[] SMN_FONT_1 = new byte[5 * 127];
    36:   public static final byte[] SMN_FONT_2 = new byte[5 * 127];
    37:   public static final byte[] SMN_FONT_3 = new byte[5 * 127];
    38: 
    39:   //アイコン
    40: /*
    41:   public static final int[] SMN_ICON_1 = {
    42:     0b01010101,0b01010100,  //0:[1]
    43:     0b01000000,0b00000100,
    44:     0b01000001,0b00000100,
    45:     0b01000001,0b00000100,
    46:     0b01000001,0b00000100,
    47:     0b01000001,0b00000100,
    48:     0b01000001,0b00000100,
    49:     0b01000000,0b00000100,
    50:     0b01010101,0b01010100,
    51:     0b01010101,0b01010100,  //1:[2]
    52:     0b01000000,0b00000100,
    53:     0b01000101,0b01000100,
    54:     0b01000000,0b01000100,
    55:     0b01000101,0b01000100,
    56:     0b01000100,0b00000100,
    57:     0b01000101,0b01000100,
    58:     0b01000000,0b00000100,
    59:     0b01010101,0b01010100,
    60:     0b01010101,0b01010100,  //2:[3]
    61:     0b01000000,0b00000100,
    62:     0b01000101,0b01000100,
    63:     0b01000000,0b01000100,
    64:     0b01000101,0b01000100,
    65:     0b01000000,0b01000100,
    66:     0b01000101,0b01000100,
    67:     0b01000000,0b00000100,
    68:     0b01010101,0b01010100,
    69:     0b01010101,0b01010100,  //3:[4]
    70:     0b01000000,0b00000100,
    71:     0b01000100,0b01000100,
    72:     0b01000100,0b01000100,
    73:     0b01000101,0b01000100,
    74:     0b01000000,0b01000100,
    75:     0b01000000,0b01000100,
    76:     0b01000000,0b00000100,
    77:     0b01010101,0b01010100,
    78:     0b01010101,0b01010100,  //4:[5]
    79:     0b01000000,0b00000100,
    80:     0b01000101,0b01000100,
    81:     0b01000100,0b00000100,
    82:     0b01000101,0b01000100,
    83:     0b01000000,0b01000100,
    84:     0b01000101,0b01000100,
    85:     0b01000000,0b00000100,
    86:     0b01010101,0b01010100,
    87:     0b01010101,0b01010100,  //5:[6]
    88:     0b01000000,0b00000100,
    89:     0b01000101,0b01000100,
    90:     0b01000100,0b00000100,
    91:     0b01000101,0b01000100,
    92:     0b01000100,0b01000100,
    93:     0b01000101,0b01000100,
    94:     0b01000000,0b00000100,
    95:     0b01010101,0b01010100,
    96:     0b01010101,0b01010100,  //6:[7]
    97:     0b01000000,0b00000100,
    98:     0b01000101,0b01000100,
    99:     0b01000000,0b01000100,
   100:     0b01000000,0b01000100,
   101:     0b01000000,0b01000100,
   102:     0b01000000,0b01000100,
   103:     0b01000000,0b00000100,
   104:     0b01010101,0b01010100,
   105:     0b01010101,0b01010100,  //7:[8]
   106:     0b01000000,0b00000100,
   107:     0b01000101,0b01000100,
   108:     0b01000100,0b01000100,
   109:     0b01000101,0b01000100,
   110:     0b01000100,0b01000100,
   111:     0b01000101,0b01000100,
   112:     0b01000000,0b00000100,
   113:     0b01010101,0b01010100,
   114:     0b01010101,0b01010100,  //8:[W]
   115:     0b01000000,0b00000100,
   116:     0b01000100,0b01000100,
   117:     0b01000100,0b01000100,
   118:     0b01000101,0b01000100,
   119:     0b01000101,0b01000100,
   120:     0b01000100,0b01000100,
   121:     0b01000000,0b00000100,
   122:     0b01010101,0b01010100,
   123:     0b01010101,0b01010100,  //9:[S]
   124:     0b01000000,0b00000100,
   125:     0b01000001,0b01000100,
   126:     0b01000100,0b00000100,
   127:     0b01000001,0b00000100,
   128:     0b01000000,0b01000100,
   129:     0b01000101,0b00000100,
   130:     0b01000000,0b00000100,
   131:     0b01010101,0b01010100,
   132:     0b01010101,0b01010100,  //10:[P]
   133:     0b01000000,0b00000100,
   134:     0b01000101,0b00000100,
   135:     0b01000100,0b01000100,
   136:     0b01000101,0b00000100,
   137:     0b01000100,0b00000100,
   138:     0b01000100,0b00000100,
   139:     0b01000000,0b00000100,
   140:     0b01010101,0b01010100,
   141:   };
   142: */
   143:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_ICON_1
   144:   public static final byte[] SMN_ICON_1 = "UT@\4A\4A\4A\4A\4A\4@\4UTUT@\4ED@DEDD\4ED@\4UTUT@\4ED@DED@DED@\4UTUT@\4DDDDED@D@D@\4UTUT@\4EDD\4ED@DED@\4UTUT@\4EDD\4EDDDED@\4UTUT@\4ED@D@D@D@D@\4UTUT@\4EDDDEDDDED@\4UTUT@\4DDDDEDEDDD@\4UTUT@\4ADD\4A\4@DE\4@\4UTUT@\4E\4DDE\4D\4D\4@\4UT".getBytes (XEiJ.ISO_8859_1);
   145: /*
   146:   public static final int[] SMN_ICON_3 = {
   147:     0b11111111,0b11111100,  //0:[1]
   148:     0b11000000,0b00001100,
   149:     0b11000011,0b00001100,
   150:     0b11000011,0b00001100,
   151:     0b11000011,0b00001100,
   152:     0b11000011,0b00001100,
   153:     0b11000011,0b00001100,
   154:     0b11000000,0b00001100,
   155:     0b11111111,0b11111100,
   156:     0b11111111,0b11111100,  //1:[2]
   157:     0b11000000,0b00001100,
   158:     0b11001111,0b11001100,
   159:     0b11000000,0b11001100,
   160:     0b11001111,0b11001100,
   161:     0b11001100,0b00001100,
   162:     0b11001111,0b11001100,
   163:     0b11000000,0b00001100,
   164:     0b11111111,0b11111100,
   165:     0b11111111,0b11111100,  //2:[3]
   166:     0b11000000,0b00001100,
   167:     0b11001111,0b11001100,
   168:     0b11000000,0b11001100,
   169:     0b11001111,0b11001100,
   170:     0b11000000,0b11001100,
   171:     0b11001111,0b11001100,
   172:     0b11000000,0b00001100,
   173:     0b11111111,0b11111100,
   174:     0b11111111,0b11111100,  //3:[4]
   175:     0b11000000,0b00001100,
   176:     0b11001100,0b11001100,
   177:     0b11001100,0b11001100,
   178:     0b11001111,0b11001100,
   179:     0b11000000,0b11001100,
   180:     0b11000000,0b11001100,
   181:     0b11000000,0b00001100,
   182:     0b11111111,0b11111100,
   183:     0b11111111,0b11111100,  //4:[5]
   184:     0b11000000,0b00001100,
   185:     0b11001111,0b11001100,
   186:     0b11001100,0b00001100,
   187:     0b11001111,0b11001100,
   188:     0b11000000,0b11001100,
   189:     0b11001111,0b11001100,
   190:     0b11000000,0b00001100,
   191:     0b11111111,0b11111100,
   192:     0b11111111,0b11111100,  //5:[6]
   193:     0b11000000,0b00001100,
   194:     0b11001111,0b11001100,
   195:     0b11001100,0b00001100,
   196:     0b11001111,0b11001100,
   197:     0b11001100,0b11001100,
   198:     0b11001111,0b11001100,
   199:     0b11000000,0b00001100,
   200:     0b11111111,0b11111100,
   201:     0b11111111,0b11111100,  //6:[7]
   202:     0b11000000,0b00001100,
   203:     0b11001111,0b11001100,
   204:     0b11000000,0b11001100,
   205:     0b11000000,0b11001100,
   206:     0b11000000,0b11001100,
   207:     0b11000000,0b11001100,
   208:     0b11000000,0b00001100,
   209:     0b11111111,0b11111100,
   210:     0b11111111,0b11111100,  //7:[8]
   211:     0b11000000,0b00001100,
   212:     0b11001111,0b11001100,
   213:     0b11001100,0b11001100,
   214:     0b11001111,0b11001100,
   215:     0b11001100,0b11001100,
   216:     0b11001111,0b11001100,
   217:     0b11000000,0b00001100,
   218:     0b11111111,0b11111100,
   219:     0b11111111,0b11111100,  //8:[W]
   220:     0b11000000,0b00001100,
   221:     0b11001100,0b11001100,
   222:     0b11001100,0b11001100,
   223:     0b11001111,0b11001100,
   224:     0b11001111,0b11001100,
   225:     0b11001100,0b11001100,
   226:     0b11000000,0b00001100,
   227:     0b11111111,0b11111100,
   228:     0b11111111,0b11111100,  //9:[S]
   229:     0b11000000,0b00001100,
   230:     0b11000011,0b11001100,
   231:     0b11001100,0b00001100,
   232:     0b11000011,0b00001100,
   233:     0b11000000,0b11001100,
   234:     0b11001111,0b00001100,
   235:     0b11000000,0b00001100,
   236:     0b11111111,0b11111100,
   237:     0b11111111,0b11111100,  //10:[P]
   238:     0b11000000,0b00001100,
   239:     0b11001111,0b00001100,
   240:     0b11001100,0b11001100,
   241:     0b11001111,0b00001100,
   242:     0b11001100,0b00001100,
   243:     0b11001100,0b00001100,
   244:     0b11000000,0b00001100,
   245:     0b11111111,0b11111100,
   246:   };
   247: */
   248:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_ICON_3
   249:   public static final byte[] SMN_ICON_3 = "\377\374\300\f\303\f\303\f\303\f\303\f\303\f\300\f\377\374\377\374\300\f\317\314\300\314\317\314\314\f\317\314\300\f\377\374\377\374\300\f\317\314\300\314\317\314\300\314\317\314\300\f\377\374\377\374\300\f\314\314\314\314\317\314\300\314\300\314\300\f\377\374\377\374\300\f\317\314\314\f\317\314\300\314\317\314\300\f\377\374\377\374\300\f\317\314\314\f\317\314\314\314\317\314\300\f\377\374\377\374\300\f\317\314\300\314\300\314\300\314\300\314\300\f\377\374\377\374\300\f\317\314\314\314\317\314\314\314\317\314\300\f\377\374\377\374\300\f\314\314\314\314\317\314\317\314\314\314\300\f\377\374\377\374\300\f\303\314\314\f\303\f\300\314\317\f\300\f\377\374\377\374\300\f\317\f\314\314\317\f\314\f\314\f\300\f\377\374".getBytes (XEiJ.ISO_8859_1);
   250: 
   251:   //波形
   252:   public static final int SMN_WAVE_X = 12;  //4の倍数に限る
   253:   public static final int SMN_WAVE_Y = 4;
   254:   public static final int SMN_WAVE_WIDTH = SMN_WIDTH - 4 - SMN_WAVE_X;
   255:   public static final int SMN_WAVE_VALUE_SHIFT = 11;  //振幅の縮小率
   256:   public static final int SMN_WAVE_HEIGHT = (1 << 16 - SMN_WAVE_VALUE_SHIFT) + 1;  //49
   257:   public static final int SMN_WAVE_SCALE_X_MAX = 5;
   258:   public static final int SMN_WAVE_SCALE_Y_MAX = 3;
   259:   public static final int[] smnOPMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
   260:   public static final int[] smnPCMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
   261:   public static final int[][] smnWaveIndex0 = new int[SMN_WAVE_SCALE_X_MAX + 1][];
   262:   public static final int[][] smnWaveIndex1 = new int[SMN_WAVE_SCALE_X_MAX + 1][];
   263:   public static int smnWaveScaleX;
   264:   public static int smnWaveScaleY;
   265:   public static int smnWaveOffsetMax;
   266:   public static int smnWaveOffset;
   267:   public static int smnWaveElevation;
   268:   public static boolean smnWaveDragOn;
   269:   public static int smnWavePressedX;
   270:   public static int smnWavePressedY;
   271:   public static final int[] smnWaveLastYPCMLeft = new int[2];
   272:   public static final int[] smnWaveLastYPCMRight = new int[2];
   273:   public static final int[] smnWaveLastYOPMLeft = new int[2];
   274:   public static final int[] smnWaveLastYOPMRight = new int[2];
   275: 
   276:   //スペクトラムアナライザ
   277:   //  OPM.OPM_SAMPLE_FREQ == 62500 && OPM.OPM_BLOCK_SAMPLES == 2500 && SMN_WIDTH == 480 に固定
   278:   public static final int SMN_SPECTRUM_X = 4;  //4の倍数に限る
   279:   public static final int SMN_SPECTRUM_Y = SMN_WAVE_Y + SMN_WAVE_HEIGHT + 4;
   280:   public static final int SMN_SPECTRUM_WIDTH = 480;  //SMN_WIDTH-4-SMN_SPECTRUM_X
   281:   public static final int SMN_SPECTRUM_HEIGHT = 32;
   282: /*
   283:   public static final int[] SMN_SPECTRUM_MAP = {
   284:     //       C           C#               D              D#               E                               F
   285:     0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43,
   286:     //          F#               G              G#               A              A#               B
   287:     45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 92, 93, 94, 95,
   288:   };
   289: */
   290:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_SPECTRUM_MAP
   291:   public static final byte[] SMN_SPECTRUM_MAP = "\0\1\2\3\5\7\t\13\r\17\21\23\25\27\31\33\35\37!#$%&\'()*+-/13579;=?ACEGIKMOQSUWY[\\]^_".getBytes (XEiJ.ISO_8859_1);
   292:   public static final int SMN_SPECTRUM_BIT = 10;  //FFTのサンプル数のbit数
   293:   public static final int SMN_SPECTRUM_N = 1 << SMN_SPECTRUM_BIT;  //FFTのサンプル数
   294:   public static final int SMN_SPECTRUM_PARTITIONS = 6;  //分割数
   295:   public static final int SMN_SPECTRUM_RANGE = 480 / SMN_SPECTRUM_PARTITIONS;  //分割幅。120
   296:   public static final int[] SMN_SPECTRUM_INTERVAL = new int[] { 100, 100, 50, 25, 10, 5 };  //サンプリング間隔
   297:   public static final double[][] smnSpectrumBuffer = new double[SMN_SPECTRUM_PARTITIONS][];  //バッファ。[1]は使わない
   298:   public static final double[] smnSpectrumX = new double[SMN_SPECTRUM_N];  //実数部
   299:   public static final double[] smnSpectrumY = new double[SMN_SPECTRUM_N];  //虚数部
   300:   public static final int[] smnSpectrumIndex = new int[480];  //幅<<16|インデックス
   301:   public static final int[] smnSpectrumValue = new int[480];  //前回の値
   302:   public static final double[] smnSpectrumWindow = new double[SMN_SPECTRUM_N];  //窓関数
   303:   public static final int SMN_SPECTRUM_TRAIL = 2;  //一度に減らす数の上限。小さくするとゆっくり下がる。小さくしすぎると最後に伸びた線がどれかわからなくなる
   304:   public static final double SMN_SPECTRUM_SCALE = 64.0;  //拡大率
   305:   public static FFT smnFFT;  //FFT
   306: 
   307:   //440Hzマーク
   308:   public static final int[] SMN_440HZ_PATTERN = { 18, SMN_BLUE, 0, 0, -1, 1, 1, 1, -2, 2, 2, 2, -1, 3, 1, 3, 0, 4 };
   309: 
   310:   //鍵盤
   311:   public static final int SMN_KEY_X = 12;
   312:   public static final int SMN_KEY_Y = SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT + 1;
   313:   public static final int SMN_KEY_HEIGHT = 6 + 12 * 8;
   314:   public static final byte[] SMN_KEY_COLOR = {
   315:     SMN_WHITE,  //C
   316:     SMN_BLUE,   //C#
   317:     SMN_WHITE,  //D
   318:     SMN_BLUE,   //D#
   319:     SMN_WHITE,  //E
   320:     SMN_WHITE,  //F
   321:     SMN_BLUE,   //F#
   322:     SMN_WHITE,  //G
   323:     SMN_BLUE,   //G#
   324:     SMN_WHITE,  //A
   325:     SMN_BLUE,   //A#
   326:     SMN_WHITE,  //B
   327:   };
   328:   public static final int[] smnKey = new int[8];  //キーオンされているキー。-1=なし,0=O0C
   329: 
   330:   //音色
   331:   public static final int SMN_TONE_X = 20;  //4の倍数に限る
   332:   public static final int SMN_TONE_Y = SMN_KEY_Y + SMN_KEY_HEIGHT + 4;
   333:   public static final int SMN_TONE_BOX_COLS = 3 * 12 + 2;
   334:   public static final int SMN_TONE_BOX_HEIGHT = 6 * 7 + 4;
   335:   public static final int SMN_TONE_HEIGHT = SMN_TONE_BOX_HEIGHT * 3 - 4;
   336:   public static final char[] SMN_TONE_H1 = "FC SL WA SY SP PD AD PS AS PN"   .toCharArray ();
   337:   public static final char[] SMN_TONE_V0 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
   338:   public static final char[] SMN_TONE_H2 = "AR 1R 2R RR 1L TL KS ML T1 T2 AE".toCharArray ();
   339:   public static final char[] SMN_TONE_M1 = "M1".toCharArray ();
   340:   public static final char[] SMN_TONE_V1 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
   341:   public static final char[] SMN_TONE_C1 = "C1".toCharArray ();
   342:   public static final char[] SMN_TONE_V2 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
   343:   public static final char[] SMN_TONE_M2 = "M2".toCharArray ();
   344:   public static final char[] SMN_TONE_V3 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
   345:   public static final char[] SMN_TONE_C2 = "C2".toCharArray ();
   346:   public static final char[] SMN_TONE_V4 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
   347: 
   348:   //PCM
   349:   public static final int SMN_PCM_COL = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * 2 + 6;
   350:   public static final int SMN_PCM_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2;
   351:   //            11111111112222
   352:   //  012345678901234567890123
   353:   //  II 16MHz 1/512  31.3kHz
   354:   //     ^^      ^^^^ ^^^^
   355:   //  II PLAY DATA LEFT RIGHT
   356:   //     ^^^^ ^^^^ ^^^^ ^^^^^
   357:   public static final char[][] SMN_PCM_OSCILLATOR = {  //[ADPCM.pcmOSCFreqMode<<1|ADPCM.pcmOscillator]
   358:     " 8".toCharArray (),
   359:     " 4".toCharArray (),
   360:     " 8".toCharArray (),
   361:     "16".toCharArray (),
   362:   };
   363:   public static final char[][] SMN_PCM_DIVIDER = {  //[ADPCM.pcmDivider]
   364:     "1024".toCharArray (),
   365:     "768 ".toCharArray (),
   366:     "512 ".toCharArray (),
   367:     "768 ".toCharArray (),
   368:   };
   369:   public static final char[][] SMN_PCM_FREQ = {  //[ADPCM.pcmOSCFreqMode<<3|ADPCM.pcmOscillator<<2|ADPCM.pcmDivider]
   370:     " 7.8".toCharArray (),
   371:     "10.4".toCharArray (),
   372:     "15.6".toCharArray (),
   373:     "10.4".toCharArray (),
   374:     " 3.9".toCharArray (),
   375:     " 5.2".toCharArray (),
   376:     " 7.8".toCharArray (),
   377:     " 5.2".toCharArray (),
   378:     " 7.8".toCharArray (),
   379:     "10.4".toCharArray (),
   380:     "15.6".toCharArray (),
   381:     "10.4".toCharArray (),
   382:     "15.6".toCharArray (),
   383:     "20.8".toCharArray (),
   384:     "31.3".toCharArray (),
   385:     "20.8".toCharArray (),
   386:   };
   387:   public static final char[][] SMN_PCM_PLAY = {  //[ADPCM.pcmActive?1:0]
   388:     "    ".toCharArray (),
   389:     "PLAY".toCharArray (),
   390:   };
   391:   public static final char[][] SMN_PCM_DATA = {  //[ADPCM.pcmEncodedData>=0?1:0]
   392:     "    ".toCharArray (),
   393:     "DATA".toCharArray (),
   394:   };
   395:   public static final char[][] SMN_PCM_LEFT = {  //[ADPCM.pcmPanLeft==0||ADPCM.pcmPanLeft<0x80000000+ADPCM.PCM_ATTACK_SPAN*2?0:1]
   396:     "    ".toCharArray (),
   397:     "LEFT".toCharArray (),
   398:   };
   399:   public static final char[][] SMN_PCM_RIGHT = {  //[SoundSource.SND_CHANNELS==1?ADPCM.pcmPanLeft==0||ADPCM.pcmPanLeft<0x80000000+ADPCM.PCM_ATTACK_SPAN*2?0:1:ADPCM.pcmPanRight==0||ADPCM.pcmPanRight<0x80000000+ADPCM.PCM_ATTACK_SPAN*2?0:1]
   400:     "     ".toCharArray (),
   401:     "RIGHT".toCharArray (),
   402:   };
   403: 
   404:   //パレット
   405:   public static final int SMN_PALET_X = SMN_TONE_X + 4 * SMN_TONE_BOX_COLS * 2;
   406:   public static final int SMN_PALET_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2 + 6 * 2;
   407:   public static final int SMN_PALET_WIDTH = 140;
   408:   public static final int SMN_PALET_HEIGHT = 6 * 5;
   409:   public static final int[][] SMN_SLIDER_ARRAY = {
   410:     { SMN_PALET_X + 4 *  2, SMN_PALET_Y + 6 * 1, 48, SMN_WHITE ,  0 },  //0 H  0
   411:     { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 1, 32, SMN_WHITE ,  0 },  //0 S  0
   412:     { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 1, 32, SMN_WHITE ,  0 },  //0 B  0
   413:     { SMN_PALET_X + 4 *  2, SMN_PALET_Y + 6 * 2, 48, SMN_BLUE  , 30 },  //1 H 32
   414:     { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 2, 32, SMN_BLUE  , 30 },  //1 S 28
   415:     { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 2, 32, SMN_BLUE  , 32 },  //1 B 32
   416:     { SMN_PALET_X + 4 *  2, SMN_PALET_Y + 6 * 3, 48, SMN_ORANGE,  3 },  //2 H  3
   417:     { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 3, 32, SMN_ORANGE, 30 },  //2 S 24
   418:     { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 3, 32, SMN_ORANGE, 32 },  //2 B 32
   419:     { SMN_PALET_X + 4 *  2, SMN_PALET_Y + 6 * 4, 48, SMN_WHITE , 30 },  //3 H  0
   420:     { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 4, 32, SMN_WHITE ,  3 },  //3 S  0
   421:     { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 4, 32, SMN_WHITE , 30 },  //3 B 32
   422:   };
   423:   public static final int[][] SMN_SLIDER_PATTERN = {
   424:     { 18, SMN_WHITE ,   1, -2, 2, -2,   0, -1,               3, -1,                 0, 1,             3, 1,   1, 2, 2, 2,
   425:       14, SMN_BLACK ,                          1, -1, 2, -1,          1, 0, 2, 0,         1, 1, 2, 1                     },
   426:     { 26, SMN_BLUE  ,   1, -2, 2, -2,   0, -1, 1, -1, 2, -1, 3, -1,                 0, 1, 1, 1, 2, 1, 3, 1,   1, 2, 2, 2 },
   427:     { 26, SMN_ORANGE,   1, -2, 2, -2,   0, -1, 1, -1, 2, -1, 3, -1,                 0, 1, 1, 1, 2, 1, 3, 1,   1, 2, 2, 2 },
   428:     { 26, SMN_WHITE ,   1, -2, 2, -2,   0, -1, 1, -1, 2, -1, 3, -1,                 0, 1, 1, 1, 2, 1, 3, 1,   1, 2, 2, 2 },
   429:   };
   430:   public static int smnPaletDragSlider;
   431:   public static int smnPaletPressedX;
   432:   public static IndexColorModel smnColorModel;
   433: 
   434:   //一時停止
   435:   public static final int SMN_PAUSE_WIDTH = 16;
   436:   public static final int SMN_PAUSE_HEIGHT = 16;
   437:   public static final int SMN_PAUSE_X = SMN_WIDTH - 4 - SMN_PAUSE_WIDTH;
   438:   public static final int SMN_PAUSE_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2 + 6 * 3 + (6 * 4 - SMN_PAUSE_HEIGHT >> 1);
   439: /*
   440:   public static final int[] SMN_PAUSE_ICON_3 = {
   441:     0b00000000,0b00000000,0b00000000,0b00000000,
   442:     0b00111111,0b11111111,0b11111111,0b11111100,
   443:     0b00110000,0b00000000,0b00000000,0b00001100,
   444:     0b00110000,0b00000000,0b00000000,0b00001100,
   445:     0b00110000,0b11111111,0b11111111,0b00001100,
   446:     0b00110000,0b11111111,0b11111111,0b00001100,
   447:     0b00110000,0b11111111,0b11111111,0b00001100,
   448:     0b00110000,0b11111111,0b11111111,0b00001100,
   449:     0b00110000,0b11111111,0b11111111,0b00001100,
   450:     0b00110000,0b11111111,0b11111111,0b00001100,
   451:     0b00110000,0b11111111,0b11111111,0b00001100,
   452:     0b00110000,0b11111111,0b11111111,0b00001100,
   453:     0b00110000,0b00000000,0b00000000,0b00001100,
   454:     0b00110000,0b00000000,0b00000000,0b00001100,
   455:     0b00111111,0b11111111,0b11111111,0b11111100,
   456:     0b00000000,0b00000000,0b00000000,0b00000000,
   457:   };
   458: */
   459:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_PAUSE_ICON_3
   460:   public static final byte[] SMN_PAUSE_ICON_3 = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
   461: /*
   462:   public static final int[] SMN_PLAY_ICON_3 = {
   463:     0b00000000,0b00000000,0b00000000,0b00000000,
   464:     0b00111111,0b11111111,0b11111111,0b11111100,
   465:     0b00110000,0b00000000,0b00000000,0b00001100,
   466:     0b00110000,0b00000000,0b00000000,0b00001100,
   467:     0b00110000,0b11110000,0b00000000,0b00001100,
   468:     0b00110000,0b11111111,0b00000000,0b00001100,
   469:     0b00110000,0b11111111,0b11110000,0b00001100,
   470:     0b00110000,0b11111111,0b11111111,0b00001100,
   471:     0b00110000,0b11111111,0b11111111,0b00001100,
   472:     0b00110000,0b11111111,0b11110000,0b00001100,
   473:     0b00110000,0b11111111,0b00000000,0b00001100,
   474:     0b00110000,0b11110000,0b00000000,0b00001100,
   475:     0b00110000,0b00000000,0b00000000,0b00001100,
   476:     0b00110000,0b00000000,0b00000000,0b00001100,
   477:     0b00111111,0b11111111,0b11111111,0b11111100,
   478:     0b00000000,0b00000000,0b00000000,0b00000000,
   479:   };
   480: */
   481:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_PLAY_ICON_3
   482:   public static final byte[] SMN_PLAY_ICON_3 = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\360\0\f0\377\0\f0\377\360\f0\377\377\f0\377\377\f0\377\360\f0\377\0\f0\360\0\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
   483:   public static boolean smnPauseRequest;  //次の更新でsmnPauseUpdateに設定する値
   484:   public static boolean smnPauseUpdate;  //true=更新を一時停止している
   485: 
   486:   //ズーム
   487:   public static final int SMN_ZOOM_WIDTH = 16;
   488:   public static final int SMN_ZOOM_HEIGHT = 16;
   489:   public static final int SMN_ZOOM_X = SMN_PAUSE_X;
   490:   public static final int SMN_ZOOM_Y = SMN_PAUSE_Y - 24;
   491: /*
   492:   public static final int[] SMN_ZOOM_X1_ICON = {
   493:     0b00000000,0b00000000,0b00000000,0b00000000,
   494:     0b00111111,0b11111111,0b11111111,0b11111100,
   495:     0b00110000,0b00000000,0b00000000,0b00001100,
   496:     0b00110000,0b00000000,0b00000000,0b00001100,
   497:     0b00110000,0b00000000,0b00001111,0b00001100,
   498:     0b00110000,0b00000000,0b00001111,0b00001100,
   499:     0b00110000,0b00000000,0b00001111,0b00001100,
   500:     0b00110011,0b11001111,0b00001111,0b00001100,
   501:     0b00110011,0b11001111,0b00001111,0b00001100,
   502:     0b00110000,0b11111100,0b00001111,0b00001100,
   503:     0b00110011,0b11001111,0b00001111,0b00001100,
   504:     0b00110011,0b11001111,0b00001111,0b00001100,
   505:     0b00110000,0b00000000,0b00000000,0b00001100,
   506:     0b00110000,0b00000000,0b00000000,0b00001100,
   507:     0b00111111,0b11111111,0b11111111,0b11111100,
   508:     0b00000000,0b00000000,0b00000000,0b00000000,
   509:   };
   510: */
   511:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_ZOOM_X1_ICON
   512:   public static final byte[] SMN_ZOOM_X1_ICON = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\0\17\f0\0\17\f0\0\17\f3\317\17\f3\317\17\f0\374\17\f3\317\17\f3\317\17\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
   513: /*
   514:   public static final int[] SMN_ZOOM_X2_ICON = {
   515:     0b00000000,0b00000000,0b00000000,0b00000000,
   516:     0b00111111,0b11111111,0b11111111,0b11111100,
   517:     0b00110000,0b00000000,0b00000000,0b00001100,
   518:     0b00110000,0b00000000,0b00000000,0b00001100,
   519:     0b00110000,0b00000000,0b00111111,0b00001100,
   520:     0b00110000,0b00000000,0b00000011,0b11001100,
   521:     0b00110000,0b00000000,0b00000011,0b11001100,
   522:     0b00110011,0b11001111,0b00000011,0b11001100,
   523:     0b00110011,0b11001111,0b00001111,0b00001100,
   524:     0b00110000,0b11111100,0b00111100,0b00001100,
   525:     0b00110011,0b11001111,0b00111100,0b00001100,
   526:     0b00110011,0b11001111,0b00111111,0b11001100,
   527:     0b00110000,0b00000000,0b00000000,0b00001100,
   528:     0b00110000,0b00000000,0b00000000,0b00001100,
   529:     0b00111111,0b11111111,0b11111111,0b11111100,
   530:     0b00000000,0b00000000,0b00000000,0b00000000,
   531:   };
   532: */
   533:   //  perl misc/itob.pl xeij/SoundMonitor.java SMN_ZOOM_X2_ICON
   534:   public static final byte[] SMN_ZOOM_X2_ICON = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\0?\f0\0\3\3140\0\3\3143\317\17\f3\317\17\f0\374<\f3\317<\f3\317?\3140\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
   535:   public static int smnZoomRequest;  //次の更新でsmnZoomShiftに設定する値
   536:   public static int smnZoomShift;  //0=1倍,1=2倍
   537: 
   538:   //パネル
   539:   public static final int SMN_HEIGHT = SMN_TONE_Y + SMN_TONE_HEIGHT + 4;
   540:   public static boolean smnIsVisible;
   541:   public static BufferedImage smnImage;
   542:   public static byte[] smnBitmap;
   543:   public static JPanel smnPanel;
   544:   public static JFrame smnFrame;
   545: 
   546:   //smnInit ()
   547:   //  初期化
   548:   public static void smnInit () {
   549: 
   550:     //フォント
   551:     {
   552:       final long m = 0b01010100_01010000_01000100_01000000_00010100_00010000_00000100_00000000L;
   553:       int k = 0;
   554:       for (int i = 0; i < 127; i++) {
   555:         int t = Indicator.IND_ASCII_3X5[i];
   556:         int d;
   557:         //d = t >> 14 - 6 & 0b01000000 | t >> 13 - 4 & 0b00010000 | t >> 12 - 2 & 0b00000100;
   558:         d = (int) (m >>> (t >>> 12 - 3 & 7 << 3)) & 255;
   559:         SMN_FONT_1[k] = (byte)  d;
   560:         SMN_FONT_2[k] = (byte) (d * 2);
   561:         SMN_FONT_3[k] = (byte) (d * 3);
   562:         k++;
   563:         //d = t >> 11 - 6 & 0b01000000 | t >> 10 - 4 & 0b00010000 | t >>  9 - 2 & 0b00000100;
   564:         d = (int) (m >>> (t >>>  9 - 3 & 7 << 3)) & 255;
   565:         SMN_FONT_1[k] = (byte)  d;
   566:         SMN_FONT_2[k] = (byte) (d * 2);
   567:         SMN_FONT_3[k] = (byte) (d * 3);
   568:         k++;
   569:         //d = t >>  8 - 6 & 0b01000000 | t >>  7 - 4 & 0b00010000 | t >>  6 - 2 & 0b00000100;
   570:         d = (int) (m >>> (t >>>  6 - 3 & 7 << 3)) & 255;
   571:         SMN_FONT_1[k] = (byte)  d;
   572:         SMN_FONT_2[k] = (byte) (d * 2);
   573:         SMN_FONT_3[k] = (byte) (d * 3);
   574:         k++;
   575:         //d = t <<  6 - 5 & 0b01000000 | t           & 0b00010000 | t >>  3 - 2 & 0b00000100;
   576:         d = (int) (m >>> (t            & 7 << 3)) & 255;
   577:         SMN_FONT_1[k] = (byte)  d;
   578:         SMN_FONT_2[k] = (byte) (d * 2);
   579:         SMN_FONT_3[k] = (byte) (d * 3);
   580:         k++;
   581:         //d = t <<  6 - 2 & 0b01000000 | t <<  4 - 1 & 0b00010000 | t <<  2 - 0 & 0b00000100;
   582:         d = (int) (m >>> (t <<   6 - 3 & 7 << 3)) & 255;
   583:         SMN_FONT_1[k] = (byte)  d;
   584:         SMN_FONT_2[k] = (byte) (d * 2);
   585:         SMN_FONT_3[k] = (byte) (d * 3);
   586:         k++;
   587:       }
   588:     }
   589: 
   590:     //波形
   591:     //smnOPMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
   592:     //smnPCMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
   593:     for (int scaleX = 0; scaleX <= SMN_WAVE_SCALE_X_MAX; scaleX++) {
   594:       int limit = SMN_WAVE_WIDTH << scaleX;
   595:       int[] index0 = smnWaveIndex0[scaleX] = new int[limit];
   596:       if (SoundSource.SND_CHANNELS == 1) {  //モノラル
   597:         for (int x = 0; x < limit; x++) {
   598:           index0[x] = x * OPM.OPM_BLOCK_SAMPLES / limit;
   599:         }
   600:       } else {  //ステレオ
   601:         int[] index1 = smnWaveIndex1[scaleX] = new int[limit];
   602:         for (int x = 0; x < limit; x++) {
   603:           index1[x] = (index0[x] = x * OPM.OPM_BLOCK_SAMPLES / limit << 1) + 1;
   604:         }
   605:       }
   606:     }
   607:     smnWaveScaleX = 0;
   608:     smnWaveScaleY = 0;
   609:     smnWaveOffsetMax = (SMN_WAVE_WIDTH << smnWaveScaleX) - SMN_WAVE_WIDTH;
   610:     smnWaveOffset = 0;
   611:     smnWaveElevation = 0;
   612:     smnWaveDragOn = false;
   613:     smnWavePressedX = -1;
   614:     smnWavePressedY = -1;
   615:     //smnWaveLastYPCMLeft = new int[2];
   616:     //smnWaveLastYPCMRight = new int[2];
   617:     //smnWaveLastYOPMLeft = new int[2];
   618:     //smnWaveLastYOPMRight = new int[2];
   619:     smnWaveLastYPCMLeft[0] = 0;
   620:     smnWaveLastYPCMLeft[1] = 0;
   621:     smnWaveLastYPCMRight[0] = 0;
   622:     smnWaveLastYPCMRight[1] = 0;
   623:     smnWaveLastYOPMLeft[0] = 0;
   624:     smnWaveLastYOPMLeft[1] = 0;
   625:     smnWaveLastYOPMRight[0] = 0;
   626:     smnWaveLastYOPMRight[1] = 0;
   627: 
   628:     //スペクトラムアナライザ
   629:     //smnSpectrumBuffer = new double[SMN_SPECTRUM_PARTITIONS][];  //バッファ
   630:     //smnSpectrumX = new double[SMN_SPECTRUM_N];  //実数部
   631:     //smnSpectrumY = new double[SMN_SPECTRUM_N];  //虚数部
   632:     //smnSpectrumIndex = new int[480];  //幅<<16|インデックス
   633:     //smnSpectrumValue = new int[480];  //前回の値
   634:     for (int partition = 0; partition < SMN_SPECTRUM_PARTITIONS; partition++) {
   635:       if (partition != 1) {
   636:         smnSpectrumBuffer[partition] = new double[SMN_SPECTRUM_N];
   637:       }
   638:       double coeff = (double) SMN_SPECTRUM_N * 440.0 / 62500.0 * (double) SMN_SPECTRUM_INTERVAL[partition];
   639:       for (int x = SMN_SPECTRUM_RANGE * partition, x1 = x + SMN_SPECTRUM_RANGE; x < x1; x++) {
   640:         int k = (int) Math.floor (coeff * Math.pow (
   641:           2.0,
   642:           (double) (((56 - 8 + x) / 56 - 1) * 96 + SMN_SPECTRUM_MAP[(56 - 8 + x) % 56] - (96 * 4 + 75)) / 96.0));
   643:         int n = (int) Math.floor (coeff * Math.pow (
   644:           2.0,
   645:           (double) (((56 - 8 + 1 + x) / 56 - 1) * 96 + SMN_SPECTRUM_MAP[(56 - 8 + 1 + x) % 56] - (96 * 4 + 75)) / 96.0)) - k;
   646:         smnSpectrumIndex[x] = n << 16 | k;
   647:         //smnSpectrumValue[x] = -1;
   648:       }
   649:     }  //for partition
   650:     Arrays.fill (smnSpectrumValue, -1);
   651:     //smnSpectrumWindow = new double[SMN_SPECTRUM_N];  //窓関数
   652:     for (int i = 0; i < SMN_SPECTRUM_N; i++) {
   653:       smnSpectrumWindow[i] = 0.5 * (1.0 - Math.cos (2.0 * Math.PI / (double) SMN_SPECTRUM_N * (double) i));  //Hanning窓
   654:     }
   655:     smnFFT = new FFT (SMN_SPECTRUM_N);
   656: 
   657:     //一時停止
   658:     //  初回の更新で一時停止の解除を行うことで一時停止アイコンを描かせる
   659:     smnPauseRequest = false;
   660:     smnPauseUpdate = true;
   661: 
   662:     //ズーム
   663:     smnZoomRequest = 0;
   664:     smnZoomShift = 1;
   665: 
   666:     //スライダ
   667:     smnPaletDragSlider = -1;
   668:     smnPaletPressedX = 0;
   669: 
   670:   }  //smnInit()
   671: 
   672:   //smnStart ()
   673:   public static void smnStart () {
   674:     if (RestorableFrame.rfmGetOpened (Settings.SGS_SMN_FRAME_KEY)) {
   675:       smnOpen ();
   676:     }
   677:   }  //smnStart()
   678: 
   679:   //smnOpen ()
   680:   //  音声モニタを開く
   681:   public static void smnOpen () {
   682:     if (smnFrame == null) {
   683:       smnMakeFrame ();
   684:     }
   685:     smnIsVisible = true;
   686:     smnUpdate ();
   687:     XEiJ.pnlExitFullScreen (false);
   688:     smnFrame.setVisible (true);
   689:   }  //smnOpen()
   690: 
   691:   //smnMakeFrame ()
   692:   //  ウインドウを作る
   693:   //  ここでは開かない
   694:   public static void smnMakeFrame () {
   695: 
   696:     //イメージ
   697:     smnMakeImage ();
   698: 
   699:     //パネル
   700:     smnPanel = ComponentFactory.setFixedSize (new JPanel () {
   701:       @Override public void paint (Graphics g) {
   702:         if (smnZoomShift == 0) {
   703:           g.drawImage (smnImage, 0, 0, null);
   704:         } else {
   705:           g.drawImage (smnImage,
   706:                        0, 0, SMN_WIDTH << smnZoomShift, SMN_HEIGHT << smnZoomShift,
   707:                        0, 0, SMN_WIDTH, SMN_HEIGHT,
   708:                        null);
   709:         }
   710:       }
   711:       @Override protected void paintComponent (Graphics g) {
   712:       }
   713:       @Override protected void paintBorder (Graphics g) {
   714:       }
   715:       @Override protected void paintChildren (Graphics g) {
   716:       }
   717:       @Override public void update (Graphics g) {
   718:       }
   719:     }, SMN_WIDTH, SMN_HEIGHT);
   720:     smnPanel.setOpaque (true);
   721: 
   722:     //マウスリスナー
   723:     ComponentFactory.addListener (
   724:       smnPanel,
   725:       new MouseAdapter () {
   726:         @Override public void mouseClicked (MouseEvent me) {
   727:           int x = me.getX () >> smnZoomShift;
   728:           int y = me.getY () >> smnZoomShift;
   729:           int button = me.getButton ();
   730:           int modifiersEx = me.getModifiersEx ();
   731:           if (SMN_WAVE_X <= x && x < SMN_WAVE_X + SMN_WAVE_WIDTH &&
   732:               SMN_WAVE_Y <= y && y < SMN_WAVE_Y + SMN_WAVE_HEIGHT) {  //波形
   733:             if ((modifiersEx & InputEvent.SHIFT_DOWN_MASK) == 0) {  //Shiftが押されていない
   734:               int d = 0;
   735:               if (button == MouseEvent.BUTTON1) {  //左ボタンが押された
   736:                 if (smnWaveScaleX < SMN_WAVE_SCALE_X_MAX) {  //増やせる
   737:                   d = 1;
   738:                 }
   739:               } else if (button == MouseEvent.BUTTON3) {  //右ボタンが押された
   740:                 if (0 < smnWaveScaleX) {  //減らせる
   741:                   d = -1;
   742:                 }
   743:               }
   744:               if (d != 0) {
   745:                 smnWaveScaleX += d;
   746:                 smnWaveOffsetMax = (SMN_WAVE_WIDTH << smnWaveScaleX) - SMN_WAVE_WIDTH;
   747:                 int o = x - SMN_WAVE_X;  //SMN_WAVE_WIDTH/2。拡大縮小の中心
   748:                 smnWaveOffset = Math.max (0, Math.min (smnWaveOffsetMax, (d >= 0 ? smnWaveOffset + o << d : smnWaveOffset + o >> -d) - o));
   749:                 if (smnPauseUpdate) {  //一時停止中
   750:                   smnWavePaint ();
   751:                   smnPanel.repaint ();
   752:                 }
   753:               }
   754:             } else {  //Shiftが押されている
   755:               int d = 0;
   756:               if (button == MouseEvent.BUTTON1) {  //左ボタンが押された
   757:                 if (smnWaveScaleY < SMN_WAVE_SCALE_Y_MAX) {  //増やせる
   758:                   d = 1;
   759:                 }
   760:               } else if (button == MouseEvent.BUTTON3) {  //右ボタンが押された
   761:                 if (0 < smnWaveScaleY) {  //減らせる
   762:                   d = -1;
   763:                 }
   764:               }
   765:               if (d != 0) {
   766:                 //  smnWaveElevationはグラフが下にずれて上の方が見えているときマイナス、上にずれて下の方が見えているいるときプラス
   767:                 //  グラフの高さSMN_WAVE_HEIGHT*2^smnWaveScaleY
   768:                 //  グラフの上端から画面の中央までSMN_WAVE_HEIGHT*2^smnWaveScaleY/2+smnWaveElevation
   769:                 //  画面の中央からクリックした位置までo=y-(SMN_WAVE_Y+SMN_WAVE_HEIGHT/2)
   770:                 //  グラフの上端からクリックした位置までSMN_WAVE_HEIGHT*2^smnWaveScaleY/2+smnWaveElevation+o
   771:                 //  スケールを変更する
   772:                 //  グラフの上端からクリックした位置まで(SMN_WAVE_HEIGHT*2^smnWaveScaleY/2+smnWaveElevation+o)*2^d
   773:                 //  グラフの上端から画面の中央まで(SMN_WAVE_HEIGHT*2^smnWaveScaleY/2+smnWaveElevation+o)*2^d-o
   774:                 //  新しいelevation=(SMN_WAVE_HEIGHT*2^smnWaveScaleY/2+smnWaveElevation+o)*2^d-o-SMN_WAVE_HEIGHT*2^smnWaveScaleY*2^d/2
   775:                 //                 =(smnWaveElevation+o)*2^d-o
   776:                 smnWaveScaleY += d;
   777:                 int spaceY = (SMN_WAVE_HEIGHT >> 1 << smnWaveScaleY) - (SMN_WAVE_HEIGHT >> 1);
   778:                 int o = y - (SMN_WAVE_Y + SMN_WAVE_HEIGHT / 2);
   779:                 smnWaveElevation = Math.max (-spaceY, Math.min (spaceY, (d >= 0 ? smnWaveElevation + o << d : smnWaveElevation + o >> -d) - o));
   780:                 if (smnPauseUpdate) {  //一時停止中
   781:                   smnWavePaint ();
   782:                   smnPanel.repaint ();
   783:                 }
   784:               }
   785:             }
   786:           } else if (SMN_PAUSE_X <= x && x < SMN_PAUSE_X + SMN_PAUSE_WIDTH &&
   787:                      SMN_PAUSE_Y <= y && y < SMN_PAUSE_Y + SMN_PAUSE_HEIGHT) {  //一時停止
   788:             smnPauseRequest = !smnPauseRequest;
   789:           } else if (SMN_ZOOM_X <= x && x < SMN_ZOOM_X + SMN_ZOOM_WIDTH &&
   790:                      SMN_ZOOM_Y <= y && y < SMN_ZOOM_Y + SMN_ZOOM_HEIGHT) {  //一時停止
   791:             smnZoomRequest = smnZoomShift ^ 1;
   792:           }
   793:         }
   794:         @Override public void mousePressed (MouseEvent me) {
   795:           int x = me.getX () >> smnZoomShift;
   796:           int y = me.getY () >> smnZoomShift;
   797:           smnWaveDragOn = false;
   798:           smnPaletDragSlider = -1;
   799:           if (SMN_WAVE_X <= x && x < SMN_WAVE_X + SMN_WAVE_WIDTH &&
   800:               SMN_WAVE_Y <= y && y < SMN_WAVE_Y + SMN_WAVE_HEIGHT) {  //波形
   801:             smnWaveDragOn = true;
   802:             smnWavePressedX = x;
   803:             smnWavePressedY = y;
   804:           } else if (SMN_PALET_X <= x && x < SMN_PALET_X + SMN_PALET_WIDTH &&
   805:                      SMN_PALET_Y <= y && y < SMN_PALET_Y + SMN_PALET_HEIGHT) {  //パレット
   806:             for (int n = 0; n < SMN_SLIDER_ARRAY.length; n++) {
   807:               int[] slider = SMN_SLIDER_ARRAY[n];
   808:               int x0 = slider[0];
   809:               int y0 = slider[1];
   810:               int max = slider[2];
   811:               int value = slider[4];
   812:               if (x0 <= x && x < x0 + max + 4 && y0 <= y && y < y0 + 5) {  //スライダの範囲内
   813:                 smnPaletDragSlider = n;
   814:                 smnPaletPressedX = x;
   815:                 if (x < x0 + value || x0 + value + 4 <= x) {  //つまみの範囲外
   816:                   slider[4] = Math.max (0, Math.min (max, x - x0));
   817:                   smnDrawPaletSlider ();
   818:                   smnUpdateColor ();
   819:                 }
   820:                 break;
   821:               }
   822:             }
   823:           }
   824:         }
   825:         @Override public void mouseReleased (MouseEvent me) {
   826:           smnWaveDragOn = false;
   827:           smnPaletDragSlider = -1;
   828:         }
   829:       });
   830: 
   831:     //マウスモーションリスナー
   832:     ComponentFactory.addListener (
   833:       smnPanel,
   834:       new MouseMotionAdapter () {
   835:         @Override public void mouseDragged (MouseEvent me) {
   836:           int x = me.getX () >> smnZoomShift;
   837:           int y = me.getY () >> smnZoomShift;
   838:           if (smnWaveDragOn) {  //波形のドラッグ中
   839:             int offset = Math.max (0, Math.min (smnWaveOffsetMax, smnWaveOffset - (x - smnWavePressedX)));
   840:             int spaceY = (SMN_WAVE_HEIGHT >> 1 << smnWaveScaleY) - (SMN_WAVE_HEIGHT >> 1);
   841:             int elevation = Math.max (-spaceY, Math.min (spaceY, smnWaveElevation - (y - smnWavePressedY)));
   842:             smnWavePressedX = x;
   843:             smnWavePressedY = y;
   844:             if (smnWaveOffset != offset || smnWaveElevation != elevation) {
   845:               smnWaveOffset = offset;
   846:               smnWaveElevation = elevation;
   847:               if (smnPauseUpdate) {  //一時停止中
   848:                 smnWavePaint ();
   849:                 smnPanel.repaint ();
   850:               }
   851:             }
   852:           } else if (smnPaletDragSlider >= 0) {  //パレットのスライダのドラッグ中
   853:             int[] slider = SMN_SLIDER_ARRAY[smnPaletDragSlider];
   854:             int max = slider[2];
   855:             int value = slider[4];
   856:             slider[4] = Math.max (0, Math.min (max, value + x - smnPaletPressedX));
   857:             smnPaletPressedX = x;
   858:             smnDrawPaletSlider ();
   859:             smnUpdateColor ();
   860:           }
   861:         }
   862:       });
   863: 
   864:     //ウインドウ
   865:     smnFrame = Multilingual.mlnTitle (
   866:       ComponentFactory.createRestorableSubFrame (
   867:         Settings.SGS_SMN_FRAME_KEY,
   868:         "Sound Monitor",
   869:         null,
   870:         smnPanel,
   871:         false  //リサイズ不可
   872:         ),
   873:       "ja", "音声モニタ");
   874:     ComponentFactory.addListener (
   875:       smnFrame,
   876:       new WindowAdapter () {
   877:         @Override public void windowClosing (WindowEvent we) {
   878:           smnIsVisible = false;
   879:         }
   880:       });
   881: 
   882:   }  //smnMakeFrame()
   883: 
   884:   //smnMakeImage ()
   885:   //  イメージを作る
   886:   public static void smnMakeImage () {
   887: 
   888:     //ビットマップ
   889:     smnMakeColorModel ();
   890:     smnImage = new BufferedImage (SMN_WIDTH, SMN_HEIGHT, BufferedImage.TYPE_BYTE_BINARY, smnColorModel);
   891:     byte[] bb = smnBitmap = ((DataBufferByte) smnImage.getRaster ().getDataBuffer ()).getData ();
   892: 
   893:     //波形
   894:     //アイコン
   895:     //smnDrawIcon1 (SMN_WAVE_X / 4 - 2, SMN_WAVE_Y, 8);
   896: 
   897:     //スペクトラムアナライザ
   898:     //アイコン
   899:     smnDrawIcon3 (SMN_SPECTRUM_X / 4, SMN_SPECTRUM_Y, 9);
   900: 
   901:     //440Hzマーク
   902:     smnDrawPattern (SMN_KEY_X + 56 * 4 + 43, SMN_KEY_Y, SMN_440HZ_PATTERN);
   903: 
   904:     //鍵盤と音色
   905:     for (int ch = 0; ch < 8; ch++) {
   906:       //鍵盤
   907:       smnDrawIcon3 (SMN_KEY_X / 4 - 2, SMN_KEY_Y + 6 + 12 * ch, ch);  //鍵盤の左のチャンネルアイコン
   908:       smnKey[ch] = -1;
   909:       for (int o = 0, i = SMN_KEY_X / 4 + SMN_OFFSET * (SMN_KEY_Y + 6 + 12 * ch); ; o++, i += 14) {
   910:         smnDrawChar1 (SMN_KEY_X / 4 + 14 * o, SMN_KEY_Y, '0' + o);  //オクターブ
   911:         smnPaintKey (i     ,  0, SMN_KEY_COLOR[ 0]);  //C
   912:         smnPaintKey (i +  1,  1, SMN_KEY_COLOR[ 1]);  //C#
   913:         smnPaintKey (i +  2,  2, SMN_KEY_COLOR[ 2]);  //D
   914:         smnPaintKey (i +  3,  3, SMN_KEY_COLOR[ 3]);  //D#
   915:         smnPaintKey (i +  4,  4, SMN_KEY_COLOR[ 4]);  //E
   916:         if (o == 8) {
   917:           break;
   918:         }
   919:         smnPaintKey (i +  6,  5, SMN_KEY_COLOR[ 5]);  //F
   920:         smnPaintKey (i +  7,  6, SMN_KEY_COLOR[ 6]);  //F#
   921:         smnPaintKey (i +  8,  7, SMN_KEY_COLOR[ 7]);  //G
   922:         smnPaintKey (i +  9,  8, SMN_KEY_COLOR[ 8]);  //G#
   923:         smnPaintKey (i + 10,  9, SMN_KEY_COLOR[ 9]);  //A
   924:         smnPaintKey (i + 11, 10, SMN_KEY_COLOR[10]);  //A#
   925:         smnPaintKey (i + 12, 11, SMN_KEY_COLOR[11]);  //B
   926:       }
   927:       //音色
   928:       //                     1  1  1  2  2  2  3
   929:       //         0  3  6  9  2  5  8  1  4  7  0
   930:       //  0     FC SL WA SY SP PD AD PS AS PN
   931:       //  1     XX XX XX XX XX XX XX XX XX XX XX
   932:       //  2     AR 1R 2R RR 1L TL KS ML T1 T2 AE
   933:       //  3  M1 XX XX XX XX XX XX XX XX XX XX XX
   934:       //  4  C1 XX XX XX XX XX XX XX XX XX XX XX
   935:       //  5  M2 XX XX XX XX XX XX XX XX XX XX XX
   936:       //  6  C2 XX XX XX XX XX XX XX XX XX XX XX
   937:       {
   938:         int x = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * (0b01_00_10_01_00_10_01_00 >> (ch << 1) & 3);
   939:         int y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * (0b10_10_01_01_01_00_00_00 >> (ch << 1) & 3);
   940:         smnDrawIcon3 (x, y, ch);  //音色の左上のチャンネルアイコン
   941:         smnDrawString1 (3 + x,         y, SMN_TONE_H1);  //FC SL WA SY SP PD AD PS AS PN
   942:         smnDrawString1 (3 + x, 6 * 2 + y, SMN_TONE_H2);  //AR 1R 2R RR 1L TL KS ML T1 T2 AE
   943:         smnDrawString1 (    x, 6 * 3 + y, SMN_TONE_M1);  //M1
   944:         smnDrawString1 (    x, 6 * 4 + y, SMN_TONE_C1);  //C1
   945:         smnDrawString1 (    x, 6 * 5 + y, SMN_TONE_M2);  //M2
   946:         smnDrawString1 (    x, 6 * 6 + y, SMN_TONE_C2);  //C2
   947:       }
   948:     }
   949: 
   950:     //PCM
   951:     smnDrawIcon3 (SMN_PCM_COL, SMN_PCM_Y, 10);  //アイコン
   952:     smnDrawString3 (SMN_PCM_COL +  5, SMN_PCM_Y    , "MHz");
   953:     smnDrawString3 (SMN_PCM_COL +  9, SMN_PCM_Y    , "1/");
   954:     smnDrawString3 (SMN_PCM_COL + 20, SMN_PCM_Y    , "kHz");
   955: 
   956:     //パレット
   957:     //            1111111111222222222233333
   958:     //  01234567890123456789012345678901234
   959:     //          H           S         B
   960:     //  0 hhhhhhhhhhhhh sssssssss bbbbbbbbb
   961:     //  1 hhhhhhhhhhhhh sssssssss bbbbbbbbb
   962:     //  2 hhhhhhhhhhhhh sssssssss bbbbbbbbb
   963:     //  3 hhhhhhhhhhhhh sssssssss bbbbbbbbb
   964:     smnDrawChar1 (SMN_PALET_X / 4 +  8, SMN_PALET_Y, 'H');
   965:     smnDrawChar1 (SMN_PALET_X / 4 + 20, SMN_PALET_Y, 'S');
   966:     smnDrawChar1 (SMN_PALET_X / 4 + 30, SMN_PALET_Y, 'B');
   967:     for (int p = 0; p < 4; p++) {
   968:       smnDrawChar1 (SMN_PALET_X / 4, SMN_PALET_Y + 6 + 6 * p, '0' + p);
   969:     }
   970:     smnDrawPaletSlider ();
   971: 
   972:   }  //smnMakeImage()
   973: 
   974:   //smnDrawPaletSlider ()
   975:   //  パレットのスライダを描く
   976:   public static void smnDrawPaletSlider () {
   977:     for (int p = 0; p < 4; p++) {
   978:       int[] pattern = SMN_SLIDER_PATTERN[p];
   979:       smnDrawSlider (SMN_SLIDER_ARRAY[3 * p    ], pattern);
   980:       smnDrawSlider (SMN_SLIDER_ARRAY[3 * p + 1], pattern);
   981:       smnDrawSlider (SMN_SLIDER_ARRAY[3 * p + 2], pattern);
   982:     }
   983:   }  //smnDrawPaletSlider()
   984: 
   985:   //smnMakeColorModel ()
   986:   //  SMN_SLIDER_ARRAYのvalueからsmnColorModelを作る
   987:   public static void smnMakeColorModel () {
   988:     byte[] r = new byte[4];
   989:     byte[] g = new byte[4];
   990:     byte[] b = new byte[4];
   991:     for (int p = 0; p < 4; p++) {
   992:       int rgb = Color.HSBtoRGB ((float) SMN_SLIDER_ARRAY[3 * p    ][4] / 48F,
   993:                                 (float) SMN_SLIDER_ARRAY[3 * p + 1][4] / 32F,
   994:                                 (float) SMN_SLIDER_ARRAY[3 * p + 2][4] / 32F);
   995:       if (false) {
   996:         System.out.printf ("%d 0x%08x %2d %2d %2d\n", p, rgb,
   997:                            SMN_SLIDER_ARRAY[3 * p    ][4],
   998:                            SMN_SLIDER_ARRAY[3 * p + 1][4],
   999:                            SMN_SLIDER_ARRAY[3 * p + 2][4]);
  1000:       }
  1001:       r[p] = (byte) (rgb >> 16);
  1002:       g[p] = (byte) (rgb >>  8);
  1003:       b[p] = (byte)  rgb;
  1004:     }
  1005:     smnColorModel = new IndexColorModel (2, 4, r, g, b);
  1006:   }  //smnMakeColorModel()
  1007: 
  1008:   //smnUpdateColor ()
  1009:   public static void smnUpdateColor () {
  1010:     smnMakeColorModel ();
  1011:     smnImage = new BufferedImage (smnColorModel, smnImage.getRaster(), false, null);
  1012:     //smnBitmap = ((DataBufferByte) smnImage.getRaster ().getDataBuffer ()).getData ();
  1013:     smnPanel.repaint ();
  1014:   }  //smnUpdateColor()
  1015: 
  1016:   //smnUpdate ()
  1017:   //  音声モニタを更新する
  1018:   public static void smnUpdate () {
  1019:     byte[] bb = smnBitmap;
  1020: 
  1021:     //ズームの処理
  1022:     if (smnZoomShift != smnZoomRequest) {  //ズームの要求がある
  1023:       smnZoomShift = smnZoomRequest;
  1024:       byte[] icon = smnZoomShift == 0 ? SMN_ZOOM_X2_ICON : SMN_ZOOM_X1_ICON;
  1025:       int i = SMN_ZOOM_X / 4 + SMN_OFFSET * SMN_ZOOM_Y;
  1026:       int j = 0;
  1027:       for (int v = 0; v < SMN_ZOOM_HEIGHT; v++) {
  1028:         for (int u = 0; u < SMN_ZOOM_WIDTH; u += 4) {
  1029:           bb[i++] = icon[j++];
  1030:         }
  1031:         i += SMN_OFFSET - SMN_ZOOM_WIDTH / 4;
  1032:       }
  1033:       int panelWidth = SMN_WIDTH << smnZoomShift;
  1034:       int panelHeight = SMN_HEIGHT << smnZoomShift;
  1035:       int marginWidth = smnFrame.getWidth () - smnPanel.getWidth ();
  1036:       int marginHeight = smnFrame.getHeight () - smnPanel.getHeight ();
  1037:       ComponentFactory.setFixedSize (smnFrame, panelWidth + marginWidth, panelHeight + marginHeight);
  1038:       smnFrame.setResizable (false);
  1039:       ComponentFactory.setFixedSize (smnPanel, panelWidth, panelHeight);
  1040:       smnFrame.pack ();
  1041:     }
  1042: 
  1043:     //一時停止の処理
  1044:     if (smnPauseUpdate) {  //更新を一時停止している
  1045:       if (smnPauseRequest) {  //一時停止の解除の要求はない
  1046:         return;  //何もしない
  1047:       }
  1048:       smnPauseUpdate = false;  //一時停止を解除する
  1049:       int i = SMN_PAUSE_X / 4 + SMN_OFFSET * SMN_PAUSE_Y;
  1050:       int j = 0;
  1051:       for (int v = 0; v < SMN_PAUSE_HEIGHT; v++) {
  1052:         for (int u = 0; u < SMN_PAUSE_WIDTH; u += 4) {
  1053:           bb[i++] = SMN_PAUSE_ICON_3[j++];
  1054:         }
  1055:         i += SMN_OFFSET - SMN_PAUSE_WIDTH / 4;
  1056:       }
  1057:     } else if (smnPauseRequest) {  //一時停止していないが一時停止の要求がある
  1058:       smnPauseUpdate = true;  //一時停止する
  1059:       int i = SMN_PAUSE_X / 4 + SMN_OFFSET * SMN_PAUSE_Y;
  1060:       int j = 0;
  1061:       for (int v = 0; v < SMN_PAUSE_HEIGHT; v++) {
  1062:         for (int u = 0; u < SMN_PAUSE_WIDTH; u += 4) {
  1063:           bb[i++] = SMN_PLAY_ICON_3[j++];
  1064:         }
  1065:         i += SMN_OFFSET - SMN_PAUSE_WIDTH / 4;
  1066:       }
  1067:       smnPanel.repaint ();
  1068:       return;
  1069:     }
  1070: 
  1071:     //波形
  1072:     System.arraycopy (OPM.opmBuffer, 0, smnOPMBuffer, 0, SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES);
  1073:     System.arraycopy (ADPCM.pcmBuffer, 0, smnPCMBuffer, 0, SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES);
  1074:     smnWavePaint ();
  1075: 
  1076:     //スペクトラムアナライザ
  1077:     //
  1078:     //  x座標と周波数の関係
  1079:     //    |          1111111111222222222233333333334444444444555555|5
  1080:     //    |01234567890123456789012345678901234567890123456789012345|6
  1081:     //    |       1111122222333333344444445555566666777778888899999|9
  1082:     //    |01235791357913579135678901235791357913579135791357912345|6
  1083:     //    |   *   *   *   *   *       *   *   *   *   *   *   *    |
  1084:     //    |WWW BBBBBBB BBBBBBB WWW WWW BBBBBBB BBBBBBB BBBBBBB WWW |
  1085:     //    |WWW BBBBBBB BBBBBBB WWW WWW BBBBBBB BBBBBBB BBBBBBB WWW |
  1086:     //    |WWW BBBBBBB BBBBBBB WWW WWW BBBBBBB BBBBBBB BBBBBBB WWW |
  1087:     //    |WWW BBBBBBB BBBBBBB WWW WWW BBBBBBB BBBBBBB BBBBBBB WWW |
  1088:     //    |WWW BBBBBBB BBBBBBB WWW WWW BBBBBBB BBBBBBB BBBBBBB WWW |
  1089:     //    |WWW                 WWW WWW                         WWW |
  1090:     //    |WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW |
  1091:     //    |WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW |
  1092:     //    |WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW |
  1093:     //    |WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW |
  1094:     //    |WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW |
  1095:     //    鍵盤とスペクトラムアナライザの位置を合わせるため、x座標-8を56で割った商を96倍、余りをSMN_SPECTRUM_MAPで0~95に変換する
  1096:     //    O4Aのx=8+56*4+43=275の変換結果の96*4+75=459を440Hzに合わせる
  1097:     //    perl -e "@m=(0,1,2,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,36,37,38,39,40,41,42,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,92,93,94,95);for$x(0..479){$x%10 or print'    //    ';printf'|%4d%8.2f',$x,440*2**(((int(($x-8+56)/56)-1)*96+$m[($x-8+56)%56]-(96*4+75))/96);$x%10==9 and printf'|%c',10;}"
  1098:     //    |   0   14.78|   1   14.99|   2   15.21|   3   15.43|   4   15.55|   5   15.66|   6   15.77|   7   15.89|   8   16.00|   9   16.12|
  1099:     //    |  10   16.23|  11   16.35|  12   16.59|  13   16.83|  14   17.08|  15   17.32|  16   17.58|  17   17.83|  18   18.09|  19   18.35|
  1100:     //    |  20   18.62|  21   18.89|  22   19.17|  23   19.45|  24   19.73|  25   20.02|  26   20.31|  27   20.60|  28   20.75|  29   20.90|
  1101:     //    |  30   21.05|  31   21.21|  32   21.36|  33   21.51|  34   21.67|  35   21.83|  36   22.14|  37   22.47|  38   22.79|  39   23.12|
  1102:     //    |  40   23.46|  41   23.80|  42   24.15|  43   24.50|  44   24.86|  45   25.22|  46   25.58|  47   25.96|  48   26.33|  49   26.72|
  1103:     //    |  50   27.11|  51   27.50|  52   27.90|  53   28.31|  54   28.72|  55   29.14|  56   29.56|  57   29.99|  58   30.43|  59   30.87|
  1104:     //    |  60   31.09|  61   31.32|  62   31.54|  63   31.77|  64   32.00|  65   32.23|  66   32.47|  67   32.70|  68   33.18|  69   33.66|
  1105:     //    |  70   34.15|  71   34.65|  72   35.15|  73   35.66|  74   36.18|  75   36.71|  76   37.24|  77   37.78|  78   38.33|  79   38.89|
  1106:     //    |  80   39.46|  81   40.03|  82   40.61|  83   41.20|  84   41.50|  85   41.80|  86   42.11|  87   42.41|  88   42.72|  89   43.03|
  1107:     //    |  90   43.34|  91   43.65|  92   44.29|  93   44.93|  94   45.59|  95   46.25|  96   46.92|  97   47.60|  98   48.30|  99   49.00|
  1108:     //    | 100   49.71| 101   50.44| 102   51.17| 103   51.91| 104   52.67| 105   53.43| 106   54.21| 107   55.00| 108   55.80| 109   56.61|
  1109:     //    | 110   57.44| 111   58.27| 112   59.12| 113   59.98| 114   60.85| 115   61.74| 116   62.18| 117   62.63| 118   63.09| 119   63.54|
  1110:     //    | 120   64.00| 121   64.47| 122   64.94| 123   65.41| 124   66.36| 125   67.32| 126   68.30| 127   69.30| 128   70.30| 129   71.33|
  1111:     //    | 130   72.36| 131   73.42| 132   74.48| 133   75.57| 134   76.67| 135   77.78| 136   78.91| 137   80.06| 138   81.23| 139   82.41|
  1112:     //    | 140   83.00| 141   83.61| 142   84.21| 143   84.82| 144   85.44| 145   86.06| 146   86.68| 147   87.31| 148   88.58| 149   89.87|
  1113:     //    | 150   91.17| 151   92.50| 152   93.84| 153   95.21| 154   96.59| 155   98.00| 156   99.42| 157  100.87| 158  102.34| 159  103.83|
  1114:     //    | 160  105.34| 161  106.87| 162  108.42| 163  110.00| 164  111.60| 165  113.22| 166  114.87| 167  116.54| 168  118.24| 169  119.96|
  1115:     //    | 170  121.70| 171  123.47| 172  124.37| 173  125.27| 174  126.17| 175  127.09| 176  128.01| 177  128.94| 178  129.87| 179  130.81|
  1116:     //    | 180  132.72| 181  134.65| 182  136.60| 183  138.59| 184  140.61| 185  142.65| 186  144.73| 187  146.83| 188  148.97| 189  151.13|
  1117:     //    | 190  153.33| 191  155.56| 192  157.83| 193  160.12| 194  162.45| 195  164.81| 196  166.01| 197  167.21| 198  168.42| 199  169.64|
  1118:     //    | 200  170.87| 201  172.11| 202  173.36| 203  174.61| 204  177.15| 205  179.73| 206  182.34| 207  185.00| 208  187.69| 209  190.42|
  1119:     //    | 210  193.19| 211  196.00| 212  198.85| 213  201.74| 214  204.68| 215  207.65| 216  210.67| 217  213.74| 218  216.85| 219  220.00|
  1120:     //    | 220  223.20| 221  226.45| 222  229.74| 223  233.08| 224  236.47| 225  239.91| 226  243.40| 227  246.94| 228  248.73| 229  250.53|
  1121:     //    | 230  252.35| 231  254.18| 232  256.02| 233  257.87| 234  259.74| 235  261.63| 236  265.43| 237  269.29| 238  273.21| 239  277.18|
  1122:     //    | 240  281.21| 241  285.30| 242  289.45| 243  293.66| 244  297.94| 245  302.27| 246  306.67| 247  311.13| 248  315.65| 249  320.24|
  1123:     //    | 250  324.90| 251  329.63| 252  332.02| 253  334.42| 254  336.85| 255  339.29| 256  341.74| 257  344.22| 258  346.72| 259  349.23|
  1124:     //    | 260  354.31| 261  359.46| 262  364.69| 263  369.99| 264  375.38| 265  380.84| 266  386.38| 267  392.00| 268  397.70| 269  403.48|
  1125:     //    | 270  409.35| 271  415.30| 272  421.35| 273  427.47| 274  433.69| 275  440.00| 276  446.40| 277  452.89| 278  459.48| 279  466.16|
  1126:     //    | 280  472.94| 281  479.82| 282  486.80| 283  493.88| 284  497.46| 285  501.07| 286  504.70| 287  508.36| 288  512.04| 289  515.75|
  1127:     //    | 290  519.49| 291  523.25| 292  530.86| 293  538.58| 294  546.42| 295  554.37| 296  562.43| 297  570.61| 298  578.91| 299  587.33|
  1128:     //    | 300  595.87| 301  604.54| 302  613.33| 303  622.25| 304  631.30| 305  640.49| 306  649.80| 307  659.26| 308  664.03| 309  668.84|
  1129:     //    | 310  673.69| 311  678.57| 312  683.49| 313  688.44| 314  693.43| 315  698.46| 316  708.62| 317  718.92| 318  729.38| 319  739.99|
  1130:     //    | 320  750.75| 321  761.67| 322  772.75| 323  783.99| 324  795.39| 325  806.96| 326  818.70| 327  830.61| 328  842.69| 329  854.95|
  1131:     //    | 330  867.38| 331  880.00| 332  892.80| 333  905.79| 334  918.96| 335  932.33| 336  945.89| 337  959.65| 338  973.61| 339  987.77|
  1132:     //    | 340  994.92| 341 1002.13| 342 1009.40| 343 1016.71| 344 1024.08| 345 1031.50| 346 1038.97| 347 1046.50| 348 1061.72| 349 1077.17|
  1133:     //    | 350 1092.83| 351 1108.73| 352 1124.86| 353 1141.22| 354 1157.82| 355 1174.66| 356 1191.74| 357 1209.08| 358 1226.67| 359 1244.51|
  1134:     //    | 360 1262.61| 361 1280.97| 362 1299.61| 363 1318.51| 364 1328.06| 365 1337.69| 366 1347.38| 367 1357.15| 368 1366.98| 369 1376.89|
  1135:     //    | 370 1386.86| 371 1396.91| 372 1417.23| 373 1437.85| 374 1458.76| 375 1479.98| 376 1501.50| 377 1523.34| 378 1545.50| 379 1567.98|
  1136:     //    | 380 1590.79| 381 1613.93| 382 1637.40| 383 1661.22| 384 1685.38| 385 1709.90| 386 1734.77| 387 1760.00| 388 1785.60| 389 1811.57|
  1137:     //    | 390 1837.92| 391 1864.66| 392 1891.78| 393 1919.29| 394 1947.21| 395 1975.53| 396 1989.85| 397 2004.27| 398 2018.79| 399 2033.42|
  1138:     //    | 400 2048.16| 401 2063.00| 402 2077.95| 403 2093.00| 404 2123.45| 405 2154.33| 406 2185.67| 407 2217.46| 408 2249.71| 409 2282.44|
  1139:     //    | 410 2315.64| 411 2349.32| 412 2383.49| 413 2418.16| 414 2453.33| 415 2489.02| 416 2525.22| 417 2561.95| 418 2599.21| 419 2637.02|
  1140:     //    | 420 2656.13| 421 2675.38| 422 2694.76| 423 2714.29| 424 2733.96| 425 2753.77| 426 2773.73| 427 2793.83| 428 2834.46| 429 2875.69|
  1141:     //    | 430 2917.52| 431 2959.96| 432 3003.01| 433 3046.69| 434 3091.00| 435 3135.96| 436 3181.58| 437 3227.85| 438 3274.80| 439 3322.44|
  1142:     //    | 440 3370.76| 441 3419.79| 442 3469.53| 443 3520.00| 444 3571.20| 445 3623.14| 446 3675.84| 447 3729.31| 448 3783.55| 449 3838.59|
  1143:     //    | 450 3894.42| 451 3951.07| 452 3979.70| 453 4008.54| 454 4037.58| 455 4066.84| 456 4096.31| 457 4126.00| 458 4155.89| 459 4186.01|
  1144:     //    | 460 4246.90| 461 4308.67| 462 4371.34| 463 4434.92| 464 4499.43| 465 4564.88| 466 4631.27| 467 4698.64| 468 4766.98| 469 4836.32|
  1145:     //    | 470 4906.66| 471 4978.03| 472 5050.44| 473 5123.90| 474 5198.43| 475 5274.04| 476 5312.26| 477 5350.75| 478 5389.53| 479 5428.58|
  1146:     //
  1147:     //  周波数の範囲の分割
  1148:     //    周波数の範囲が広いので1回のFFTで全体を処理しようとすると端の方で大きな誤差または大きな無駄が生じる
  1149:     //    周波数の範囲を5分割してサンプリング間隔を変えて処理する
  1150:     //    分割数が少ないと区間毎のサンプリング期間の違いが大きくなり遅延時間にずれが生じて区間の境目に壁ができてしまう
  1151:     //    周波数の低い区間では完全に分解しようとすると大きな遅延が生じてしまうので分解能よりもレスポンスを優先する
  1152:     //
  1153:     //                                                サンプリング          更新サンプル数
  1154:     //             x座標          周波数         間隔   周波数   数    期間      /ブロック
  1155:     //      0,1    0..159    14.78Hz..103.83Hz    100    625Hz  1024  1.638s        25
  1156:     //       2   160..239   105.34Hz..277.18Hz     50   1250Hz  1024  0.819s        50
  1157:     //       3   240..319   281.21Hz..739.99Hz     25   2500Hz  1024  0.410s       100
  1158:     //       4   320..399   750.75Hz..2033.42Hz    10   6250Hz  1024  0.164s       250
  1159:     //       5   400..479  2048.16Hz..5428.58Hz     5  12500Hz  1024  0.082s       500
  1160:     //
  1161:     //  x座標とフーリエ変換の結果のインデックスの関係
  1162:     //
  1163:     //    perl -e "@m=(0,1,2,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,36,37,38,39,40,41,42,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,92,93,94,95);for$r([0,160,100],[160,240,50],[240,320,25],[320,400,10],[400,480,5]){for$x($r->[0]..$r->[1]){$x%10 or print'    //    ';printf'|%4d%4d',$x,int($r->[2]*1024/62500*440*2**(((int(($x-8+56)/56)-1)*96+$m[($x-8+56)%56]-(96*4+75))/96));$x%10==9 and printf'|%c',10;}printf'|%c',10;}"
  1164:     //    |   0  24|   1  24|   2  24|   3  25|   4  25|   5  25|   6  25|   7  26|   8  26|   9  26|
  1165:     //    |  10  26|  11  26|  12  27|  13  27|  14  27|  15  28|  16  28|  17  29|  18  29|  19  30|
  1166:     //    |  20  30|  21  30|  22  31|  23  31|  24  32|  25  32|  26  33|  27  33|  28  33|  29  34|
  1167:     //    |  30  34|  31  34|  32  34|  33  35|  34  35|  35  35|  36  36|  37  36|  38  37|  39  37|
  1168:     //    |  40  38|  41  38|  42  39|  43  40|  44  40|  45  41|  46  41|  47  42|  48  43|  49  43|
  1169:     //    |  50  44|  51  45|  52  45|  53  46|  54  47|  55  47|  56  48|  57  49|  58  49|  59  50|
  1170:     //    |  60  50|  61  51|  62  51|  63  52|  64  52|  65  52|  66  53|  67  53|  68  54|  69  55|
  1171:     //    |  70  55|  71  56|  72  57|  73  58|  74  59|  75  60|  76  61|  77  61|  78  62|  79  63|
  1172:     //    |  80  64|  81  65|  82  66|  83  67|  84  67|  85  68|  86  68|  87  69|  88  69|  89  70|
  1173:     //    |  90  71|  91  71|  92  72|  93  73|  94  74|  95  75|  96  76|  97  77|  98  79|  99  80|
  1174:     //    | 100  81| 101  82| 102  83| 103  85| 104  86| 105  87| 106  88| 107  90| 108  91| 109  92|
  1175:     //    | 110  94| 111  95| 112  96| 113  98| 114  99| 115 101| 116 101| 117 102| 118 103| 119 104|
  1176:     //    | 120 104| 121 105| 122 106| 123 107| 124 108| 125 110| 126 111| 127 113| 128 115| 129 116|
  1177:     //    | 130 118| 131 120| 132 122| 133 123| 134 125| 135 127| 136 129| 137 131| 138 133| 139 135|
  1178:     //    | 140 135| 141 136| 142 137| 143 138| 144 139| 145 140| 146 142| 147 143| 148 145| 149 147|
  1179:     //    | 150 149| 151 151| 152 153| 153 155| 154 158| 155 160| 156 162| 157 165| 158 167| 159 170|
  1180:     //    | 160 172|
  1181:     //    | 160  86| 161  87| 162  88| 163  90| 164  91| 165  92| 166  94| 167  95| 168  96| 169  98|
  1182:     //    | 170  99| 171 101| 172 101| 173 102| 174 103| 175 104| 176 104| 177 105| 178 106| 179 107|
  1183:     //    | 180 108| 181 110| 182 111| 183 113| 184 115| 185 116| 186 118| 187 120| 188 122| 189 123|
  1184:     //    | 190 125| 191 127| 192 129| 193 131| 194 133| 195 135| 196 135| 197 136| 198 137| 199 138|
  1185:     //    | 200 139| 201 140| 202 142| 203 143| 204 145| 205 147| 206 149| 207 151| 208 153| 209 155|
  1186:     //    | 210 158| 211 160| 212 162| 213 165| 214 167| 215 170| 216 172| 217 175| 218 177| 219 180|
  1187:     //    | 220 182| 221 185| 222 188| 223 190| 224 193| 225 196| 226 199| 227 202| 228 203| 229 205|
  1188:     //    | 230 206| 231 208| 232 209| 233 211| 234 212| 235 214| 236 217| 237 220| 238 223| 239 227|
  1189:     //    | 240 230|
  1190:     //    | 240 115| 241 116| 242 118| 243 120| 244 122| 245 123| 246 125| 247 127| 248 129| 249 131|
  1191:     //    | 250 133| 251 135| 252 135| 253 136| 254 137| 255 138| 256 139| 257 140| 258 142| 259 143|
  1192:     //    | 260 145| 261 147| 262 149| 263 151| 264 153| 265 155| 266 158| 267 160| 268 162| 269 165|
  1193:     //    | 270 167| 271 170| 272 172| 273 175| 274 177| 275 180| 276 182| 277 185| 278 188| 279 190|
  1194:     //    | 280 193| 281 196| 282 199| 283 202| 284 203| 285 205| 286 206| 287 208| 288 209| 289 211|
  1195:     //    | 290 212| 291 214| 292 217| 293 220| 294 223| 295 227| 296 230| 297 233| 298 237| 299 240|
  1196:     //    | 300 244| 301 247| 302 251| 303 254| 304 258| 305 262| 306 266| 307 270| 308 271| 309 273|
  1197:     //    | 310 275| 311 277| 312 279| 313 281| 314 284| 315 286| 316 290| 317 294| 318 298| 319 303|
  1198:     //    | 320 307|
  1199:     //    | 320 123| 321 124| 322 126| 323 128| 324 130| 325 132| 326 134| 327 136| 328 138| 329 140|
  1200:     //    | 330 142| 331 144| 332 146| 333 148| 334 150| 335 152| 336 154| 337 157| 338 159| 339 161|
  1201:     //    | 340 163| 341 164| 342 165| 343 166| 344 167| 345 169| 346 170| 347 171| 348 173| 349 176|
  1202:     //    | 350 179| 351 181| 352 184| 353 186| 354 189| 355 192| 356 195| 357 198| 358 200| 359 203|
  1203:     //    | 360 206| 361 209| 362 212| 363 216| 364 217| 365 219| 366 220| 367 222| 368 223| 369 225|
  1204:     //    | 370 227| 371 228| 372 232| 373 235| 374 239| 375 242| 376 246| 377 249| 378 253| 379 256|
  1205:     //    | 380 260| 381 264| 382 268| 383 272| 384 276| 385 280| 386 284| 387 288| 388 292| 389 296|
  1206:     //    | 390 301| 391 305| 392 309| 393 314| 394 319| 395 323| 396 326| 397 328| 398 330| 399 333|
  1207:     //    | 400 335|
  1208:     //    | 400 167| 401 169| 402 170| 403 171| 404 173| 405 176| 406 179| 407 181| 408 184| 409 186|
  1209:     //    | 410 189| 411 192| 412 195| 413 198| 414 200| 415 203| 416 206| 417 209| 418 212| 419 216|
  1210:     //    | 420 217| 421 219| 422 220| 423 222| 424 223| 425 225| 426 227| 427 228| 428 232| 429 235|
  1211:     //    | 430 239| 431 242| 432 246| 433 249| 434 253| 435 256| 436 260| 437 264| 438 268| 439 272|
  1212:     //    | 440 276| 441 280| 442 284| 443 288| 444 292| 445 296| 446 301| 447 305| 448 309| 449 314|
  1213:     //    | 450 319| 451 323| 452 326| 453 328| 454 330| 455 333| 456 335| 457 338| 458 340| 459 342|
  1214:     //    | 460 347| 461 352| 462 358| 463 363| 464 368| 465 373| 466 379| 467 384| 468 390| 469 396|
  1215:     //    | 470 401| 471 407| 472 413| 473 419| 474 425| 475 432| 476 435| 477 438| 478 441| 479 444|
  1216:     //    | 480 447|
  1217:     //
  1218:     //クリア
  1219:     //  毎回減った分だけ消しているので不要
  1220:     //Arrays.fill (bb, SMN_OFFSET * SMN_SPECTRUM_Y, SMN_OFFSET * (SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT), SMN_BLACK);
  1221:     //アイコン
  1222:     //smnDrawIcon3 (SMN_SPECTRUM_X / 4, SMN_SPECTRUM_Y, 9);
  1223:     //バッファを更新する
  1224:     double[] buffer0 = smnSpectrumBuffer[0];
  1225:     double[] buffer2 = smnSpectrumBuffer[2];
  1226:     double[] buffer3 = smnSpectrumBuffer[3];
  1227:     double[] buffer4 = smnSpectrumBuffer[4];
  1228:     double[] buffer5 = smnSpectrumBuffer[5];
  1229:     //  区間5
  1230:     System.arraycopy (buffer5, 500, buffer5, 0, SMN_SPECTRUM_N - 500);
  1231:     if (SoundSource.SND_CHANNELS == 1) {  //モノラル
  1232:       for (int i = SMN_SPECTRUM_N - 500, k = 0; i < SMN_SPECTRUM_N; i++, k += 5) {
  1233:         buffer5[i] = (double) (OPM.opmBuffer[k    ] + ADPCM.pcmBuffer[k    ] +
  1234:                                OPM.opmBuffer[k + 1] + ADPCM.pcmBuffer[k + 1] +
  1235:                                OPM.opmBuffer[k + 2] + ADPCM.pcmBuffer[k + 2] +
  1236:                                OPM.opmBuffer[k + 3] + ADPCM.pcmBuffer[k + 3] +
  1237:                                OPM.opmBuffer[k + 4] + ADPCM.pcmBuffer[k + 4]) * (0.2 / 32768.0);
  1238:       }
  1239:     } else {  //ステレオ
  1240:       for (int i = SMN_SPECTRUM_N - 500, k = 0; i < SMN_SPECTRUM_N; i++, k += 10) {
  1241:         buffer5[i] = (double) (OPM.opmBuffer[k    ] + OPM.opmBuffer[k + 1] + ADPCM.pcmBuffer[k    ] + ADPCM.pcmBuffer[k + 1] +
  1242:                                OPM.opmBuffer[k + 2] + OPM.opmBuffer[k + 3] + ADPCM.pcmBuffer[k + 2] + ADPCM.pcmBuffer[k + 3] +
  1243:                                OPM.opmBuffer[k + 4] + OPM.opmBuffer[k + 5] + ADPCM.pcmBuffer[k + 4] + ADPCM.pcmBuffer[k + 5] +
  1244:                                OPM.opmBuffer[k + 6] + OPM.opmBuffer[k + 7] + ADPCM.pcmBuffer[k + 6] + ADPCM.pcmBuffer[k + 7] +
  1245:                                OPM.opmBuffer[k + 8] + OPM.opmBuffer[k + 9] + ADPCM.pcmBuffer[k + 8] + ADPCM.pcmBuffer[k + 9]) * (0.1 / 32768.0);
  1246:       }
  1247:     }
  1248:     //  区間4
  1249:     System.arraycopy (buffer4, 250, buffer4, 0, SMN_SPECTRUM_N - 250);
  1250:     for (int i = SMN_SPECTRUM_N - 250, k = SMN_SPECTRUM_N - 500; i < SMN_SPECTRUM_N; i++, k += 2) {
  1251:       buffer4[i] = (buffer5[k] + buffer5[k + 1]) * 0.5;
  1252:     }
  1253:     //  区間3
  1254:     System.arraycopy (buffer3, 100, buffer3, 0, SMN_SPECTRUM_N - 100);
  1255:     for (int i = SMN_SPECTRUM_N - 100, k = SMN_SPECTRUM_N - 500; i < SMN_SPECTRUM_N; i++, k += 5) {
  1256:       buffer3[i] = (buffer5[k] + buffer5[k + 1] + buffer5[k + 2] + buffer5[k + 3] + buffer5[k + 4]) * 0.2;
  1257:     }
  1258:     //  区間2
  1259:     System.arraycopy (buffer2, 50, buffer2, 0, SMN_SPECTRUM_N - 50);
  1260:     for (int i = SMN_SPECTRUM_N - 50, k = SMN_SPECTRUM_N - 100; i < SMN_SPECTRUM_N; i++, k += 2) {
  1261:       buffer2[i] = (buffer3[k] + buffer3[k + 1]) * 0.5;
  1262:     }
  1263:     //  区間0
  1264:     System.arraycopy (buffer0, 25, buffer0, 0, SMN_SPECTRUM_N - 25);
  1265:     for (int i = SMN_SPECTRUM_N - 25, k = SMN_SPECTRUM_N - 50; i < SMN_SPECTRUM_N; i++, k += 2) {
  1266:       buffer0[i] = (buffer2[k] + buffer2[k + 1]) * 0.5;
  1267:     }
  1268:     for (int partition = 0; partition < SMN_SPECTRUM_PARTITIONS; partition++) {
  1269:       if (partition != 1) {  //区間1は区間0の結果を使う
  1270:         //実数部
  1271:         double[] buffer = smnSpectrumBuffer[partition];
  1272:         for (int i = 0; i < SMN_SPECTRUM_N; i++) {
  1273:           smnSpectrumX[i] = smnSpectrumWindow[i] * buffer[i];
  1274:         }
  1275:         //虚数部
  1276:         Arrays.fill (smnSpectrumY, 0, SMN_SPECTRUM_N, 0.0);
  1277:         //FFTを呼び出す
  1278:         //smnFFT.fftSandeTukey2 (smnSpectrumX, smnSpectrumY);  //基数2
  1279:         smnFFT.fftSandeTukey4 (smnSpectrumX, smnSpectrumY);  //基数4
  1280:       }
  1281:       //グラフを描く
  1282:       //  区間0はx=8から描く
  1283:       for (int x = partition == 0 ? 8 : SMN_SPECTRUM_RANGE * partition, x1 = x + SMN_SPECTRUM_RANGE, b = 6; x < x1; x++, b = b - 2 & 6) {  //b=6,4,2,0
  1284:         int k = smnSpectrumIndex[x];
  1285:         int n = k >> 16;
  1286:         k = (char) k;
  1287:         double level = smnSpectrumX[k];
  1288:         while (--n > 0) {
  1289:           level = Math.max (level, smnSpectrumX[++k]);
  1290:         }
  1291:         int value = Math.max (0, Math.min (SMN_SPECTRUM_HEIGHT - 1, (int) ((double) SMN_SPECTRUM_HEIGHT / (double) SMN_SPECTRUM_N * SMN_SPECTRUM_SCALE * level)));  //今回の値。0=最小,SMN_SPECTRUM_HEIGHT-1=最大
  1292:         int value0 = smnSpectrumValue[x];  //前回の値
  1293:         if (value > value0) {  //増えたとき
  1294:           smnSpectrumValue[x] = value;
  1295:           int i = SMN_OFFSET * (SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT - 1 - value) + SMN_SPECTRUM_X / 4 + (x >> 2);
  1296:           while (value > value0) {
  1297:             bb[i] = (byte) (bb[i] & ~(3 << b) | (SMN_WHITE & 3) << b);
  1298:             i += SMN_OFFSET;
  1299:             value--;
  1300:           }
  1301:         } else if (value < value0) {  //減ったとき
  1302:           if (value < value0 - SMN_SPECTRUM_TRAIL) {
  1303:             value = value0 - SMN_SPECTRUM_TRAIL;
  1304:           }
  1305:           smnSpectrumValue[x] = value;
  1306:           int i = SMN_OFFSET * (SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT - 1 - value0) + SMN_SPECTRUM_X / 4 + (x >> 2);
  1307:           while (value < value0) {
  1308:             bb[i] = (byte) (bb[i] & ~(3 << b));
  1309:             i += SMN_OFFSET;
  1310:             value++;
  1311:           }
  1312:         }
  1313:       }  //for i
  1314:     }  //for partition
  1315: 
  1316:     //OPM
  1317:     for (int ch = 0; ch < 8; ch++) {
  1318:       YM2151.fm_channel channel = OPM.opmYM2151.m_channel[ch];
  1319:       YM2151.fm_operator opM1 = channel.m_op[0];
  1320:       YM2151.fm_operator opM2 = channel.m_op[1];
  1321:       YM2151.fm_operator opC1 = channel.m_op[2];
  1322:       YM2151.fm_operator opC2 = channel.m_op[3];
  1323:       //鍵盤
  1324:       int k0 = smnKey[ch];  //前回キーオンされていたかリリース中だったキー。0x10000+キー=リリース中。-1=なし
  1325:       //  -=ATTACK/DECAY/SUSTAIN,0=RELEASE,+=SILENCE
  1326:       int m1 = opM1.m_env_state < YM2151.EG_RELEASE ? -1 : opM1.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
  1327:       int m2 = opM2.m_env_state < YM2151.EG_RELEASE ? -1 : opM2.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
  1328:       int c1 = opC1.m_env_state < YM2151.EG_RELEASE ? -1 : opC1.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
  1329:       int c2 = opC2.m_env_state < YM2151.EG_RELEASE ? -1 : opC2.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
  1330:       int k1;  //今回キーオンされているかリリース中のキー。0x10000+キー=リリース中。-1=なし
  1331:       if (m1 > 0 && m2 > 0 && c1 > 0 && c2 > 0) {  //すべてSILENCE。キーオフ
  1332:         k1 = -1;
  1333:       } else {
  1334:         //  KC=74のときKF=5.5くらいで440Hzになるので、KFが38以上のときKCを1増やす
  1335:         int kc = OPM.opmRegister[0x28 + ch] & 127;
  1336:         int kf = (OPM.opmRegister[0x30 + ch] >> 2) & 63;
  1337:         k1 = (((kc - (kc >> 2)) << 6 | kf) + (3 << 6) + (64 - 38)) >> 6;  //今回キーオンされているか最後にキーオンされたキー
  1338:         if (m1 >= 0 && m2 >= 0 && c1 >= 0 && c2 >= 0) {  //1個以上のRELEASEと0個以上のSILENCE。リリース中
  1339:           k1 |= 0x10000;
  1340:         }
  1341:       }
  1342:       if (k0 != k1) {  //キーオンされているキーまたはキーの状態が変わった
  1343:         int i = SMN_KEY_X / 4 + SMN_OFFSET * (SMN_KEY_Y + 6 + 12 * ch);  //鍵盤の左端
  1344:         if (k0 >= 0 && (short) k0 != (short) k1) {  //前回キーオンされていたかリリース中だったキーがあって、キーが変わった
  1345:           //perl optdiv.pl 97 12
  1346:           //  x/12==x*43>>>9 (0<=x<=130) [97*43==4171]
  1347:           int kk = (short) k0;
  1348:           int o = kk * 43 >>> 9;  //オクターブ
  1349:           kk -= 12 * o;  //鍵の番号。0..11
  1350:           smnPaintKey (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_KEY_COLOR[kk]);
  1351:         }
  1352:         if (k1 >= 0 && k0 != k1) {  //今回キーオンされているかリリース中のキーがあって、キーまたはキーの状態が変わった
  1353:           //perl optdiv.pl 97 12
  1354:           //  x/12==x*43>>>9 (0<=x<=130) [97*43==4171]
  1355:           int kk = (short) k1;
  1356:           int o = kk * 43 >>> 9;  //オクターブ
  1357:           kk -= 12 * o;  //鍵の番号。0..11
  1358:           if (k1 >> 16 == 0) {  //キーオンされている
  1359:             smnPaintKey (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_ORANGE);
  1360:           } else {  //リリース中
  1361:             smnPaintKey2 (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_KEY_COLOR[kk], SMN_ORANGE);
  1362:           }
  1363:         }
  1364:         smnKey[ch] = k1;
  1365:       }
  1366:       //音色
  1367:       {
  1368:         XEiJ.fmtHex2 (SMN_TONE_V0,  0, OPM.opmRegister[0x20 + ch] & 63);  //FLCON
  1369:         XEiJ.fmtHex2 (SMN_TONE_V0,  3, OPM.opmRegister[256 + ch]);  //SLOT
  1370:         XEiJ.fmtHex2 (SMN_TONE_V0,  6, OPM.opmRegister[0x1b] & 3);  //WAVE
  1371:         XEiJ.fmtHex2 (SMN_TONE_V0,  9, 0);  //SYNC
  1372:         XEiJ.fmtHex2 (SMN_TONE_V0, 12, OPM.opmRegister[0x18] & 255);  //SPEED
  1373:         XEiJ.fmtHex2 (SMN_TONE_V0, 15, OPM.opmRegister[265]);  //PMD
  1374:         XEiJ.fmtHex2 (SMN_TONE_V0, 18, OPM.opmRegister[264]);  //AMD
  1375:         XEiJ.fmtHex2 (SMN_TONE_V0, 21, (OPM.opmRegister[0x38 + ch] >> 4) & 7);  //PMS
  1376:         XEiJ.fmtHex2 (SMN_TONE_V0, 24, OPM.opmRegister[0x38 + ch] & 3);  //AMS
  1377:         XEiJ.fmtHex2 (SMN_TONE_V0, 27, (OPM.opmRegister[0x20 + ch] >> 6) & 3);  //PAN
  1378:         XEiJ.fmtHex2 (SMN_TONE_V1,  0, OPM.opmRegister[0x80 + ch] & 31);  //M1 AR
  1379:         XEiJ.fmtHex2 (SMN_TONE_V2,  0, OPM.opmRegister[0x90 + ch] & 31);  //C1 AR
  1380:         XEiJ.fmtHex2 (SMN_TONE_V3,  0, OPM.opmRegister[0x88 + ch] & 31);  //M2 AR
  1381:         XEiJ.fmtHex2 (SMN_TONE_V4,  0, OPM.opmRegister[0x98 + ch] & 31);  //C2 AR
  1382:         XEiJ.fmtHex2 (SMN_TONE_V1,  3, OPM.opmRegister[0xa0 + ch] & 31);  //M1 D1R
  1383:         XEiJ.fmtHex2 (SMN_TONE_V2,  3, OPM.opmRegister[0xb0 + ch] & 31);  //C1 D1R
  1384:         XEiJ.fmtHex2 (SMN_TONE_V3,  3, OPM.opmRegister[0xa8 + ch] & 31);  //M2 D1R
  1385:         XEiJ.fmtHex2 (SMN_TONE_V4,  3, OPM.opmRegister[0xb8 + ch] & 31);  //C2 D1R
  1386:         XEiJ.fmtHex2 (SMN_TONE_V1,  6, OPM.opmRegister[0xc0 + ch] & 31);  //M1 D2R
  1387:         XEiJ.fmtHex2 (SMN_TONE_V2,  6, OPM.opmRegister[0xd0 + ch] & 31);  //C1 D2R
  1388:         XEiJ.fmtHex2 (SMN_TONE_V3,  6, OPM.opmRegister[0xc8 + ch] & 31);  //M2 D2R
  1389:         XEiJ.fmtHex2 (SMN_TONE_V4,  6, OPM.opmRegister[0xd8 + ch] & 31);  //C2 D2R
  1390:         XEiJ.fmtHex2 (SMN_TONE_V1,  9, OPM.opmRegister[0xe0 + ch] & 15);  //M1 RR
  1391:         XEiJ.fmtHex2 (SMN_TONE_V2,  9, OPM.opmRegister[0xf0 + ch] & 15);  //C1 RR
  1392:         XEiJ.fmtHex2 (SMN_TONE_V3,  9, OPM.opmRegister[0xe8 + ch] & 15);  //M2 RR
  1393:         XEiJ.fmtHex2 (SMN_TONE_V4,  9, OPM.opmRegister[0xf8 + ch] & 15);  //C2 RR
  1394:         XEiJ.fmtHex2 (SMN_TONE_V1, 12, (OPM.opmRegister[0xe0 + ch] >> 4) & 15);  //M1 D1L
  1395:         XEiJ.fmtHex2 (SMN_TONE_V2, 12, (OPM.opmRegister[0xf0 + ch] >> 4) & 15);  //C1 D1L
  1396:         XEiJ.fmtHex2 (SMN_TONE_V3, 12, (OPM.opmRegister[0xe8 + ch] >> 4) & 15);  //M2 D1L
  1397:         XEiJ.fmtHex2 (SMN_TONE_V4, 12, (OPM.opmRegister[0xf8 + ch] >> 4) & 15);  //C2 D1L
  1398:         XEiJ.fmtHex2 (SMN_TONE_V1, 15, OPM.opmRegister[0x60 + ch] & 127);  //M1 TL
  1399:         XEiJ.fmtHex2 (SMN_TONE_V2, 15, OPM.opmRegister[0x70 + ch] & 127);  //C1 TL
  1400:         XEiJ.fmtHex2 (SMN_TONE_V3, 15, OPM.opmRegister[0x68 + ch] & 127);  //M2 TL
  1401:         XEiJ.fmtHex2 (SMN_TONE_V4, 15, OPM.opmRegister[0x78 + ch] & 127);  //C2 TL
  1402:         XEiJ.fmtHex2 (SMN_TONE_V1, 18, (OPM.opmRegister[0x80 + ch] >> 6) & 3);  //M1 KS
  1403:         XEiJ.fmtHex2 (SMN_TONE_V2, 18, (OPM.opmRegister[0x90 + ch] >> 6) & 3);  //C1 KS
  1404:         XEiJ.fmtHex2 (SMN_TONE_V3, 18, (OPM.opmRegister[0x88 + ch] >> 6) & 3);  //M2 KS
  1405:         XEiJ.fmtHex2 (SMN_TONE_V4, 18, (OPM.opmRegister[0x98 + ch] >> 6) & 3);  //C2 KS
  1406:         XEiJ.fmtHex2 (SMN_TONE_V1, 21, OPM.opmRegister[0x40 + ch] & 15);  //M1 MUL
  1407:         XEiJ.fmtHex2 (SMN_TONE_V2, 21, OPM.opmRegister[0x50 + ch] & 15);  //C1 MUL
  1408:         XEiJ.fmtHex2 (SMN_TONE_V3, 21, OPM.opmRegister[0x48 + ch] & 15);  //M2 MUL
  1409:         XEiJ.fmtHex2 (SMN_TONE_V4, 21, OPM.opmRegister[0x58 + ch] & 15);  //C2 MUL
  1410:         XEiJ.fmtHex2 (SMN_TONE_V1, 24, (OPM.opmRegister[0x40 + ch] >> 4) & 7);  //M1 DT1
  1411:         XEiJ.fmtHex2 (SMN_TONE_V2, 24, (OPM.opmRegister[0x50 + ch] >> 4) & 7);  //C1 DT1
  1412:         XEiJ.fmtHex2 (SMN_TONE_V3, 24, (OPM.opmRegister[0x48 + ch] >> 4) & 7);  //M2 DT1
  1413:         XEiJ.fmtHex2 (SMN_TONE_V4, 24, (OPM.opmRegister[0x58 + ch] >> 4) & 7);  //C2 DT1
  1414:         XEiJ.fmtHex2 (SMN_TONE_V1, 27, (OPM.opmRegister[0xc0 + ch] >> 6) & 3);  //M1 DT2
  1415:         XEiJ.fmtHex2 (SMN_TONE_V2, 27, (OPM.opmRegister[0xd0 + ch] >> 6) & 3);  //C1 DT2
  1416:         XEiJ.fmtHex2 (SMN_TONE_V3, 27, (OPM.opmRegister[0xc8 + ch] >> 6) & 3);  //M2 DT2
  1417:         XEiJ.fmtHex2 (SMN_TONE_V4, 27, (OPM.opmRegister[0xd8 + ch] >> 6) & 3);  //C2 DT2
  1418:         XEiJ.fmtHex2 (SMN_TONE_V1, 30, (OPM.opmRegister[0xa0 + ch] >> 7) & 1);  //M1 AMSEN
  1419:         XEiJ.fmtHex2 (SMN_TONE_V2, 30, (OPM.opmRegister[0xb0 + ch] >> 7) & 1);  //C1 AMSEN
  1420:         XEiJ.fmtHex2 (SMN_TONE_V3, 30, (OPM.opmRegister[0xa8 + ch] >> 7) & 1);  //M2 AMSEN
  1421:         XEiJ.fmtHex2 (SMN_TONE_V4, 30, (OPM.opmRegister[0xb8 + ch] >> 7) & 1);  //C2 AMSEN
  1422:         int x = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * (0b01_00_10_01_00_10_01_00 >> (ch << 1) & 3);
  1423:         int y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * (0b10_10_01_01_01_00_00_00 >> (ch << 1) & 3);
  1424:         smnDrawString3 (3 + x, 6     + y, SMN_TONE_V0);
  1425:         smnDrawString3 (3 + x, 6 * 3 + y, SMN_TONE_V1);
  1426:         smnDrawString3 (3 + x, 6 * 4 + y, SMN_TONE_V2);
  1427:         smnDrawString3 (3 + x, 6 * 5 + y, SMN_TONE_V3);
  1428:         smnDrawString3 (3 + x, 6 * 6 + y, SMN_TONE_V4);
  1429:       }
  1430:     }  //for ch
  1431: 
  1432:     //PCM
  1433:     smnDrawString3 (SMN_PCM_COL +  3, SMN_PCM_Y    , SMN_PCM_OSCILLATOR[ADPCM.pcmOSCFreqMode << 1 | ADPCM.pcmOscillator]);
  1434:     smnDrawString3 (SMN_PCM_COL + 11, SMN_PCM_Y    , SMN_PCM_DIVIDER[ADPCM.pcmDivider]);
  1435:     smnDrawString3 (SMN_PCM_COL + 16, SMN_PCM_Y    , SMN_PCM_FREQ[ADPCM.pcmOSCFreqMode << 3 | ADPCM.pcmOscillator << 2 | ADPCM.pcmDivider]);
  1436:     smnDrawString2 (SMN_PCM_COL +  3, SMN_PCM_Y + 6, SMN_PCM_PLAY[ADPCM.pcmActive ? 1 : 0]);
  1437:     smnDrawString2 (SMN_PCM_COL +  8, SMN_PCM_Y + 6, SMN_PCM_DATA[ADPCM.pcmEncodedData >= 0 ? 1 : 0]);
  1438:     smnDrawString2 (SMN_PCM_COL + 13, SMN_PCM_Y + 6, SMN_PCM_LEFT[ADPCM.pcmPanLeft == 0 || ADPCM.pcmPanLeft < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1]);
  1439:     smnDrawString2 (SMN_PCM_COL + 18, SMN_PCM_Y + 6, SMN_PCM_RIGHT[SoundSource.SND_CHANNELS == 1 ?
  1440:                                                                    ADPCM.pcmPanLeft == 0 || ADPCM.pcmPanLeft < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1 :
  1441:                                                                    ADPCM.pcmPanRight == 0 || ADPCM.pcmPanRight < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1]);
  1442: 
  1443:     smnPanel.repaint ();
  1444: 
  1445:   }  //smnUpdate()
  1446: 
  1447:   //smnWavePaint ()
  1448:   //  波形を描く
  1449:   public static void smnWavePaint () {
  1450:     byte[] bb = smnBitmap;
  1451:     //クリア
  1452:     Arrays.fill (bb, SMN_OFFSET * SMN_WAVE_Y, SMN_OFFSET * (SMN_WAVE_Y + SMN_WAVE_HEIGHT), SMN_BLACK);
  1453:     //アイコン
  1454:     smnDrawIcon3 (SMN_WAVE_X / 4 - 2, SMN_WAVE_Y, 8);
  1455:     //時間軸
  1456:     if (-SMN_WAVE_HEIGHT / 2 <= smnWaveElevation && smnWaveElevation <= SMN_WAVE_HEIGHT / 2) {
  1457:       int i = SMN_OFFSET * (SMN_WAVE_Y + SMN_WAVE_HEIGHT / 2 - smnWaveElevation) + SMN_WAVE_X / 4;
  1458:       Arrays.fill (bb, i, i + SMN_WAVE_WIDTH / 4, SMN_BLUE);
  1459:     }
  1460:     //時間目盛り
  1461:     int ms0 = (1000 / SoundSource.SND_BLOCK_FREQ * smnWaveOffset + (SMN_WAVE_WIDTH << smnWaveScaleX) - 1) / (SMN_WAVE_WIDTH << smnWaveScaleX);
  1462:     int ms1 = 1000 / SoundSource.SND_BLOCK_FREQ * (smnWaveOffset + SMN_WAVE_WIDTH) / (SMN_WAVE_WIDTH << smnWaveScaleX);
  1463:     for (int ms = ms0; ms <= ms1; ms++) {
  1464:       //  perl optdiv.pl 11800 1000
  1465:       //  x/1000==x*8389>>>23 (0<=x<=21998) [11800*8389==98990200]
  1466:       //int x = SoundSource.SND_BLOCK_FREQ * SMN_WAVE_WIDTH * ms / 1000;
  1467:       int x = Math.max (0, Math.min (SMN_WAVE_WIDTH - 1, (SoundSource.SND_BLOCK_FREQ * SMN_WAVE_WIDTH * ms * 8389 >>> 23 << smnWaveScaleX) - smnWaveOffset));
  1468:       int b = (~x & 3) << 1;  //0→6,1→4,2→2,3→0
  1469:       if (ms1 - ms0 <= 10 ||
  1470:           ms1 - ms0 <= 20 && (1L << 63 -  0 |
  1471:                               1L << 63 -  5 |
  1472:                               1L << 63 - 10 |
  1473:                               1L << 63 - 15 |
  1474:                               1L << 63 - 20 |
  1475:                               1L << 63 - 25 |
  1476:                               1L << 63 - 30 |
  1477:                               1L << 63 - 35 |
  1478:                               1L << 63 - 40 |
  1479:                               1L << 63 - 45 |
  1480:                               1L << 63 - 50 |
  1481:                               1L << 63 - 55 |
  1482:                               1L << 63 - 60) << ms < 0 ||
  1483:           (1L << 63 -  0 |
  1484:            1L << 63 - 10 |
  1485:            1L << 63 - 20 |
  1486:            1L << 63 - 30 |
  1487:            1L << 63 - 40 |
  1488:            1L << 63 - 50 |
  1489:            1L << 63 - 60) << ms < 0) {
  1490:         int t = XEiJ.FMT_BCD4[ms];
  1491:         int col = SMN_WAVE_X / 4 + Math.max (0, Math.min (SMN_WAVE_WIDTH / 4 - (t >= 0x10 ? 4 : 3), (x + 3 >> 2) - (t >= 0x10 ? 2 : 1)));
  1492:         if (t >= 0x10) {
  1493:           smnDrawChar1 (col++, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, '0' | t >> 4);
  1494:         }
  1495:         smnDrawChar1 (col    , SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, '0' | t & 15);
  1496:         smnDrawChar1 (col + 1, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, 'm');
  1497:         smnDrawChar1 (col + 2, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, 's');
  1498:       }
  1499:       int v0, v1;
  1500:       if ((1L << 63 -  0 |
  1501:            1L << 63 - 10 |
  1502:            1L << 63 - 20 |
  1503:            1L << 63 - 30 |
  1504:            1L << 63 - 40 |
  1505:            1L << 63 - 50 |
  1506:            1L << 63 - 60) << ms < 0) {
  1507:         v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 4 / 16;  //0
  1508:         v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 4 / 16;  //SMN_WAVE_HEIGHT-1
  1509:       } else if ((1L << 63 -  0 |
  1510:                   1L << 63 -  5 |
  1511:                   1L << 63 - 10 |
  1512:                   1L << 63 - 15 |
  1513:                   1L << 63 - 20 |
  1514:                   1L << 63 - 25 |
  1515:                   1L << 63 - 30 |
  1516:                   1L << 63 - 35 |
  1517:                   1L << 63 - 40 |
  1518:                   1L << 63 - 45 |
  1519:                   1L << 63 - 50 |
  1520:                   1L << 63 - 55 |
  1521:                   1L << 63 - 60) << ms < 0) {
  1522:         v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 3 / 16;
  1523:         v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 3 / 16;
  1524:       } else {
  1525:         v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 2 / 16;
  1526:         v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 2 / 16;
  1527:       }
  1528:       v0 -= smnWaveElevation;
  1529:       v1 -= smnWaveElevation;
  1530:       if (v0 < 0) {
  1531:         v0 = 0;
  1532:       }
  1533:       if (v1 > SMN_WAVE_HEIGHT - 1) {
  1534:         v1 = SMN_WAVE_HEIGHT - 1;
  1535:       }
  1536:       int i = SMN_OFFSET * (SMN_WAVE_Y + v0) + SMN_WAVE_X / 4 + (x >> 2);
  1537:       for (int v = v0; v <= v1; v++) {
  1538:         bb[i] = (byte) (bb[i] & ~(3 << b) | (SMN_BLUE & 3) << b);
  1539:         i += SMN_OFFSET;
  1540:       }
  1541:     }
  1542:     if (SoundSource.SND_CHANNELS == 1) {  //モノラル
  1543:       smnWavePaint1 (smnPCMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMLeft);  //PCM
  1544:       smnWavePaint1 (smnOPMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMLeft);  //OPM
  1545:     } else {  //ステレオ
  1546:       smnWavePaint1 (smnPCMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMLeft);  //PCM left
  1547:       smnWavePaint1 (smnPCMBuffer, smnWaveIndex1[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMRight);  //PCM right
  1548:       smnWavePaint1 (smnOPMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMLeft);  //OPM left
  1549:       smnWavePaint1 (smnOPMBuffer, smnWaveIndex1[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMRight);  //OPM right
  1550:     }
  1551:   }  //smnWavePaint()
  1552: 
  1553:   //smnWavePaint1 (buffer, index, palet, lastY)
  1554:   public static void smnWavePaint1 (int[] buffer, int[] index, int palet, int[] lastY) {
  1555:     byte[] bb = smnBitmap;
  1556:     int o = smnWaveOffset;
  1557:     int t;
  1558:     int y0 = lastY[0];
  1559:     int y1 = lastY[1];
  1560:     int scaleY = SMN_WAVE_VALUE_SHIFT - smnWaveScaleY;
  1561:     for (int x = 0, b = 6; x < SMN_WAVE_WIDTH; x++, b = b - 2 & 6) {  //b=6,4,2,0
  1562:       int y2 = SMN_WAVE_HEIGHT / 2 - ((t = buffer[index[o + x]]) + (t >>> -scaleY) >> scaleY);
  1563:       int min, max;  //y1がminまたはmaxのときはy1まで、y0またはy2がminまたはmaxのときはy0+y1>>1またはy1+y2>>1まで描く
  1564:       if (y0 < y1) {  //y0<y1
  1565:         if (y1 < y2) {  //y0<y1<y2
  1566:           min = y0 + y1 >> 1;
  1567:           max = y1 + y2 >> 1;
  1568:         } else if (y0 < y2) {  //y0<y2<y1
  1569:           min = y0 + y1 >> 1;
  1570:           max = y1;
  1571:         } else {  //y2<y0<y1
  1572:           min = y1 + y2 >> 1;
  1573:           max = y1;
  1574:         }
  1575:       } else {  //y1<y0
  1576:         if (y0 < y2) {  //y1<y0<y2
  1577:           min = y1;
  1578:           max = y1 + y2 >> 1;
  1579:         } else if (y1 < y2) {  //y1<y2<y0
  1580:           min = y1;
  1581:           max = y0 + y1 >> 1;
  1582:         } else {  //y2<y1<y0
  1583:           min = y1 + y2 >> 1;
  1584:           max = y0 + y1 >> 1;
  1585:         }
  1586:       }
  1587:       min -= smnWaveElevation;
  1588:       max -= smnWaveElevation;
  1589:       //[min,max]と[0,SMN_WAVE_HEIGHT-1]の重なる部分だけ描く
  1590:       if (min < 0) {
  1591:         min = 0;
  1592:       }
  1593:       if (max > SMN_WAVE_HEIGHT - 1) {
  1594:         max = SMN_WAVE_HEIGHT - 1;
  1595:       }
  1596:       for (int y = min; y <= max; y++) {
  1597:         int i = SMN_OFFSET * (SMN_WAVE_Y + y) + SMN_WAVE_X / 4 + (x >> 2);
  1598:         bb[i] = (byte) (bb[i] & ~(3 << b) | palet << b);
  1599:       }
  1600:       y0 = y1;
  1601:       y1 = y2;
  1602:     }  //for x,b
  1603:     lastY[0] = y0;
  1604:     lastY[1] = y1;
  1605:   }  //smnWavePaint1(int[],int[],int,int[])
  1606: 
  1607:   //smnPaintKey (x, k, c1111)
  1608:   //  鍵を描く
  1609:   //  x      x座標
  1610:   //  k      鍵の番号。0..11
  1611:   //  c1111  4ドット分の色
  1612:   //    |    |   1|    |   3|    |    |    |   6|    |   8|    |  10|    |    |
  1613:   //    |    |  C#|    |  D#|    |    |    |  F#|    |  G#|    |  A#|    |    |
  1614:   //    |   0|   1|   2|   3|   4|   5|   6|   7|   8|   9|  10|  11|  12|  13|
  1615:   //   0|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1616:   //   1|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1617:   //   2|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1618:   //   3|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1619:   //   4|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1620:   //   5|WWW |    |    |    |    |WWW |WWW |    |    |    |    |    |    |WWW |
  1621:   //   6|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1622:   //   7|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1623:   //   8|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1624:   //   9|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1625:   //  10|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1626:   //    |   0|   1|   2|   3|   4|   5|   6|   7|   8|   9|  10|  11|  12|  13|
  1627:   //    |   C|    |   D|    |   E|    |   F|    |   G|    |   A|    |   B|    |
  1628:   //    |   0|    |   2|    |   4|    |   5|    |   7|    |   9|    |  11|    |
  1629:   public static void smnPaintKey (int i, int k, int c1111) {
  1630:     int c1110 = c1111 & 0b11111100;
  1631:     byte[] bb = smnBitmap;
  1632:     switch (k) {
  1633:     case 0:  //C
  1634:     case 5:  //F
  1635:       bb[       SMN_OFFSET *  6 + i] = (
  1636:         bb[     SMN_OFFSET *  7 + i] =
  1637:         bb[     SMN_OFFSET *  8 + i] =
  1638:         bb[     SMN_OFFSET *  9 + i] =
  1639:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111);
  1640:       bb[                       + i] = (
  1641:         bb[     SMN_OFFSET      + i] =
  1642:         bb[     SMN_OFFSET *  2 + i] =
  1643:         bb[     SMN_OFFSET *  3 + i] =
  1644:         bb[     SMN_OFFSET *  4 + i] =
  1645:         bb[     SMN_OFFSET *  5 + i] =
  1646:         bb[ 1 + SMN_OFFSET *  6 + i] =
  1647:         bb[ 1 + SMN_OFFSET *  7 + i] =
  1648:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1649:         bb[ 1 + SMN_OFFSET *  9 + i] =
  1650:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
  1651:       break;
  1652:     case 1:  //C#
  1653:     case 3:  //D#
  1654:     case 6:  //F#
  1655:     case 8:  //G#
  1656:     case 10:  //A#
  1657:       bb[                         i] = (
  1658:         bb[     SMN_OFFSET      + i] =
  1659:         bb[     SMN_OFFSET *  2 + i] =
  1660:         bb[     SMN_OFFSET *  3 + i] =
  1661:         bb[     SMN_OFFSET *  4 + i] = (byte) c1111);
  1662:       bb[   1 +                 + i] = (
  1663:         bb[ 1 + SMN_OFFSET      + i] =
  1664:         bb[ 1 + SMN_OFFSET *  2 + i] =
  1665:         bb[ 1 + SMN_OFFSET *  3 + i] =
  1666:         bb[ 1 + SMN_OFFSET *  4 + i] = (byte) c1110);
  1667:       break;
  1668:     case 2:  //D
  1669:     case 7:  //G
  1670:     case 9:  //A
  1671:       bb[       SMN_OFFSET *  6 + i] = (
  1672:         bb[     SMN_OFFSET *  7 + i] =
  1673:         bb[     SMN_OFFSET *  8 + i] =
  1674:         bb[     SMN_OFFSET *  9 + i] =
  1675:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111);
  1676:       bb[   1 + SMN_OFFSET *  6 + i] = (
  1677:         bb[ 1 + SMN_OFFSET *  7 + i] =
  1678:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1679:         bb[ 1 + SMN_OFFSET *  9 + i] =
  1680:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
  1681:       break;
  1682:     case 4:  //E
  1683:     case 11:  //B
  1684:       bb[       SMN_OFFSET *  6 + i] = (
  1685:         bb[     SMN_OFFSET *  7 + i] =
  1686:         bb[     SMN_OFFSET *  8 + i] =
  1687:         bb[     SMN_OFFSET *  9 + i] =
  1688:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111);
  1689:       bb[   1 +                 + i] = (
  1690:         bb[ 1 + SMN_OFFSET      + i] =
  1691:         bb[ 1 + SMN_OFFSET *  2 + i] =
  1692:         bb[ 1 + SMN_OFFSET *  3 + i] =
  1693:         bb[ 1 + SMN_OFFSET *  4 + i] =
  1694:         bb[ 1 + SMN_OFFSET *  5 + i] =
  1695:         bb[ 1 + SMN_OFFSET *  6 + i] =
  1696:         bb[ 1 + SMN_OFFSET *  7 + i] =
  1697:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1698:         bb[ 1 + SMN_OFFSET *  9 + i] =
  1699:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
  1700:       break;
  1701:     }  //switch k
  1702:   }  //smnPaintKey(int,int,int)
  1703: 
  1704:   //smnPaintKey2 (x, k, c1111a, c1111b)
  1705:   //  鍵を市松模様に塗る
  1706:   //  x       x座標
  1707:   //  k       鍵の番号。0..11
  1708:   //  c1111a  4ドット分の色a
  1709:   //  c1111b  4ドット分の色b
  1710:   //    |    |   1|    |   3|    |    |    |   6|    |   8|    |  10|    |    |
  1711:   //    |    |  C#|    |  D#|    |    |    |  F#|    |  G#|    |  A#|    |    |
  1712:   //    |   0|   1|   2|   3|   4|   5|   6|   7|   8|   9|  10|  11|  12|  13|
  1713:   //   0|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1714:   //   1|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1715:   //   2|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1716:   //   3|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1717:   //   4|WWW |BBBB|BBB |BBBB|BBB |WWW |WWW |BBBB|BBB |BBBB|BBB |BBBB|BBB |WWW |
  1718:   //   5|WWW |    |    |    |    |WWW |WWW |    |    |    |    |    |    |WWW |
  1719:   //   6|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1720:   //   7|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1721:   //   8|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1722:   //   9|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1723:   //  10|WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |WWWW|WWW |
  1724:   //    |   0|   1|   2|   3|   4|   5|   6|   7|   8|   9|  10|  11|  12|  13|
  1725:   //    |   C|    |   D|    |   E|    |   F|    |   G|    |   A|    |   B|    |
  1726:   //    |   0|    |   2|    |   4|    |   5|    |   7|    |   9|    |  11|    |
  1727:   public static void smnPaintKey2 (int i, int k, int c1111a, int c1111b) {
  1728:     int c1111ab = c1111a & 0b11001100 | c1111b & 0b00110011;
  1729:     int c1111ba = c1111b & 0b11001100 | c1111a & 0b00110011;
  1730:     int c1110ab = c1111ab & 0b11111100;
  1731:     int c1110ba = c1111ba & 0b11111100;
  1732:     byte[] bb = smnBitmap;
  1733:     switch (k) {
  1734:     case 0:  //C
  1735:     case 5:  //F
  1736:       bb[       SMN_OFFSET *  6 + i] = (
  1737:         bb[     SMN_OFFSET *  8 + i] =
  1738:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111ab);
  1739:       bb[       SMN_OFFSET *  7 + i] = (
  1740:         bb[     SMN_OFFSET *  9 + i] = (byte) c1111ba);
  1741:       bb[                       + i] = (
  1742:         bb[     SMN_OFFSET *  2 + i] =
  1743:         bb[     SMN_OFFSET *  4 + i] =
  1744:         bb[ 1 + SMN_OFFSET *  6 + i] =
  1745:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1746:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
  1747:       bb[       SMN_OFFSET      + i] = (
  1748:         bb[     SMN_OFFSET *  3 + i] =
  1749:         bb[     SMN_OFFSET *  5 + i] =
  1750:         bb[ 1 + SMN_OFFSET *  7 + i] =
  1751:         bb[ 1 + SMN_OFFSET *  9 + i] = (byte) c1110ba);
  1752:       break;
  1753:     case 1:  //C#
  1754:     case 3:  //D#
  1755:     case 6:  //F#
  1756:     case 8:  //G#
  1757:     case 10:  //A#
  1758:       bb[                         i] = (
  1759:         bb[     SMN_OFFSET *  2 + i] =
  1760:         bb[     SMN_OFFSET *  4 + i] = (byte) c1111ab);
  1761:       bb[       SMN_OFFSET      + i] = (
  1762:         bb[     SMN_OFFSET *  3 + i] = (byte) c1111ba);
  1763:       bb[   1 +                 + i] = (
  1764:         bb[ 1 + SMN_OFFSET *  2 + i] =
  1765:         bb[ 1 + SMN_OFFSET *  4 + i] = (byte) c1110ab);
  1766:       bb[   1 + SMN_OFFSET      + i] = (
  1767:         bb[ 1 + SMN_OFFSET *  3 + i] = (byte) c1110ba);
  1768:       break;
  1769:     case 2:  //D
  1770:     case 7:  //G
  1771:     case 9:  //A
  1772:       bb[       SMN_OFFSET *  6 + i] = (
  1773:         bb[     SMN_OFFSET *  8 + i] =
  1774:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111ab);
  1775:       bb[       SMN_OFFSET *  7 + i] = (
  1776:         bb[     SMN_OFFSET *  9 + i] = (byte) c1111ba);
  1777:       bb[   1 + SMN_OFFSET *  6 + i] = (
  1778:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1779:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
  1780:       bb[   1 + SMN_OFFSET *  7 + i] = (
  1781:         bb[ 1 + SMN_OFFSET *  9 + i] = (byte) c1110ba);
  1782:       break;
  1783:     case 4:  //E
  1784:     case 11:  //B
  1785:       bb[       SMN_OFFSET *  6 + i] = (
  1786:         bb[     SMN_OFFSET *  8 + i] =
  1787:         bb[     SMN_OFFSET * 10 + i] = (byte) c1111ab);
  1788:       bb[       SMN_OFFSET *  7 + i] = (
  1789:         bb[     SMN_OFFSET *  9 + i] = (byte) c1111ba);
  1790:       bb[   1 +                 + i] = (
  1791:         bb[ 1 + SMN_OFFSET *  2 + i] =
  1792:         bb[ 1 + SMN_OFFSET *  4 + i] =
  1793:         bb[ 1 + SMN_OFFSET *  6 + i] =
  1794:         bb[ 1 + SMN_OFFSET *  8 + i] =
  1795:         bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
  1796:       bb[   1 + SMN_OFFSET      + i] = (
  1797:         bb[ 1 + SMN_OFFSET *  3 + i] =
  1798:         bb[ 1 + SMN_OFFSET *  5 + i] =
  1799:         bb[ 1 + SMN_OFFSET *  7 + i] =
  1800:         bb[ 1 + SMN_OFFSET *  9 + i] = (byte) c1110ba);
  1801:       break;
  1802:     }  //switch k
  1803:   }  //smnPaintKey2(int,int,int,int)
  1804: 
  1805:   //smnDrawIcon1 (x, y, c)
  1806:   //  パレットコード1でアイコンを描く
  1807:   public static void smnDrawIcon1 (int x, int y, int c) {
  1808:     byte[] bb = smnBitmap;
  1809:     x += SMN_OFFSET * y;
  1810:     c *= 18;
  1811:     bb[                    + x] = SMN_ICON_1[c     ];
  1812:     bb[1                   + x] = SMN_ICON_1[c +  1];
  1813:     bb[    SMN_OFFSET      + x] = SMN_ICON_1[c +  2];
  1814:     bb[1 + SMN_OFFSET      + x] = SMN_ICON_1[c +  3];
  1815:     bb[    SMN_OFFSET *  2 + x] = SMN_ICON_1[c +  4];
  1816:     bb[1 + SMN_OFFSET *  2 + x] = SMN_ICON_1[c +  5];
  1817:     bb[    SMN_OFFSET *  3 + x] = SMN_ICON_1[c +  6];
  1818:     bb[1 + SMN_OFFSET *  3 + x] = SMN_ICON_1[c +  7];
  1819:     bb[    SMN_OFFSET *  4 + x] = SMN_ICON_1[c +  8];
  1820:     bb[1 + SMN_OFFSET *  4 + x] = SMN_ICON_1[c +  9];
  1821:     bb[    SMN_OFFSET *  5 + x] = SMN_ICON_1[c + 10];
  1822:     bb[1 + SMN_OFFSET *  5 + x] = SMN_ICON_1[c + 11];
  1823:     bb[    SMN_OFFSET *  6 + x] = SMN_ICON_1[c + 12];
  1824:     bb[1 + SMN_OFFSET *  6 + x] = SMN_ICON_1[c + 13];
  1825:     bb[    SMN_OFFSET *  7 + x] = SMN_ICON_1[c + 14];
  1826:     bb[1 + SMN_OFFSET *  7 + x] = SMN_ICON_1[c + 15];
  1827:     bb[    SMN_OFFSET *  8 + x] = SMN_ICON_1[c + 16];
  1828:     bb[1 + SMN_OFFSET *  8 + x] = SMN_ICON_1[c + 17];
  1829:   }  //smnDrawIcon1(int,int,int)
  1830: 
  1831:   //smnDrawIcon3 (x, y, c)
  1832:   //  パレットコード3でアイコンを描く
  1833:   public static void smnDrawIcon3 (int x, int y, int c) {
  1834:     byte[] bb = smnBitmap;
  1835:     x += SMN_OFFSET * y;
  1836:     c *= 18;
  1837:     bb[                    + x] = SMN_ICON_3[c     ];
  1838:     bb[1                   + x] = SMN_ICON_3[c +  1];
  1839:     bb[    SMN_OFFSET      + x] = SMN_ICON_3[c +  2];
  1840:     bb[1 + SMN_OFFSET      + x] = SMN_ICON_3[c +  3];
  1841:     bb[    SMN_OFFSET *  2 + x] = SMN_ICON_3[c +  4];
  1842:     bb[1 + SMN_OFFSET *  2 + x] = SMN_ICON_3[c +  5];
  1843:     bb[    SMN_OFFSET *  3 + x] = SMN_ICON_3[c +  6];
  1844:     bb[1 + SMN_OFFSET *  3 + x] = SMN_ICON_3[c +  7];
  1845:     bb[    SMN_OFFSET *  4 + x] = SMN_ICON_3[c +  8];
  1846:     bb[1 + SMN_OFFSET *  4 + x] = SMN_ICON_3[c +  9];
  1847:     bb[    SMN_OFFSET *  5 + x] = SMN_ICON_3[c + 10];
  1848:     bb[1 + SMN_OFFSET *  5 + x] = SMN_ICON_3[c + 11];
  1849:     bb[    SMN_OFFSET *  6 + x] = SMN_ICON_3[c + 12];
  1850:     bb[1 + SMN_OFFSET *  6 + x] = SMN_ICON_3[c + 13];
  1851:     bb[    SMN_OFFSET *  7 + x] = SMN_ICON_3[c + 14];
  1852:     bb[1 + SMN_OFFSET *  7 + x] = SMN_ICON_3[c + 15];
  1853:     bb[    SMN_OFFSET *  8 + x] = SMN_ICON_3[c + 16];
  1854:     bb[1 + SMN_OFFSET *  8 + x] = SMN_ICON_3[c + 17];
  1855:   }  //smnDrawIcon3(int,int,int)
  1856: 
  1857:   //smnDrawChar1 (x, y, c)
  1858:   //  パレットコード1で文字を描く
  1859:   public static void smnDrawChar1 (int x, int y, int c) {
  1860:     byte[] bb = smnBitmap;
  1861:     x += SMN_OFFSET * y;
  1862:     c *= 5;
  1863:     bb[x                 ] = SMN_FONT_1[c    ];
  1864:     bb[x + SMN_OFFSET    ] = SMN_FONT_1[c + 1];
  1865:     bb[x + SMN_OFFSET * 2] = SMN_FONT_1[c + 2];
  1866:     bb[x + SMN_OFFSET * 3] = SMN_FONT_1[c + 3];
  1867:     bb[x + SMN_OFFSET * 4] = SMN_FONT_1[c + 4];
  1868:   }  //smnDrawChar1(int,int,int)
  1869: 
  1870:   //smnDrawChar2 (x, y, c)
  1871:   //  パレットコード2で文字を描く
  1872:   public static void smnDrawChar2 (int x, int y, int c) {
  1873:     byte[] bb = smnBitmap;
  1874:     x += SMN_OFFSET * y;
  1875:     c *= 5;
  1876:     bb[x                 ] = SMN_FONT_2[c    ];
  1877:     bb[x + SMN_OFFSET    ] = SMN_FONT_2[c + 1];
  1878:     bb[x + SMN_OFFSET * 2] = SMN_FONT_2[c + 2];
  1879:     bb[x + SMN_OFFSET * 3] = SMN_FONT_2[c + 3];
  1880:     bb[x + SMN_OFFSET * 4] = SMN_FONT_2[c + 4];
  1881:   }  //smnDrawChar2(int,int,int)
  1882: 
  1883:   //smnDrawChar3 (x, y, c)
  1884:   //  パレットコード3で文字を描く
  1885:   public static void smnDrawChar3 (int x, int y, int c) {
  1886:     byte[] bb = smnBitmap;
  1887:     x += SMN_OFFSET * y;
  1888:     c *= 5;
  1889:     bb[x                 ] = SMN_FONT_3[c    ];
  1890:     bb[x + SMN_OFFSET    ] = SMN_FONT_3[c + 1];
  1891:     bb[x + SMN_OFFSET * 2] = SMN_FONT_3[c + 2];
  1892:     bb[x + SMN_OFFSET * 3] = SMN_FONT_3[c + 3];
  1893:     bb[x + SMN_OFFSET * 4] = SMN_FONT_3[c + 4];
  1894:   }  //smnDrawChar3(int,int,int)
  1895: 
  1896:   //smnDrawString1 (x, y, s)
  1897:   //  パレットコード1で文字列を描く
  1898:   public static void smnDrawString1 (int x, int y, String s) {
  1899:     smnDrawString1 (x, y, s.toCharArray ());
  1900:   }  //smnDrawString1(int,int,String)
  1901:   public static void smnDrawString1 (int x, int y, char[] s) {
  1902:     byte[] bb = smnBitmap;
  1903:     x += SMN_OFFSET * y;
  1904:     for (char c : s) {
  1905:       c *= 5;
  1906:       bb[x                 ] = SMN_FONT_1[c    ];
  1907:       bb[x + SMN_OFFSET    ] = SMN_FONT_1[c + 1];
  1908:       bb[x + SMN_OFFSET * 2] = SMN_FONT_1[c + 2];
  1909:       bb[x + SMN_OFFSET * 3] = SMN_FONT_1[c + 3];
  1910:       bb[x + SMN_OFFSET * 4] = SMN_FONT_1[c + 4];
  1911:       x++;
  1912:     }
  1913:   }  //smnDrawString1(int,int,char[])
  1914: 
  1915:   //smnDrawString2 (x, y, s)
  1916:   //  パレットコード2で文字列を描く
  1917:   public static void smnDrawString2 (int x, int y, String s) {
  1918:     smnDrawString2 (x, y, s.toCharArray ());
  1919:   }  //smnDrawString2(int,int,String)
  1920:   public static void smnDrawString2 (int x, int y, char[] s) {
  1921:     byte[] bb = smnBitmap;
  1922:     x += SMN_OFFSET * y;
  1923:     for (char c : s) {
  1924:       c *= 5;
  1925:       bb[x                 ] = SMN_FONT_2[c    ];
  1926:       bb[x + SMN_OFFSET    ] = SMN_FONT_2[c + 1];
  1927:       bb[x + SMN_OFFSET * 2] = SMN_FONT_2[c + 2];
  1928:       bb[x + SMN_OFFSET * 3] = SMN_FONT_2[c + 3];
  1929:       bb[x + SMN_OFFSET * 4] = SMN_FONT_2[c + 4];
  1930:       x++;
  1931:     }
  1932:   }  //smnDrawString2(int,int,char[])
  1933: 
  1934:   //smnDrawString3 (x, y, s)
  1935:   //  パレットコード3で文字列を描く
  1936:   public static void smnDrawString3 (int x, int y, String s) {
  1937:     smnDrawString3 (x, y, s.toCharArray ());
  1938:   }  //smnDrawString3(int,int,String)
  1939:   public static void smnDrawString3 (int x, int y, char[] s) {
  1940:     byte[] bb = smnBitmap;
  1941:     x += SMN_OFFSET * y;
  1942:     for (char c : s) {
  1943:       c *= 5;
  1944:       bb[x                 ] = SMN_FONT_3[c    ];
  1945:       bb[x + SMN_OFFSET    ] = SMN_FONT_3[c + 1];
  1946:       bb[x + SMN_OFFSET * 2] = SMN_FONT_3[c + 2];
  1947:       bb[x + SMN_OFFSET * 3] = SMN_FONT_3[c + 3];
  1948:       bb[x + SMN_OFFSET * 4] = SMN_FONT_3[c + 4];
  1949:       x++;
  1950:     }
  1951:   }  //smnDrawString3(int,int,char[])
  1952: 
  1953:   //smnDrawSlider (slider, pattern)
  1954:   //  スライダを描く
  1955:   //  slider[0]  x0。4の倍数
  1956:   //  slider[1]  y0
  1957:   //  slider[2]  max。4の倍数
  1958:   //  slider[3]  palet
  1959:   //  slider[4]  value。0<=value<=max
  1960:   //  width=max+4
  1961:   //  height=5
  1962:   public static void smnDrawSlider (int[] slider, int[] pattern) {
  1963:     byte[] bb = smnBitmap;
  1964:     int x0 = slider[0];
  1965:     int y0 = slider[1];
  1966:     int max = slider[2];
  1967:     int palet = slider[3];
  1968:     int value = slider[4];
  1969:     int width = max + 4;
  1970:     for (int i = (x0 >> 2) + SMN_OFFSET * y0, l = i + (width >> 2); i < l; i++) {
  1971:       bb[  i                 ] = (
  1972:         bb[i + SMN_OFFSET * 1] =
  1973:         bb[i + SMN_OFFSET * 3] =
  1974:         bb[i + SMN_OFFSET * 4] = SMN_BLACK);
  1975:       bb[  i + SMN_OFFSET * 2] = (byte) palet;
  1976:     }
  1977:     smnDrawPattern (x0 + value, y0 + 2, pattern);
  1978:   }  //smnDrawSlider(int[],int[])
  1979: 
  1980:   //smnDrawPattern (x0, y0, pattern)
  1981:   //  パターンを描く
  1982:   //  pattern={n0,palet,u0,v0,u1,v1,...,n1,palet,...}
  1983:   //           <-----------n0---------->
  1984:   public static void smnDrawPattern (int x0, int y0, int[] pattern) {
  1985:     byte[] bb = smnBitmap;
  1986:     for (int k = 0; k < pattern.length; ) {
  1987:       int limit = k + pattern[k];
  1988:       int palet = pattern[k + 1] & 3;
  1989:       for (k += 2; k < limit; k += 2) {
  1990:         int x = x0 + pattern[k];
  1991:         int y = y0 + pattern[k + 1];
  1992:         int b = (~x & 3) << 1;  //0→6,1→4,2→2,3→0
  1993:         int i = SMN_OFFSET * y + (x >> 2);
  1994:         bb[i] = (byte) (bb[i] & ~(3 << b) | palet << b);
  1995:       }
  1996:     }
  1997:   }  //smnDrawPattern(int,int,int[])
  1998: 
  1999: }  //class SoundMonitor
  2000: 
  2001: 
  2002: