Skip to content

Commit

Permalink
Add FLAC CDDA support via miniaudio to mkpsxiso (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi authored Dec 16, 2021
1 parent 1aa12f3 commit d0cd9e5
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 193 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tinyxml2"]
path = tinyxml2
url = https://github.com/leethomason/tinyxml2
[submodule "miniaudio"]
path = miniaudio
url = https://github.com/mackron/miniaudio
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if(NOT EXISTS ${PROJECT_SOURCE_DIR}/tinyxml2/tinyxml2.cpp)
message(FATAL_ERROR "The tinyxml2 directory is empty. Run 'git submodule update --init --recursive' to populate it.")
endif()

if(NOT EXISTS ${PROJECT_SOURCE_DIR}/miniaudio/miniaudio.h)
message(FATAL_ERROR "The miniaudio directory is empty. Run 'git submodule update --init --recursive' to populate it.")
endif()

# Build tinyxml2. I didn't bother with tinyxml2's actual CMake integration
# because it's far easier do do this. It is a single-file library after all.
add_library (tinyxml2 STATIC tinyxml2/tinyxml2.cpp)
Expand All @@ -46,6 +50,7 @@ add_executable(mkpsxiso
${mkpsxiso_dir}/iso.cpp
${mkpsxiso_dir}/main.cpp
)
target_include_directories(mkpsxiso PUBLIC "miniaudio")
target_link_libraries(mkpsxiso tinyxml2 iso_shared)

add_executable(dumpsxiso
Expand Down
1 change: 1 addition & 0 deletions miniaudio
Submodule miniaudio added at 8686f5
14 changes: 13 additions & 1 deletion src/mkpsxiso/cdwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ size_t cd::IsoWriter::WriteBytesXA(void* data, size_t bytes, int edcEccEncode) {

}

size_t cd::IsoWriter::WriteBytesRaw(void* data, size_t bytes) {
size_t cd::IsoWriter::WriteBytesRaw(const void* data, size_t bytes) {

size_t writeBytes = 0;

Expand Down Expand Up @@ -305,6 +305,18 @@ size_t cd::IsoWriter::WriteBytesRaw(void* data, size_t bytes) {

}

size_t cd::IsoWriter::WriteBlankSectors(const size_t count)
{
const char blank[CD_SECTOR_SIZE] {};

size_t bytesWritten = 0;
for(size_t i = 0; i < count; i++)
{
bytesWritten += WriteBytesRaw( blank, CD_SECTOR_SIZE );
}
return bytesWritten;
}

int cd::IsoWriter::CurrentSector() {

return currentSector;
Expand Down
3 changes: 2 additions & 1 deletion src/mkpsxiso/cdwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class IsoWriter {

size_t WriteBytes(void* data, size_t bytes, int edcEccEncode);
size_t WriteBytesXA(void* data, size_t bytes, int edcEccEncode);
size_t WriteBytesRaw(void* data, size_t bytes);
size_t WriteBytesRaw(const void* data, size_t bytes);
size_t WriteBlankSectors(const size_t count);

void Close();

Expand Down
50 changes: 7 additions & 43 deletions src/mkpsxiso/iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int iso::DirTreeClass::GetWavSize(const std::filesystem::path& wavFile)
return 2352*((WAV_Subchunk2.len+2351)/2352);
}

int iso::DirTreeClass::PackWaveFile(cd::IsoWriter* writer, const std::filesystem::path& wavFile, bool pregap)
int iso::DirTreeClass::PackWaveFile(cd::IsoWriter* writer, const std::filesystem::path& wavFile)
{
FILE *fp;
int waveLen;
Expand All @@ -162,16 +162,6 @@ int iso::DirTreeClass::PackWaveFile(cd::IsoWriter* writer, const std::filesystem
{

// File must be a raw, pack it anyway
memset(buff, 0x00, CD_SECTOR_SIZE);

if ( pregap ) {

// Write pregap region
for ( int i=0; i<150; i++ ) {
writer->WriteBytesRaw(buff, CD_SECTOR_SIZE);
}

}

// Write data
fseek(fp, 0, SEEK_END);
Expand Down Expand Up @@ -268,16 +258,6 @@ int iso::DirTreeClass::PackWaveFile(cd::IsoWriter* writer, const std::filesystem

waveLen = WAV_Subchunk2.len;

// Write pregap region
memset(buff, 0x00, CD_SECTOR_SIZE);
if ( pregap )
{
for ( int i=0; i<150; i++ )
{
writer->WriteBytesRaw(buff, CD_SECTOR_SIZE);
}
}

// Write data
while ( waveLen > 0 )
{
Expand Down Expand Up @@ -862,19 +842,9 @@ int iso::DirTreeClass::WriteDirectoryRecords(cd::IsoWriter* writer, const DIRENT

int iso::DirTreeClass::WriteFiles(cd::IsoWriter* writer)
{
bool firstDAWritten = false;

for ( const DIRENTRY& entry : entries )
{
// TODO: Configurable pregap
if ( ( entry.type == EntryType::EntryDA ) && firstDAWritten )
{
writer->SeekToSector( entry.lba-150 );
}
else
{
writer->SeekToSector( entry.lba );
}
writer->SeekToSector( entry.lba );

// Write files as regular data sectors
if ( entry.type == EntryType::EntryFile )
Expand Down Expand Up @@ -1036,7 +1006,9 @@ int iso::DirTreeClass::WriteFiles(cd::IsoWriter* writer)
}

// TODO: Configurable pregap
if ( PackWaveFile( writer, entry.srcfile, true/*!firstDAWritten*/ ) )
writer->WriteBlankSectors(150);

if ( PackWaveFile( writer, entry.srcfile) )
{
if (!global::QuietMode)
{
Expand Down Expand Up @@ -1145,18 +1117,10 @@ int iso::DirTreeClass::WriteCueEntries(FILE* fp, int* trackNum) const
fprintf( fp, " TRACK %02d AUDIO\n", *trackNum );

int trackLBA = entry.lba;

// TODO: Configurable pregap?
/*if ( *trackNum == 2 )
{
fprintf( fp, " PREGAP 00:02:00\n" );
}
else*/
{
fprintf( fp, " INDEX 00 %02d:%02d:%02d\n",
// TODO: Configurable pregap?
fprintf( fp, " INDEX 00 %02d:%02d:%02d\n",
(trackLBA/75)/60, (trackLBA/75)%60,
trackLBA%75 );
}

trackLBA += 150;

Expand Down
2 changes: 1 addition & 1 deletion src/mkpsxiso/iso.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace iso
std::unique_ptr<PathTableClass> GenPathTableSub(unsigned short& index, unsigned short parentIndex) const;

int GetWavSize(const std::filesystem::path& wavFile);
int PackWaveFile(cd::IsoWriter* writer, const std::filesystem::path& wavFile, bool pregap);
int PackWaveFile(cd::IsoWriter* writer, const std::filesystem::path& wavFile);

public:

Expand Down
Loading

0 comments on commit d0cd9e5

Please sign in to comment.