ref: 507bafb3b252316cb94677498d5d81d9f5c92924
parent: ecc9f758b68d9fc00b150dae0f04248590debe2e
parent: a43b458e676b7ee6d9a174770bfdd8e1be4e5a65
author: Cucky <44537737+cuckydev@users.noreply.github.com>
date: Sun Feb 10 05:06:34 EST 2019
Merge pull request #49 from Clownacy/master New PixTone.cpp
--- a/src/GenericLoad.cpp
+++ b/src/GenericLoad.cpp
@@ -4,6 +4,149 @@
#include "PixTone.h"
#include "Ending.h"
+static const PIXTONEPARAMETER gPtpTable[139] =
+{
+ {1, 5000, {5, 10.0, 32, 0}, {4, 4.0, 32, 0}, {0, 0.0, 63, 0}, 63, 6, 63, 45, 8, 119, 46},
+ {1, 1000, {0, 4.0, 32, 0}, {3, 1.0, 63, 0}, {0, 0.0, 63, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 10000, {0, 30.0, 32, 0}, {3, 1.0, 32, 0}, {0, 0.0, 63, 0}, 0, 19, 44, 111, 13, 198, 9},
+ {1, 10000, {5, 2.0, 31, 0}, {3, 1.0, 57, 219}, {0, 2.0, 32, 0}, 0, 19, 44, 111, 13, 198, 9},
+ {1, 4000, {5, 0.4, 32, 0}, {3, 1.0, 53, 0}, {0, 0.0, 63, 0}, 12, 19, 63, 111, 21, 198, 18},
+ {1, 1000, {1, 12.0, 32, 0}, {2, 1.0, 63, 0}, {0, 0.0, 63, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 1000, {5, 1.0, 32, 0}, {3, 1.0, 63, 0}, {0, 0.0, 63, 0}, 0, 28, 63, 53, 31, 210, 31},
+ {1, 1000, {1, 5.0, 32, 0}, {3, 1.0, 63, 0}, {0, 0.0, 0, 0}, 63, 64, 63, 128, 31, 255, 0},
+ {1, 3000, {1, 17.0, 34, 0}, {3, 2.0, 40, 0}, {4, 1.0, 31, 0}, 63, 64, 63, 225, 63, 255, 0},
+ {1, 6000, {1, 930.0, 22, 0}, {0, 0.7, 53, 0}, {0, 7.0, 32, 0}, 63, 64, 63, 202, 63, 255, 0},
+ {1, 6000, {1, 918.0, 23, 0}, {0, 0.7, 53, 0}, {0, 7.0, 32, 0}, 63, 64, 63, 202, 63, 255, 0},
+ {1, 10000, {2, 200.0, 32, 0}, {0, 1.0, 51, 0}, {1, 20.0, 31, 0}, 63, 64, 63, 89, 30, 208, 28},
+ {1, 10000, {5, 23.0, 16, 0}, {0, 1.0, 58, 0}, {1, 17.0, 32, 0}, 63, 64, 63, 96, 51, 202, 31},
+ {1, 20000, {2, 100.0, 21, 0}, {0, 1.0, 46, 0}, {1, 40.0, 32, 0}, 63, 64, 63, 128, 63, 162, 0},
+ {1, 20000, {5, 5.0, 21, 0}, {0, 1.0, 51, 0}, {1, 40.0, 32, 0}, 63, 64, 63, 128, 63, 162, 28},
+ {1, 10000, {5, 20.0, 23, 0}, {3, 0.7, 26, 235}, {5, 1.0, 9, 0}, 63, 38, 55, 87, 32, 98, 29},
+ {1, 2000, {1, 20.0, 32, 0}, {3, 2.0, 63, 0}, {4, 1.0, 29, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 15000, {5, 10.0, 32, 0}, {3, 0.7, 26, 235}, {0, 0.0, 63, 0}, 63, 38, 55, 187, 15, 255, 0},
+ {1, 4000, {1, 20.0, 32, 0}, {3, 2.0, 63, 0}, {4, 1.0, 29, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 22000, {5, 6.0, 32, 0}, {3, 0.7, 26, 246}, {0, 0.0, 63, 0}, 63, 38, 55, 187, 15, 255, 0},
+ {1, 8000, {0, 20.0, 32, 0}, {3, 2.0, 63, 0}, {4, 1.0, 29, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 10000, {4, 400.0, 13, 0}, {0, 0.8, 63, 0}, {4, 8.0, 31, 0}, 63, 64, 63, 191, 32, 255, 0},
+ {1, 10000, {4, 800.0, 14, 0}, {0, 0.8, 63, 0}, {4, 8.0, 30, 125}, 63, 64, 63, 128, 63, 166, 0},
+ {1, 5000, {2, 50.0, 39, 0}, {3, 0.5, 40, 217}, {1, 0.0, 32, 0}, 63, 64, 63, 128, 34, 198, 32},
+ {1, 5000, {5, 10.0, 39, 0}, {3, 0.5, 24, 217}, {1, 4.0, 32, 0}, 0, 4, 63, 128, 34, 198, 32},
+ {1, 40000, {5, 10.0, 32, 0}, {3, 1.0, 32, 241}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 40000, {5, 20.0, 32, 0}, {0, 0.0, 32, 0}, {5, 0.1, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 30000, {2, 400.0, 32, 0}, {3, 0.3, 60, 250}, {0, 20.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 10000, {4, 400.0, 13, 0}, {0, 0.8, 63, 0}, {4, 8.0, 50, 0}, 63, 64, 63, 191, 32, 255, 0},
+ {1, 10000, {4, 800.0, 5, 0}, {0, 0.8, 63, 0}, {4, 8.0, 63, 125}, 63, 64, 63, 128, 63, 166, 0},
+ {1, 6000, {3, 123.0, 32, 0}, {4, 1.0, 16, 222}, {4, 4.0, 37, 0}, 0, 6, 63, 104, 25, 255, 0},
+ {1, 4000, {5, 4.5, 32, 0}, {3, 1.0, 46, 102}, {3, 2.5, 47, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 5000, {4, 40.0, 52, 0}, {2, 1.0, 63, 0}, {3, 10.0, 63, 0}, 63, 47, 27, 47, 29, 255, 0},
+ {1, 3000, {0, 99.0, 32, 0}, {2, 1.0, 55, 197}, {5, 0.0, 0, 0}, 63, 0, 63, 164, 28, 255, 0},
+ {1, 10000, {1, 601.0, 32, 0}, {4, 0.5, 15, 235}, {0, 10.0, 54, 0}, 63, 0, 63, 0, 63, 255, 0},
+ {1, 8000, {5, 10.0, 15, 0}, {4, 0.5, 16, 239}, {4, 0.0, 50, 0}, 63, 0, 63, 96, 17, 255, 0},
+ {1, 20000, {1, 832.0, 32, 0}, {2, 1.0, 46, 0}, {0, 27.0, 63, 0}, 63, 0, 63, 140, 10, 255, 0},
+ {1, 20000, {1, 918.0, 32, 0}, {2, 1.0, 46, 0}, {0, 21.0, 63, 0}, 63, 0, 63, 140, 10, 255, 0},
+ {1, 4000, {1, 54.0, 32, 0}, {5, 0.1, 33, 0}, {0, 0.0, 32, 0}, 53, 57, 44, 128, 24, 255, 0},
+ {1, 10000, {1, 246.0, 23, 0}, {4, 0.6, 22, 239}, {4, 6.0, 63, 0}, 0, 11, 63, 13, 63, 255, 0},
+ {1, 10000, {1, 294.0, 23, 0}, {4, 0.6, 22, 247}, {4, 6.0, 63, 140}, 0, 15, 63, 17, 63, 255, 0},
+ {1, 22050, {0, 117.0, 63, 0}, {5, 2.0, 18, 0}, {5, 0.0, 0, 0}, 63, 0, 63, 64, 19, 255, 0},
+ {1, 5000, {0, 28.0, 32, 0}, {3, 3.0, 27, 0}, {5, 0.0, 0, 0}, 63, 0, 63, 0, 63, 255, 0},
+ {1, 10000, {0, 322.0, 32, 0}, {2, 8.0, 37, 0}, {2, 0.0, 0, 0}, 0, 13, 63, 106, 11, 255, 0},
+ {1, 10000, {5, 7.3, 32, 0}, {5, 0.2, 29, 0}, {0, 0.0, 32, 0}, 63, 91, 63, 149, 25, 255, 0},
+ {1, 1000, {0, 6.0, 32, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 20000, {2, 186.0, 32, 0}, {0, 4.0, 13, 98}, {3, 4.0, 5, 0}, 63, 64, 28, 255, 0, 255, 0},
+ {1, 20000, {2, 285.0, 19, 0}, {3, 4.0, 21, 0}, {3, 4.0, 33, 130}, 63, 64, 63, 255, 0, 255, 0},
+ {1, 10000, {0, 970.0, 32, 0}, {2, 1.0, 35, 195}, {0, 31.0, 31, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 20000, {5, 6.0, 32, 0}, {3, 1.0, 54, 239}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 35},
+ {1, 40000, {5, 4.0, 32, 0}, {3, 0.0, 32, 230}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 40000, {1, 238.0, 32, 0}, {3, 1.0, 14, 0}, {4, 30.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 3000, {2, 62.0, 32, 0}, {2, 3.0, 63, 0}, {3, 3.0, 14, 0}, 63, 0, 63, 210, 32, 255, 0},
+ {1, 5000, {2, 58.0, 32, 0}, {2, 3.0, 63, 0}, {2, 3.0, 32, 0}, 63, 0, 63, 49, 27, 255, 0},
+ {1, 3000, {0, 13.0, 24, 0}, {3, 2.0, 40, 0}, {4, 1.0, 31, 0}, 63, 64, 63, 225, 63, 255, 0},
+ {1, 3000, {5, 6.0, 32, 0}, {5, 1.0, 32, 0}, {3, 0.0, 0, 0}, 0, 0, 63, 45, 23, 255, 0},
+ {1, 20000, {1, 477.0, 40, 0}, {5, 93.0, 39, 0}, {4, 17.0, 19, 0}, 0, 64, 63, 128, 63, 255, 0},
+ {1, 6000, {5, 11.0, 32, 0}, {5, 1.0, 32, 0}, {3, 3.0, 32, 0}, 63, 0, 63, 0, 63, 255, 0},
+ {1, 6000, {1, 329.0, 20, 0}, {2, 2.0, 47, 77}, {3, 3.0, 63, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 8000, {4, 2000.0, 32, 0}, {2, 1.0, 0, 0}, {0, 0.0, 32, 0}, 43, 21, 7, 255, 0, 255, 0},
+ {1, 5000, {1, 231.0, 32, 0}, {4, 1.0, 32, 65}, {3, 2.0, 32, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 3000, {0, 107.0, 32, 0}, {4, 1.0, 15, 0}, {0, 0.0, 17, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 20000, {5, 4.0, 32, 0}, {5, 1.0, 32, 170}, {5, 0.0, 32, 0}, 63, 38, 22, 255, 0, 255, 0},
+ {1, 5000, {1, 16.0, 32, 0}, {3, 1.0, 32, 238}, {0, 0.0, 0, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 20000, {5, 4.0, 32, 0}, {0, 0.7, 61, 43}, {3, 1.0, 22, 224}, 63, 64, 63, 204, 46, 255, 0},
+ {1, 5000, {0, 880.0, 19, 0}, {0, 0.0, 32, 0}, {0, 8.0, 32, 0}, 0, 11, 63, 34, 25, 255, 0},
+ {1, 2000, {5, 3.0, 16, 0}, {3, 2.0, 12, 0}, {3, 1.0, 37, 0}, 0, 51, 63, 132, 24, 255, 0},
+ {1, 22050, {1, 400.0, 32, 0}, {0, 20.0, 10, 0}, {3, 10.0, 8, 0}, 0, 6, 63, 60, 21, 255, 0},
+ {1, 2000, {5, 2.0, 32, 0}, {2, 3.0, 54, 0}, {0, 0.0, 32, 0}, 0, 17, 63, 98, 22, 255, 0},
+ {1, 8000, {1, 814.0, 32, 0}, {2, 11.0, 32, 0}, {3, 16.0, 32, 0}, 63, 23, 63, 74, 12, 255, 0},
+ {1, 10000, {5, 21.0, 21, 0}, {0, 5.0, 32, 178}, {0, 3.0, 33, 181}, 63, 38, 63, 104, 20, 255, 0},
+ {1, 6000, {5, 1.0, 28, 0}, {3, 6.0, 56, 0}, {0, 8.0, 32, 0}, 63, 57, 63, 98, 20, 255, 0},
+ {1, 4000, {5, 6.0, 32, 0}, {3, 2.0, 32, 0}, {3, 2.0, 32, 0}, 63, 26, 30, 66, 29, 255, 0},
+ {1, 22050, {5, 711.0, 32, 0}, {5, 7.0, 32, 0}, {0, 0.0, 32, 0}, 0, 13, 0, 17, 63, 255, 0},
+ {1, 2000, {5, 2.0, 32, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 62050, {5, 40.0, 32, 0}, {5, 1.0, 32, 0}, {5, 0.0, 0, 0}, 0, 17, 63, 36, 63, 255, 0},
+ {1, 8000, {0, 77.0, 32, 0}, {3, 3.0, 56, 189}, {0, 0.0, 17, 0}, 0, 38, 63, 140, 28, 255, 0},
+ {1, 8000, {5, 8.0, 32, 0}, {3, 3.0, 54, 189}, {3, 3.0, 32, 0}, 63, 38, 42, 140, 21, 255, 0},
+ {1, 9050, {5, 9.0, 26, 0}, {0, 1.0, 32, 209}, {0, 0.0, 32, 0}, 63, 64, 63, 132, 63, 255, 0},
+ {1, 9050, {2, 43.0, 32, 0}, {3, 1.0, 47, 172}, {0, 0.0, 32, 0}, 63, 64, 63, 198, 63, 255, 0},
+ {1, 22050, {1, 754.0, 32, 0}, {2, 0.5, 14, 126}, {4, 18.0, 17, 0}, 0, 64, 63, 128, 63, 255, 0},
+ {1, 22050, {0, 597.0, 12, 0}, {2, 0.5, 14, 126}, {4, 18.0, 17, 0}, 0, 64, 40, 128, 41, 255, 0},
+ {1, 6000, {2, 217.0, 32, 0}, {0, 0.7, 16, 0}, {3, 0.0, 32, 0}, 0, 32, 63, 49, 15, 255, 0},
+ {1, 5000, {5, 1.0, 32, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 0, 64, 63, 81, 28, 255, 0},
+ {1, 10000, {5, 11.0, 32, 0}, {2, 4.0, 32, 0}, {0, 3.0, 32, 0}, 0, 64, 63, 128, 30, 255, 0},
+ {1, 10000, {5, 1.0, 32, 0}, {4, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 32, 128, 33, 255, 0},
+ {1, 10000, {2, 168.0, 32, 0}, {0, 0.5, 29, 173}, {0, 0.0, 32, 0}, 0, 13, 63, 68, 35, 255, 0},
+ {1, 10000, {2, 50.0, 32, 0}, {0, 0.5, 29, 173}, {2, 100.0, 32, 0}, 0, 13, 63, 68, 35, 255, 0},
+ {1, 4000, {5, 11.0, 25, 0}, {3, 3.0, 32, 0}, {0, 0.0, 32, 0}, 0, 9, 63, 128, 14, 255, 0},
+ {1, 4000, {5, 3.0, 27, 0}, {3, 3.0, 32, 0}, {0, 0.0, 32, 0}, 0, 9, 63, 128, 14, 255, 0},
+ {1, 3000, {4, 9.0, 20, 0}, {3, 3.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 3000, {4, 18.0, 20, 0}, {3, 3.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 0},
+ {1, 3000, {5, 4.0, 32, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 0, 64, 63, 128, 63, 255, 0},
+ {1, 12000, {5, 2.0, 32, 0}, {3, 1.7, 53, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 162, 25, 255, 0},
+ {1, 12000, {3, 77.0, 32, 0}, {3, 1.0, 61, 200}, {0, 19.0, 22, 0}, 63, 64, 63, 172, 25, 255, 0},
+ {1, 5000, {0, 16.0, 63, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 166, 35, 255, 0},
+ {1, 1000, {5, 1.0, 16, 0}, {0, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 91, 28, 255, 0},
+ {1, 5000, {0, 20.0, 30, 0}, {3, 1.0, 44, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 111, 19, 255, 0},
+ {1, 10000, {5, 14.0, 41, 0}, {5, 3.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 18, 91, 12, 255, 0},
+ {1, 1000, {5, 48.0, 30, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 166, 27, 255, 0},
+ {1, 10000, {5, 48.0, 30, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 43, 166, 41, 255, 7},
+ {1, 4000, {5, 35.0, 30, 0}, {3, 35.0, 32, 0}, {0, 0.0, 32, 0}, 63, 53, 21, 166, 13, 255, 0},
+ {1, 10000, {1, 63.0, 32, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 39, 91, 20, 255, 0},
+ {1, 22050, {5, 52.0, 22, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 3, 23, 23, 57, 10, 255, 0},
+ {1, 22050, {5, 80.0, 22, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 23, 23, 57, 10, 255, 0},
+ {1, 44100, {5, 54.0, 12, 0}, {5, 1.0, 32, 0}, {5, 1.0, 27, 0}, 40, 64, 63, 128, 38, 255, 63},
+ {1, 44100, {5, 119.0, 9, 0}, {5, 2.0, 32, 0}, {0, 0.0, 32, 0}, 61, 64, 39, 128, 60, 255, 28},
+ {1, 4000, {5, 11.0, 32, 0}, {5, 1.0, 17, 197}, {0, 0.0, 32, 0}, 51, 100, 63, 100, 0, 255, 0},
+ {1, 4000, {5, 21.0, 32, 0}, {5, 1.0, 17, 197}, {0, 0.0, 32, 0}, 0, 119, 0, 117, 63, 255, 0},
+ {1, 5000, {2, 143.0, 25, 0}, {3, 0.5, 40, 217}, {1, 0.0, 32, 0}, 63, 64, 63, 128, 34, 198, 32},
+ {1, 5000, {5, 10.0, 23, 0}, {3, 0.5, 24, 217}, {1, 4.0, 32, 0}, 0, 4, 63, 128, 34, 198, 32},
+ {1, 4000, {5, 6.0, 32, 0}, {3, 2.0, 32, 0}, {3, 2.0, 32, 0}, 63, 26, 30, 66, 29, 255, 0},
+ {1, 4000, {0, 150.0, 32, 0}, {0, 0.0, 32, 0}, {3, 2.0, 32, 0}, 63, 26, 30, 66, 29, 255, 0},
+ {1, 40050, {4, 100.0, 32, 0}, {3, 8.0, 22, 0}, {3, 8.0, 8, 0}, 63, 28, 44, 81, 23, 255, 0},
+ {1, 40050, {4, 150.0, 32, 0}, {3, 8.0, 22, 0}, {3, 8.0, 8, 0}, 63, 28, 44, 81, 23, 255, 0},
+ {1, 40050, {4, 294.0, 32, 0}, {3, 8.0, 22, 0}, {3, 8.0, 8, 0}, 63, 28, 44, 81, 23, 255, 0},
+ {1, 5000, {3, 621.0, 32, 0}, {2, 2.0, 22, 0}, {3, 6.0, 32, 0}, 0, 4, 63, 77, 30, 255, 0},
+ {1, 30000, {5, 28.0, 44, 0}, {3, 1.0, 45, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 208, 63, 255, 0},
+ {1, 30000, {2, 101.0, 44, 0}, {2, 0.5, 63, 118}, {0, 0.0, 32, 0}, 63, 64, 63, 176, 63, 255, 0},
+ {1, 30000, {2, 86.0, 44, 0}, {2, 0.5, 63, 118}, {0, 0.0, 32, 0}, 63, 64, 63, 176, 63, 255, 0},
+ {1, 2000, {5, 1.0, 32, 0}, {0, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 2000, {3, 99.0, 12, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 63, 64, 63, 128, 63, 255, 63},
+ {1, 6000, {3, 388.0, 22, 0}, {0, 0.7, 53, 0}, {0, 7.0, 32, 0}, 25, 64, 63, 202, 63, 255, 0},
+ {1, 6000, {1, 918.0, 23, 0}, {0, 0.7, 53, 0}, {0, 7.0, 32, 0}, 63, 64, 63, 202, 63, 255, 0},
+ {1, 10000, {5, 118.0, 19, 0}, {3, 1.0, 63, 0}, {0, 3.0, 32, 0}, 0, 19, 63, 66, 41, 255, 0},
+ {1, 10000, {5, 6.0, 24, 0}, {3, 1.0, 32, 208}, {2, 8.0, 12, 0}, 63, 64, 63, 128, 38, 255, 0},
+ {1, 400, {1, 20.0, 12, 0}, {0, 0.0, 32, 0}, {0, 0.0, 32, 0}, 0, 43, 63, 193, 63, 255, 0},
+ {1, 400, {1, 30.0, 12, 0}, {0, 0.0, 32, 0}, {0, 0.0, 32, 0}, 0, 43, 63, 193, 63, 255, 0},
+ {1, 400, {1, 40.0, 12, 0}, {0, 0.0, 32, 0}, {0, 0.0, 32, 0}, 0, 43, 63, 193, 63, 255, 0},
+ {1, 8000, {3, 800.0, 24, 0}, {0, 8.0, 4, 0}, {0, 0.0, 32, 0}, 0, 13, 63, 138, 63, 255, 0},
+ {1, 8000, {5, 53.0, 12, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 0, 0, 63, 68, 63, 255, 0},
+ {1, 8000, {3, 400.0, 24, 0}, {0, 8.0, 4, 0}, {0, 0.0, 32, 0}, 0, 13, 63, 138, 63, 255, 0},
+ {1, 8000, {5, 53.0, 12, 0}, {5, 1.0, 32, 0}, {0, 0.0, 32, 0}, 0, 0, 63, 68, 63, 255, 0},
+ {1, 8000, {3, 200.0, 32, 0}, {0, 8.0, 4, 0}, {0, 0.0, 32, 0}, 0, 13, 63, 138, 63, 255, 0},
+ {1, 8000, {5, 25.0, 17, 0}, {3, 1.0, 32, 0}, {0, 0.0, 32, 0}, 0, 0, 63, 68, 63, 255, 0},
+ {1, 8000, {4, 800.0, 32, 0}, {4, 2.0, 21, 0}, {4, 8.0, 32, 0}, 0, 106, 63, 130, 27, 255, 0},
+ {1, 3000, {4, 31.0, 10, 0}, {3, 2.0, 40, 0}, {4, 1.0, 31, 0}, 0, 9, 63, 94, 63, 255, 0},
+ {1, 5000, {2, 168.0, 32, 0}, {0, 0.5, 29, 173}, {0, 0.0, 32, 0}, 0, 13, 63, 68, 35, 255, 0},
+ {1, 1000, {0, 20.0, 0, 0}, {0, 0.0, 0, 0}, {0, 0.0, 0, 0}, 0, 64, 0, 128, 0, 255, 0}
+};
+
bool LoadGenericData()
{
MakeSurface_Resource("PIXEL", 1);
@@ -54,34 +197,95 @@
MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1);
MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2);
MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST);
-
- char path[0x100];
- uint8_t *buf = nullptr;
- size_t len;
-
- for (unsigned int n = 0; n < SOUND_NO; n++)
- {
- sprintf(path, "%2.2X.pxt", n);
-
- if (LoadPxt(path, &buf, &len))
- {
- lpSECONDARYBUFFER[n] = new SOUNDBUFFER(len);
-
- uint8_t *sBuf;
- size_t sLen;
- lpSECONDARYBUFFER[n]->Lock(&sBuf, &sLen);
- memcpy(sBuf, buf, sLen);
- lpSECONDARYBUFFER[n]->Unlock();
- lpSECONDARYBUFFER[n]->SetFrequency(22050);
- }
-
- //Free buffer, we're done with it
- if (buf)
- {
- free(buf);
- buf = nullptr;
- }
- }
+
+ size_t pixtone_bytes = MakePixToneObject(&gPtpTable[0], 2, 32);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[2], 2, 33);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[4], 2, 34);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[6], 1, 15);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[7], 1, 24);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[8], 1, 23);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[9], 2, 50);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[11], 2, 51);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[33], 1, 1);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[38], 1, 2);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[56], 1, 29);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[61], 1, 43);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[62], 3, 44);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[65], 1, 45);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[66], 1, 46);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[68], 1, 47);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[49], 3, 35);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[52], 3, 39);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[13], 2, 52);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[28], 2, 53);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[15], 2, 70);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[17], 2, 71);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[19], 2, 72);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[30], 1, 5);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[32], 1, 11);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[35], 1, 4);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[46], 2, 25);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[48], 1, 27);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[54], 2, 28);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[39], 1, 14);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[23], 2, 16);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[25], 3, 17);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[34], 1, 18);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[36], 2, 20);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[31], 1, 22);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[41], 2, 26);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[43], 1, 21);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[44], 2, 12);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[57], 2, 38);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[59], 1, 31);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[60], 1, 42);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[69], 1, 48);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[70], 2, 49);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[72], 1, 100);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[73], 3, 101);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[76], 2, 54);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[78], 2, 102);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[80], 2, 103);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[81], 1, 104);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[82], 1, 105);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[83], 2, 106);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[85], 1, 107);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[86], 1, 30);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[87], 1, 108);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[88], 1, 109);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[89], 1, 110);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[90], 1, 111);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[91], 1, 112);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[92], 1, 113);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[93], 2, 114);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[95], 2, 150);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[97], 2, 151);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[99], 1, 152);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[100], 1, 153);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[101], 2, 154);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[111], 2, 155);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[103], 2, 56);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[105], 2, 40);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[105], 2, 41);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[107], 2, 37);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[109], 2, 57);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[113], 3, 115);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[116], 1, 104);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[117], 3, 116);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[120], 2, 58);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[122], 2, 55);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[124], 2, 117);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[126], 1, 59);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[127], 1, 60);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[128], 1, 61);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[129], 2, 62);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[131], 2, 63);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[133], 2, 64);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[135], 1, 65);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[136], 1, 3);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[137], 1, 6);
+ pixtone_bytes += MakePixToneObject(&gPtpTable[138], 1, 7);
+// sprintf(&v1, "PixTone = %d byte", pixtone_bytes);
return true;
}
}
--- a/src/PixTone.cpp
+++ b/src/PixTone.cpp
@@ -1,298 +1,153 @@
-#include <cstdio>
-#include <cstdlib>
-#include <stdint.h>
-#include <vector>
-#include <cstring>
+#include "PixTone.h"
+
#include <math.h>
+#include <stdlib.h>
+#include <string.h>
#include "WindowsWrapper.h"
-#include "CommonDefines.h"
-#include "Tags.h"
-#include "PixTone.h"
+static char gWaveModelTable[6][256];
-int8_t gWaveModelTable[6][0x100];
-bool wave_tables_made;
-
-void MakeWaveTables()
+void MakeWaveTables(void)
{
- /* Sine wave */
- for (int i = 0; i < 0x100; i++)
+ int i, a;
+
+ // Sine wave
+ for (i = 0; i < 256; ++i)
+ {
gWaveModelTable[0][i] = (sin(i * 6.283184 / 256.0) * 64.0);
-
- /* Triangle wave */
- int triangle = 0;
- for (int i = 0; i < 0x40; ++i) //Upwards
- gWaveModelTable[1][i] = (triangle++ << 6) / 0x40;
- triangle = 0;
- for (int i = 0x40; i < 0xC0; ++i) //Downwards
- gWaveModelTable[1][i] = 0x40 - (triangle++ << 6) / 0x40;
- triangle = 0;
- for (int i = 0xC0; i < 0x100; ++i) //Back upwards
- gWaveModelTable[1][i] = (triangle++ << 6) / 0x40 - 0x40;
-
- /* Saw up wave */
- for (int i = 0; i < 0x100; i++)
+ a = gWaveModelTable[0][i];
+ }
+
+ // Triangle wave
+ for (a = 0, i = 0; i < 0x40; ++i)
+ {
+ // Upwards
+ gWaveModelTable[1][i] = (a * 0x40) / 0x40;
+ ++a;
+ }
+ for (a = 0; i < 0xC0; ++i)
+ {
+ // Downwards
+ gWaveModelTable[1][i] = 0x40 - (a * 0x40) / 0x40;
+ ++a;
+ }
+ for (a = 0; i < 0x100; ++i)
+ {
+ // Back up
+ gWaveModelTable[1][i] = (a * 0x40) / 0x40 - 0x40;
+ ++a;
+ }
+
+ // Saw up wave
+ for (i = 0; i < 0x100; ++i)
gWaveModelTable[2][i] = i / 2 - 0x40;
- /* Saw down wave */
- for (int i = 0; i < 0x100; i++)
+ // Saw down wave
+ for (i = 0; i < 0x100; ++i)
gWaveModelTable[3][i] = 0x40 - i / 2;
- /* Square wave */
- for (int i = 0; i < 0x80; i++)
+ // Square wave
+ for (i = 0; i < 0x80; ++i)
gWaveModelTable[4][i] = 0x40;
- for (int i = 0x80; i < 0x100; i++)
+ for (; i < 0x100; ++i)
gWaveModelTable[4][i] = -0x40;
- /* White noise wave */
- rep_srand(0);
- for (int i = 0; i < 0x100; i++)
- gWaveModelTable[5][i] = (int8_t)rep_rand() / 2;
+ // White noise wave
+ srand(0);
+ for (i = 0; i < 256; ++i)
+ gWaveModelTable[5][i] = (char)(rep_rand() & 0xFF) / 2;
}
-//Loading .pxt files
-double fgetv(FILE *fp) // Load a numeric value from text file; one per line.
+BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData)
{
- //Create buffer
- char Buf[0x1000];
- Buf[0xFFF] = '\0';
- char *p = Buf;
-
- if (!std::fgets(Buf, sizeof(Buf) - 1, fp))
- return 0.0;
-
- // Ignore empty lines. If the line was empty, try next line.
- if (!Buf[0] || Buf[0] == '\r' || Buf[0] == '\n')
- return fgetv(fp);
-
- while (*p && *p++ != ':')
- {
- }
-
- return std::strtod(p, 0); // Parse the value and return it.
-}
+ // The Linux port added a cute optimisation here, where MakeWaveTables is only called once during the game's execution
+ MakeWaveTables();
-bool MakePixelWaveData(const std::vector<double>& pxtData, uint8_t *data)
-{
- //Make wave tables if not created already
- if (!wave_tables_made)
- {
- MakeWaveTables();
- wave_tables_made = true;
- }
-
- //Get some envelope stuff
char envelopeTable[0x100];
- memset(envelopeTable, 0, sizeof(envelopeTable));
+ memset(envelopeTable, 0, 0x100);
- size_t i = 0;
+ int i = 0;
+ double dEnvelope;
- //Point A
- long double currentEnvelope = pxtData[14];
- while (i < pxtData[15])
+ dEnvelope = ptp->initial;
+ while (i < ptp->pointAx)
{
- envelopeTable[i] = (char)currentEnvelope;
- currentEnvelope = (pxtData[16] - pxtData[14])
- / pxtData[15]
- + currentEnvelope;
+ envelopeTable[i] = dEnvelope;
+ dEnvelope = ((double)ptp->pointAy - ptp->initial) / ptp->pointAx + dEnvelope;
++i;
}
- //Point B
- long double currentEnvelopea = pxtData[16];
- while (i < pxtData[17])
+ dEnvelope = ptp->pointAy;
+ while (i < ptp->pointBx)
{
- envelopeTable[i] = (char)currentEnvelopea;
- currentEnvelopea = (pxtData[18] - pxtData[16])
- / (pxtData[17] - pxtData[15])
- + currentEnvelopea;
+ envelopeTable[i] = dEnvelope;
+ dEnvelope = ((double)ptp->pointBy - ptp->pointAy) / (double)(ptp->pointBx - ptp->pointAx) + dEnvelope;
++i;
}
- //Point C
- long double currentEnvelopeb = pxtData[18];
- while (i < pxtData[19])
+ dEnvelope = ptp->pointBy;
+ while (i < ptp->pointCx)
{
- envelopeTable[i] = (char)currentEnvelopeb;
- currentEnvelopeb = (pxtData[20] - pxtData[18])
- / (pxtData[19] - pxtData[17])
- + currentEnvelopeb;
+ envelopeTable[i] = dEnvelope;
+ dEnvelope = ((double)ptp->pointCy - ptp->pointBy) / (double)(ptp->pointCx - ptp->pointBx) + dEnvelope;
++i;
}
- //End
- long double currentEnvelopec = pxtData[20];
- while (i < 0x100)
+ dEnvelope = ptp->pointCy;
+ while (i < 256)
{
- envelopeTable[i] = (char)currentEnvelopec;
- currentEnvelopec = currentEnvelopec
- - pxtData[20] / (0x100 - pxtData[19]);
+ envelopeTable[i] = dEnvelope;
+ dEnvelope = (double)dEnvelope - ptp->pointCy / (double)(256 - ptp->pointCx);
++i;
}
- long double pitchOffset = pxtData[9];
- long double mainOffset = pxtData[5];
- long double volumeOffset = pxtData[13];
+ double dPitch = ptp->oPitch.offset;
+ double dMain = ptp->oMain.offset;
+ double dVolume = ptp->oVolume.offset;
- //Main
- long double mainFreq;
- if (pxtData[3] == 0.0)
- mainFreq = 0.0;
+ double d1;
+ double d2;
+ double d3;
+
+ if (ptp->oMain.num == 0.0)
+ d1 = 0.0;
else
- mainFreq = 256.0 / (pxtData[1] / pxtData[3]);
+ d1 = 256.0 / (ptp->size / ptp->oMain.num);
- //Pitch
- long double pitchFreq;
- if (pxtData[7] == 0.0)
- pitchFreq = 0.0;
+ if (ptp->oPitch.num == 0.0)
+ d2 = 0.0;
else
- pitchFreq = 256.0 / (pxtData[1] / pxtData[7]);
+ d2 = 256.0 / (ptp->size / ptp->oPitch.num);
- //Volume
- long double volumeFreq;
- if (pxtData[11] == 0.0)
- volumeFreq = 0.0;
+ if (ptp->oVolume.num == 0.0)
+ d3 = 0.0;
else
- volumeFreq = 256.0 / (pxtData[1] / pxtData[11]);
+ d3 = 256.0 / (ptp->size / ptp->oVolume.num);
- for (i = 0; i < pxtData[1]; ++i)
+ for (i = 0; i < ptp->size; ++i)
{
- const int a = (int)(uint64_t)mainOffset % 256;
- const int v2 = (int)(uint64_t)pitchOffset % 256;
+ const int a = (int)dMain % 256;
+ const int b = (int)dPitch % 256;
+ const int c = (int)dVolume % 256;
+ const int d = (double)(i * 0x100) / ptp->size;
+ pData[i] = gWaveModelTable[ptp->oMain.model][a]
+ * ptp->oMain.top
+ / 64
+ * (gWaveModelTable[ptp->oVolume.model][c] * ptp->oVolume.top / 64 + 64)
+ / 64
+ * envelopeTable[d]
+ / 64
+ + 128;
- //Input data
- data[i] = envelopeTable[(uint64_t)((long double)(i << 8) / pxtData[1])]
- * (pxtData[4]
- * gWaveModelTable[(size_t)pxtData[2]][a]
- / 0x40
- * (pxtData[12]
- * gWaveModelTable[(size_t)pxtData[10]][(signed int)(uint64_t)volumeOffset % 0x100]
- / 0x40
- + 0x40)
- / 0x40)
- / 0x40
- + 0x80;
-
- long double newMainOffset;
- if (gWaveModelTable[(size_t)pxtData[6]][v2] >= 0)
- newMainOffset = (mainFreq * 2)
- * (long double)gWaveModelTable[(size_t)pxtData[6]][(signed int)(uint64_t)pitchOffset % 256]
- * pxtData[8]
- / 64.0
- / 64.0
- + mainFreq
- + mainOffset;
+ if (gWaveModelTable[ptp->oPitch.model][b] < 0)
+ dMain = d1 - d1 * 0.5 * -gWaveModelTable[ptp->oPitch.model][b] * ptp->oPitch.top / 64.0 / 64.0 + dMain;
else
- newMainOffset = mainFreq
- - mainFreq
- * 0.5
- * (long double)-gWaveModelTable[(size_t)pxtData[6]][v2]
- * pxtData[8]
- / 64.0
- / 64.0
- + mainOffset;
+ dMain = d1 + d1 * 2.0 * gWaveModelTable[ptp->oPitch.model][b] * ptp->oPitch.top / 64.0 / 64.0 + dMain;
- mainOffset = newMainOffset;
- pitchOffset = pitchOffset + pitchFreq;
- volumeOffset = volumeOffset + volumeFreq;
+ dPitch = dPitch + d2;
+ dVolume = dVolume + d3;
}
- return true;
-}
-
-bool LoadPxt(char *name, uint8_t **buf, size_t *length)
-{
- //Open file
- char path[PATH_LENGTH];
- sprintf(path, "%s/Sound/%s", gDataPath, name);
- FILE *fp = fopen(path, "rb");
-
- if (!fp)
- return false;
-
- //Read data
- std::vector<double> lineNumbers[4];
- for (int i = 0; i < 4; ++i)
- {
- for (int j = 0; j < 21; j++)
- {
- double val = fgetv(fp);
- lineNumbers[i].push_back(val);
- }
- }
-
- //Close file
- fclose(fp);
-
- //Get size
- size_t size = 0;
- for (int i = 0; i < 4; i++)
- {
- if (lineNumbers[i][1] > size)
- size = (size_t)lineNumbers[i][1];
- }
-
- //Allocate buffers
- uint8_t *dest = (uint8_t*)malloc(size);
- uint8_t *pBlock = (uint8_t*)malloc(size);
-
- if (dest && pBlock)
- {
- //Set buffers to default value of 0x80
- memset(dest, 0x80, size);
- memset(pBlock, 0x80, size);
-
- for (int i = 0; i < 4; ++i)
- {
- //Get wave data
- if (!MakePixelWaveData(lineNumbers[i], dest))
- {
- printf("MakePixelWaveData failed for %s\n", name);
- free(dest);
- free(pBlock);
- return -1;
- }
-
- //Put data into buffer
- for (int j = 0; j < lineNumbers[i][1]; ++j)
- {
- if (dest[j] + pBlock[j] - 0x100 >= -0x7F)
- {
- if (dest[j] + pBlock[j] - 0x100 <= 0x7F)
- pBlock[j] += dest[j] - 0x80;
- else
- pBlock[j] = (uint8_t)-1;
- }
- else
- {
- pBlock[j] = 0;
- }
- }
- }
-
- //Put data from buffers into main sound buffer
- *buf = (uint8_t*)malloc(size);
-
- if (!*buf)
- {
- printf("Failed to allocate buffer for %s\n", name);
- free(dest);
- free(pBlock);
- return false;
- }
-
- *length = size;
- memcpy(*buf, pBlock, size);
-
- //Free the two buffers
- free(dest);
- free(pBlock);
- return true;
- }
-
- printf("Failed to allocate dest or pBlock for %s\n", name);
- free(dest);
- free(pBlock);
- return false;
+ return TRUE;
}
--- a/src/PixTone.h
+++ b/src/PixTone.h
@@ -1,5 +1,30 @@
#pragma once
-#include <stdint.h>
-void MakeWaveTables();
-bool LoadPxt(char *name, uint8_t **buf, size_t *length);
+#include "WindowsWrapper.h"
+
+struct PIXTONEPARAMETER2
+{
+ int model;
+ double num;
+ int top;
+ int offset;
+};
+
+struct PIXTONEPARAMETER
+{
+ int use;
+ int size;
+ PIXTONEPARAMETER2 oMain;
+ PIXTONEPARAMETER2 oPitch;
+ PIXTONEPARAMETER2 oVolume;
+ int initial;
+ int pointAx;
+ int pointAy;
+ int pointBx;
+ int pointBy;
+ int pointCx;
+ int pointCy;
+};
+
+void MakeWaveTables(void);
+BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData);
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -294,3 +294,51 @@
if (lpSECONDARYBUFFER[no])
lpSECONDARYBUFFER[no]->SetPan(10 * (pan - 256));
}
+
+size_t MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no)
+{
+ size_t sample_count = 0;
+ for (int i = 0; i < ptp_num; ++i)
+ {
+ if (ptp[i].size > sample_count)
+ sample_count = ptp[i].size;
+ }
+
+ unsigned char *pcm_buffer = (unsigned char*)malloc(sample_count);
+ unsigned char *mixed_pcm_buffer = (unsigned char*)malloc(sample_count);
+ memset(pcm_buffer, 0x80, sample_count);
+ memset(mixed_pcm_buffer, 0x80, sample_count);
+
+ for (int i = 0; i < ptp_num; ++i)
+ {
+ if (!MakePixelWaveData(&ptp[i], pcm_buffer))
+ {
+ free(pcm_buffer);
+ free(mixed_pcm_buffer);
+ return -1;
+ }
+
+ for (int j = 0; j < ptp[i].size; ++j)
+ {
+ if (pcm_buffer[j] + mixed_pcm_buffer[j] - 0x100 < -0x7F)
+ mixed_pcm_buffer[j] = 0;
+ else if (pcm_buffer[j] + mixed_pcm_buffer[j] - 0x100 > 0x7F)
+ mixed_pcm_buffer[j] = -1;
+ else
+ mixed_pcm_buffer[j] += pcm_buffer[j] + -0x80;
+ }
+ }
+
+ lpSECONDARYBUFFER[no] = new SOUNDBUFFER(sample_count);
+
+ unsigned char *buf;
+ lpSECONDARYBUFFER[no]->Lock(&buf, NULL);
+ memcpy(buf, mixed_pcm_buffer, sample_count);
+ lpSECONDARYBUFFER[no]->Unlock();
+ lpSECONDARYBUFFER[no]->SetFrequency(22050);
+
+ free(pcm_buffer);
+ free(mixed_pcm_buffer);
+
+ return sample_count;
+}
--- a/src/Sound.h
+++ b/src/Sound.h
@@ -2,6 +2,8 @@
#include <stddef.h>
#include <stdint.h>
+#include "PixTone.h"
+
class SOUNDBUFFER
{
public:
@@ -95,3 +97,4 @@
void ChangeSoundFrequency(int no, uint32_t rate);
void ChangeSoundVolume(int no, int32_t volume);
void ChangeSoundPan(int no, int32_t pan);
+size_t MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no);