update aif2pcm

This commit is contained in:
Diegoisawesome 2020-02-20 02:04:20 +08:00 committed by jiangzhengwenjz
parent c51ad93f4f
commit 28f708fa0d
6 changed files with 89 additions and 35 deletions

View File

@ -169,10 +169,6 @@ else
$(C_BUILDDIR)/%.o: c_dep = $(shell $(SCANINC) -I include $(C_SUBDIR)/$*.c)
endif
ifeq ($(DINFO),1)
override CFLAGS += -g
endif
$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep)
@$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
@$(PREPROC) $(C_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(C_BUILDDIR)/$*.s

View File

@ -700,7 +700,7 @@
#define SIO_TRANS_DATA_FULL 0x0010 // Transmitted data full
#define SIO_RECV_ENABLE 0x0800 // Enable receiver
#define SIO_RECV_DATA_EMPTY 0x0020 // No data received
#define SIO_IF_ENABLE 0x4000 // Enable interrupt request
#define SIO_INTR_ENABLE 0x4000 // Enable interrupt request
#define SIO_MULTI_SI_SHIFT 2
#define SIO_MULTI_SI_MASK 0x1

View File

@ -323,8 +323,8 @@ SECTIONS {
*libc.a:s_rint.o(.rodata);
data/data_3.o(.rodata);
*libc.a:impure.o(.rodata);
/* TODO: extract the multiboot programs from ROM. */
data/data_2.o(.rodata);
/* stuff below are mislinked into the binary? */
data/data_unk.o(.rodata);
*libc.a:impure.o(.data);
} >rom

View File

@ -25,7 +25,7 @@ void MultiSioInit(u32 connectedFlags)
REG_IME = 1;
REG_RCNT = ST_R_SIO_MASTER_MODE;
*(vu32 *)REG_ADDR_SIOCNT = SIO_MULTI_MODE;
REG_SIOCNT |= SIO_IF_ENABLE | MULTI_SIO_BAUD_RATE_NO;
REG_SIOCNT |= SIO_INTR_ENABLE | MULTI_SIO_BAUD_RATE_NO;
CpuFill32(0, &gMultiSioArea, sizeof(struct MultiSioArea)); // Clear Multi-play Communication Work Area
#ifdef MULTI_SIO_DI_FUNC_FAST // Copy Function
CpuCopy32(MultiSioRecvBufChange, gMultiSioRecvFuncBuf, sizeof(gMultiSioRecvFuncBuf));

View File

@ -40,7 +40,7 @@ u32 Sio32MultiLoadMain(u32 *progressCounterp)
}
else
{ // Sets Slave
REG_SIOCNT |= SIO_IF_ENABLE | SIO_ENABLE; // Starts communication
REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE; // Starts communication
REG_IME = 0;
REG_IE |= INTR_FLAG_SERIAL; // Enables SIO interrupt
REG_IME = 1;

View File

@ -34,8 +34,8 @@ double ieee754_read_extended (uint8_t*);
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, __VA_ARGS__); \
exit(1); \
fprintf(stderr, format, __VA_ARGS__); \
exit(1); \
} while (0)
#else
@ -43,8 +43,8 @@ do \
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, ##__VA_ARGS__); \
exit(1); \
fprintf(stderr, format, ##__VA_ARGS__); \
exit(1); \
} while (0)
#endif // _MSC_VER
@ -64,6 +64,12 @@ struct Bytes {
uint8_t *data;
};
struct Marker {
unsigned short id;
unsigned long position;
// don't care about the name
};
struct Bytes *read_bytearray(const char *filename)
{
struct Bytes *bytes = malloc(sizeof(struct Bytes));
@ -167,6 +173,8 @@ void read_aif(struct Bytes *aif, AifData *aif_data)
FATAL_ERROR("FORM Type is '%s', but it must be AIFF!", chunk_type);
}
struct Marker *markers = NULL;
unsigned short num_markers = 0, loop_start = 0, loop_end = 0;
unsigned long num_sample_frames = 0;
// Read all the Chunks to populate the AifData struct.
@ -219,10 +227,17 @@ void read_aif(struct Bytes *aif, AifData *aif_data)
}
else if (strcmp(chunk_name, "MARK") == 0)
{
unsigned short num_markers = (aif->data[pos++] << 8);
num_markers = (aif->data[pos++] << 8);
num_markers |= (uint8_t)aif->data[pos++];
// Read each marker and look for the "START" marker.
if (markers)
{
FATAL_ERROR("More than one MARK Chunk in file!\n");
}
markers = calloc(num_markers, sizeof(struct Marker));
// Read each marker.
for (int i = 0; i < num_markers; i++)
{
unsigned short marker_id = (aif->data[pos++] << 8);
@ -233,28 +248,16 @@ void read_aif(struct Bytes *aif, AifData *aif_data)
marker_position |= (aif->data[pos++] << 8);
marker_position |= (uint8_t)aif->data[pos++];
// Marker id is a pascal-style string.
// Marker name is a Pascal-style string.
uint8_t marker_name_size = aif->data[pos++];
char *marker_name = (char *)malloc((marker_name_size + 1) * sizeof(char));
// We don't actually need the marker name for anything anymore.
/*char *marker_name = (char *)malloc((marker_name_size + 1) * sizeof(char));
memcpy(marker_name, &aif->data[pos], marker_name_size);
marker_name[marker_name_size] = '\0';
pos += marker_name_size;
marker_name[marker_name_size] = '\0';*/
pos += marker_name_size + !(marker_name_size & 1);
if (strcmp(marker_name, "START") == 0)
{
aif_data->loop_offset = marker_position;
aif_data->has_loop = true;
}
else if (strcmp(marker_name, "END") == 0)
{
if (!aif_data->has_loop) {
aif_data->loop_offset = marker_position;
aif_data->has_loop = true;
}
aif_data->num_samples = marker_position;
}
free(marker_name);
markers[i].id = marker_id;
markers[i].position = marker_position;
}
}
else if (strcmp(chunk_name, "INST") == 0)
@ -264,11 +267,31 @@ void read_aif(struct Bytes *aif, AifData *aif_data)
aif_data->midi_note = midi_note;
// Skip over data we don't need.
pos += 19;
pos += 7;
unsigned short loop_type = (aif->data[pos++] << 8);
loop_type |= (uint8_t)aif->data[pos++];
if (loop_type)
{
loop_start = (aif->data[pos++] << 8);
loop_start |= (uint8_t)aif->data[pos++];
loop_end = (aif->data[pos++] << 8);
loop_end |= (uint8_t)aif->data[pos++];
}
else
{
// Skip NoLooping sustain loop.
pos += 4;
}
// Skip release loop, we don't need it.
pos += 6;
}
else if (strcmp(chunk_name, "SSND") == 0)
{
// SKip offset and blockSize
// Skip offset and blockSize
pos += 8;
unsigned long num_samples = chunk_size - 8;
@ -285,6 +308,41 @@ void read_aif(struct Bytes *aif, AifData *aif_data)
pos += chunk_size;
}
}
if (markers)
{
// Resolve loop points.
struct Marker *cur_marker = markers;
// Grab loop start point.
for (int i = 0; i < num_markers; i++, cur_marker++)
{
if (cur_marker->id == loop_start)
{
aif_data->loop_offset = cur_marker->position;
aif_data->has_loop = true;
break;
}
}
cur_marker = markers;
// Grab loop end point.
for (int i = 0; i < num_markers; i++, cur_marker++)
{
if (cur_marker->id == loop_end)
{
if (cur_marker->position < aif_data->loop_offset) {
aif_data->loop_offset = cur_marker->position;
aif_data->has_loop = true;
}
aif_data->num_samples = cur_marker->position;
break;
}
}
free(markers);
}
}
// This is a table of deltas between sample values in compressed PCM data.