Merge pull request #595 from visualboyadvance-m/qol
Cleanup and WAV audio recording.
This commit is contained in:
commit
ed4d1b9827
|
@ -116,7 +116,7 @@ static int64_t readSignVarPtr(FILE* f)
|
||||||
{
|
{
|
||||||
int64_t offset = readVarPtr(f);
|
int64_t offset = readVarPtr(f);
|
||||||
bool sign = offset & 1;
|
bool sign = offset & 1;
|
||||||
|
|
||||||
offset = offset >> 1;
|
offset = offset >> 1;
|
||||||
if (sign) {
|
if (sign) {
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
|
@ -325,7 +325,7 @@ static bool patchApplyBPS(const char* patchname, uint8_t** rom, int* size)
|
||||||
|
|
||||||
fseeko64(f, 0, SEEK_SET);
|
fseeko64(f, 0, SEEK_SET);
|
||||||
uint32_t crc = computePatchCRC(f, patchSize - 4);
|
uint32_t crc = computePatchCRC(f, patchSize - 4);
|
||||||
|
|
||||||
if (crc != patchCRC) {
|
if (crc != patchCRC) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return false;
|
return false;
|
||||||
|
@ -357,13 +357,13 @@ static bool patchApplyBPS(const char* patchname, uint8_t** rom, int* size)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* new_rom = (uint8_t*)calloc(1, dataSize);
|
uint8_t* new_rom = (uint8_t*)calloc(1, dataSize);
|
||||||
|
|
||||||
int64_t length = 0;
|
int64_t length = 0;
|
||||||
uint8_t action = 0;
|
uint8_t action = 0;
|
||||||
uint32_t outputOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0;
|
uint32_t outputOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0;
|
||||||
|
|
||||||
while (ftello64(f) < patchSize - 12) {
|
while (ftello64(f) < patchSize - 12) {
|
||||||
length = readVarPtr(f);
|
length = readVarPtr(f);
|
||||||
action = length & 3 ;
|
action = length & 3 ;
|
||||||
|
@ -389,30 +389,23 @@ static bool patchApplyBPS(const char* patchname, uint8_t** rom, int* size)
|
||||||
case 3: // targetCopy
|
case 3: // targetCopy
|
||||||
targetRelativeOffset += readSignVarPtr(f);
|
targetRelativeOffset += readSignVarPtr(f);
|
||||||
while(length--) { // yes, copy from alredy patched rom, and only 1 byte at time (pseudo-rle)
|
while(length--) { // yes, copy from alredy patched rom, and only 1 byte at time (pseudo-rle)
|
||||||
new_rom[outputOffset++] = new_rom[targetRelativeOffset++];
|
new_rom[outputOffset++] = new_rom[targetRelativeOffset++];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crc = crc32(0L, Z_NULL, 0);
|
crc = crc32(0L, Z_NULL, 0);
|
||||||
crc = crc32(crc, new_rom, dataSize);
|
crc = crc32(crc, new_rom, dataSize);
|
||||||
|
|
||||||
// TODO
|
if(crc == dstCRC)
|
||||||
if(crc == dstCRC) {
|
{
|
||||||
#if 1
|
|
||||||
if (dataSize > *size) {
|
if (dataSize > *size) {
|
||||||
// SIGSEGV in /src/gba/GBA.cpp:3313 [*((uint16_t*)&rom[0x1fe209c]) = 0xdffa; // SWI 0xFA]
|
|
||||||
*rom = (uint8_t*)realloc(*rom, dataSize);
|
*rom = (uint8_t*)realloc(*rom, dataSize);
|
||||||
}
|
}
|
||||||
memcpy(*rom, new_rom, dataSize);
|
memcpy(*rom, new_rom, dataSize);
|
||||||
*size = dataSize;
|
*size = dataSize;
|
||||||
free(new_rom);
|
free(new_rom);
|
||||||
#else
|
|
||||||
free(*rom);
|
|
||||||
*rom = new_rom;
|
|
||||||
*size = dataSize;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -602,10 +595,6 @@ static bool patchApplyPPF(const char* patchname, uint8_t** rom, int* size)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// HINT: new format(.ext) => aditional changes in
|
|
||||||
// sdl/SDL.cpp>>>main (~1600)
|
|
||||||
// wx/panel.cpp>>>GameArea::LoadGame (~130)
|
|
||||||
|
|
||||||
bool applyPatch(const char* patchname, uint8_t** rom, int* size)
|
bool applyPatch(const char* patchname, uint8_t** rom, int* size)
|
||||||
{
|
{
|
||||||
#ifndef __LIBRETRO__
|
#ifndef __LIBRETRO__
|
||||||
|
|
|
@ -12,7 +12,8 @@ struct supportedCodecs {
|
||||||
|
|
||||||
const supportedCodecs audioSupported[] = {
|
const supportedCodecs audioSupported[] = {
|
||||||
{ AV_CODEC_ID_MP3, "MP3 (MPEG audio layer 3)", "mp3" },
|
{ AV_CODEC_ID_MP3, "MP3 (MPEG audio layer 3)", "mp3" },
|
||||||
{ AV_CODEC_ID_AAC, "ADTS AAC (Advanced Audio Coding)", "aac,adts" }
|
{ AV_CODEC_ID_AAC, "ADTS AAC (Advanced Audio Coding)", "aac,adts" },
|
||||||
|
{ AV_CODEC_ID_PCM_S16LE, "WAV / WAVE (Waveform Audio)", "wav" }
|
||||||
};
|
};
|
||||||
|
|
||||||
const supportedCodecs videoSupported[] = {
|
const supportedCodecs videoSupported[] = {
|
||||||
|
@ -120,7 +121,7 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isSupported) return MRET_ERR_NOCODEC;
|
if (!isSupported && acodec->supported_samplerates) return MRET_ERR_NOCODEC;
|
||||||
aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout);
|
aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout);
|
||||||
aenc->channel_layout = AV_CH_LAYOUT_STEREO;
|
aenc->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||||
if (acodec->channel_layouts)
|
if (acodec->channel_layouts)
|
||||||
|
@ -143,7 +144,10 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
|
||||||
return MRET_ERR_BUFSIZE;
|
return MRET_ERR_BUFSIZE;
|
||||||
// number of samples per frame
|
// number of samples per frame
|
||||||
if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
|
if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
|
||||||
nb_samples = 10000;
|
{
|
||||||
|
//nb_samples = 10000; // can be any value, but we use our aud buffer size
|
||||||
|
nb_samples = 1470;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
nb_samples = aenc->frame_size;
|
nb_samples = aenc->frame_size;
|
||||||
// audio frame for input
|
// audio frame for input
|
||||||
|
@ -552,6 +556,16 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int
|
||||||
int realLength = length / sizeof *aud;
|
int realLength = length / sizeof *aud;
|
||||||
bool isMissing = false;
|
bool isMissing = false;
|
||||||
int cp = -1;
|
int cp = -1;
|
||||||
|
|
||||||
|
if (c->frame_size == 0) // no compression/limit for audio frames
|
||||||
|
{
|
||||||
|
int maxCopy = realLength;
|
||||||
|
memcpy(audioBuffer + posInAudioBuffer, aud, maxCopy * 2);
|
||||||
|
posInAudioBuffer += maxCopy;
|
||||||
|
samplesInAudioBuffer += (maxCopy / 2);
|
||||||
|
aud += maxCopy;
|
||||||
|
}
|
||||||
|
|
||||||
if (samplesInAudioBuffer < c->frame_size)
|
if (samplesInAudioBuffer < c->frame_size)
|
||||||
{
|
{
|
||||||
int missingSamples = (c->frame_size - samplesInAudioBuffer);
|
int missingSamples = (c->frame_size - samplesInAudioBuffer);
|
||||||
|
@ -568,7 +582,7 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int
|
||||||
cp = realLength - maxCopy;
|
cp = realLength - maxCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (samplesInAudioBuffer != c->frame_size) // not enough samples
|
if (samplesInAudioBuffer != c->frame_size && (c->frame_size > 0 || samplesInAudioBuffer != realLength)) // not enough samples
|
||||||
{
|
{
|
||||||
return MRET_OK;
|
return MRET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1197,7 +1197,7 @@ EVT_HANDLER_MASK(RecordSoundStartRecording, "Start sound recording...", CMDEN_NS
|
||||||
ext.Replace(wxT(","), wxT(";*."));
|
ext.Replace(wxT(","), wxT(";*."));
|
||||||
ext.insert(0, wxT("*."));
|
ext.insert(0, wxT("*."));
|
||||||
|
|
||||||
if (sound_extno < 0 && ext.find(wxT("*.mp3")) != wxString::npos)
|
if (sound_extno < 0 && ext.find(wxT("*.wav")) != wxString::npos)
|
||||||
sound_extno = extno;
|
sound_extno = extno;
|
||||||
|
|
||||||
sound_exts.append(ext);
|
sound_exts.append(ext);
|
||||||
|
|
Loading…
Reference in New Issue