Skip to content

Commit

Permalink
Proper support for RAS start samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Jun 6, 2015
1 parent 82dafbd commit 9f88340
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/export/ExportDSPADPCM.cpp
Expand Up @@ -2401,7 +2401,7 @@ int ExportDSPADPCM::ExportRAS(AudacityProject *project,
struct ras_header header = {};
header.chanCount1 = numChannels;
header.chanCount2 = numChannels;
header.numSamples = numSamples;
header.numSamples = numSamples - startSample;
header.metaDataFlag = tags->HasTag(wxT("BPM")) ? 2 : 0;
header.sampleRate = sampleRate;
header.dataOffset = header.metaDataFlag ? 192 : 160;
Expand All @@ -2413,9 +2413,9 @@ int ExportDSPADPCM::ExportRAS(AudacityProject *project,
if (loops)
{
header.loopStartBlock = loopStartSample / 14 / 4096;
header.loopStartSample = loopStartSample - header.loopStartBlock * 4096 * 14 + startSample;
header.loopStartSample = loopStartSample - header.loopStartBlock * 4096 * 14;
header.loopEndBlock = loopEndSample / 14 / 4096;
header.loopEndSample = loopEndSample - header.loopEndBlock * 4096 * 14 + startSample;
header.loopEndSample = loopEndSample - header.loopEndBlock * 4096 * 14;
}
SwapRASHeader(&header);
fs.Write("RAS_", 4);
Expand Down
11 changes: 6 additions & 5 deletions src/import/ImportDSPADPCM.cpp
Expand Up @@ -438,7 +438,7 @@ class DSPADPCMRASImportFileHandle : public DSPADPCMBaseImportFileHandle
~DSPADPCMRASImportFileHandle();

wxString GetFileDescription() { return _("RAS Stereo GameCube DSPADPCM"); }
int GetFileUncompressedBytes() { return mHeader.numSamples * 2 * mHeader.chanCount1; }
int GetFileUncompressedBytes() { return (mHeader.startSample + mHeader.numSamples) * 2 * mHeader.chanCount1; }
int Import(TrackFactory *trackFactory, Track ***outTracks,
int *outNumTracks, Tags *tags);

Expand Down Expand Up @@ -1466,8 +1466,9 @@ int DSPADPCMRASImportFileHandle::Import(TrackFactory *trackFactory,

int updateResult = eProgressSuccess;

unsigned numSamples = mHeader.startSample + mHeader.numSamples;
unsigned long samplescompleted[2] = {};
unsigned long samplesremaining[2] = {mHeader.numSamples, mHeader.numSamples};
unsigned long samplesremaining[2] = {numSamples, numSamples};
short hist[2][2] = {{0, 0},
{0, 0}};

Expand Down Expand Up @@ -1509,7 +1510,7 @@ int DSPADPCMRASImportFileHandle::Import(TrackFactory *trackFactory,
}
}
updateResult = mProgress->Update((long long unsigned)samplescompleted[0],
(long long unsigned)mHeader.numSamples);
(long long unsigned)numSamples);
if (updateResult != eProgressSuccess)
break;
}
Expand Down Expand Up @@ -1538,8 +1539,8 @@ int DSPADPCMRASImportFileHandle::Import(TrackFactory *trackFactory,
double startPoint = mHeader.startSample / sr;
lt->AddLabel(SelectedRegion(startPoint, startPoint), wxT("START"));
lt->AddLabel(SelectedRegion(
(mHeader.loopStartBlock * framesPerBlock * 14 + mHeader.loopStartSample - mHeader.startSample) / sr,
(mHeader.loopEndBlock * framesPerBlock * 14 + mHeader.loopEndSample - mHeader.startSample) / sr),
(mHeader.loopStartBlock * framesPerBlock * 14 + mHeader.loopStartSample) / sr,
(mHeader.loopEndBlock * framesPerBlock * 14 + mHeader.loopEndSample) / sr),
wxT("LOOP"));
(*outTracks)[mHeader.chanCount1] = lt;
}
Expand Down

0 comments on commit 9f88340

Please sign in to comment.