| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "fileOpsCommon.h" |
| 21 |
|
| 22 |
class DivEngine; |
| 23 |
|
| 24 |
//PPS AY-3-8910 sample bank |
| 25 |
|
| 26 |
/* ======================================= |
| 27 |
Header |
| 28 |
======================================= |
| 29 |
|
| 30 |
0x0000 - 0x0053 14 * { |
| 31 |
|
| 32 |
Pointer to Sample Data Start (1h) |
| 33 |
Length of Sample Data (1h) |
| 34 |
"Pitch"(?) (1b) |
| 35 |
Volume Reduction (1b) |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
(0x0000 0x0000 [0x00 0x00] -> no sample for this instrument ID) |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
======================================= |
| 45 |
Body |
| 46 |
======================================= |
| 47 |
|
| 48 |
Stream of Sample Data { |
| 49 |
|
| 50 |
4-Bit Unsigned |
| 51 |
(afaict) |
| 52 |
Mono |
| 53 |
16Hz |
| 54 |
(based on tests, maybe alternatively 8kHz) |
| 55 |
|
| 56 |
} */ |
| 57 |
|
| 58 |
#define PPS_BANK_SIZE 14 |
| 59 |
#define PPS_SAMPLE_RATE 16000 |
| 60 |
|
| 61 |
typedef struct |
| 62 |
{ |
| 63 |
uint16_t start_pointer; |
| 64 |
uint16_t sample_length; |
| 65 |
uint8_t _pitch; |
| 66 |
uint8_t _vol; |
| 67 |
} PPS_HEADER; |
| 68 |
|
| 69 |
|
| 70 |
void DivEngine::loadPPS(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath) |
| 71 |
{ |
| 72 |
try |
| 73 |
{ |
| 74 |
reader.seek(0, SEEK_SET); |
| 75 |
|
| 76 |
PPS_HEADER headers[PPS_BANK_SIZE]; |
| 77 |
|
| 78 |
for(int i = 0; i < PPS_BANK_SIZE; i++) |
| 79 |
{ |
| 80 |
headers[i].start_pointer = (unsigned short)reader.readS(); |
| 81 |
headers[i].sample_length = (unsigned short)reader.readS(); |
| 82 |
headers[i]._pitch = (unsigned char)reader.readC(); |
| 83 |
headers[i]._vol = (unsigned char)reader.readC(); |
| 84 |
} |
| 85 |
|
| 86 |
for(int i = 0; i < PPS_BANK_SIZE; i++) |
| 87 |
{ |
| 88 |
if(headers[i].start_pointer != 0 || headers[i].sample_length != 0 |
| 89 |
|| headers[i]._pitch != 0 || headers[i]._vol != 0) |
| 90 |
{ |
| 91 |
DivSample* s = new DivSample; |
| 92 |
|
| 93 |
s->rate = PPS_SAMPLE_RATE; |
| 94 |
s->centerRate = PPS_SAMPLE_RATE; |
| 95 |
s->depth = DIV_SAMPLE_DEPTH_4BIT; |
| 96 |
s->init(headers[i].sample_length*2); // bytes->samples |
| 97 |
|
| 98 |
reader.seek((int)headers[i].start_pointer, SEEK_SET); |
| 99 |
|
| 100 |
for(int j = 0; j < headers[i].sample_length; j++) |
| 101 |
{ |
| 102 |
s->data4[j] = reader.readC(); |
| 103 |
} |
| 104 |
|
| 105 |
ret.push_back(s); |
| 106 |
|
| 107 |
logI("pps: start %d len %d", headers[i].start_pointer, headers[i].sample_length); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
catch (EndOfFileException& e) |
| 112 |
{ |
| 113 |
lastError=_("premature end of file"); |
| 114 |
logE("premature end of file"); |
| 115 |
} |
| 116 |
} |