Skip to content

Commit

Permalink
Support QOA file format
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Mar 6, 2023
1 parent df48752 commit 075896d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion projects/VS2022/raylib/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<ItemDefinitionGroup>
<ClCompile>
<PreProcessorDefinitions>%(PreProcessorDefinitions);EXTERNAL_CONFIG_FLAGS;SUPPORT_MODULE_RSHAPES;SUPPORT_MODULE_RTEXTURES;SUPPORT_MODULE_RTEXT;SUPPORT_MODULE_RAUDIO;SUPPORT_EVENTS_WAITING;SUPPORT_COMPRESSION_API;SUPPORT_QUADS_DRAW_MODE;SUPPORT_IMAGE_MANIPULATION;SUPPORT_DEFAULT_FONT;SUPPORT_FILEFORMAT_TTF;SUPPORT_TEXT_MANIPULATION;SUPPORT_FILEFORMAT_WAV;SUPPORT_FILEFORMAT_OGG;SUPPORT_FILEFORMAT_MP3;SUPPORT_FILEFORMAT_FLAC;SUPPORT_STANDARD_FILEIO;SUPPORT_TRACELOG</PreProcessorDefinitions>
<PreProcessorDefinitions>%(PreProcessorDefinitions);EXTERNAL_CONFIG_FLAGS;SUPPORT_MODULE_RSHAPES;SUPPORT_MODULE_RTEXTURES;SUPPORT_MODULE_RTEXT;SUPPORT_MODULE_RAUDIO;SUPPORT_EVENTS_WAITING;SUPPORT_COMPRESSION_API;SUPPORT_QUADS_DRAW_MODE;SUPPORT_IMAGE_MANIPULATION;SUPPORT_DEFAULT_FONT;SUPPORT_FILEFORMAT_TTF;SUPPORT_TEXT_MANIPULATION;SUPPORT_FILEFORMAT_WAV;SUPPORT_FILEFORMAT_QOA;SUPPORT_FILEFORMAT_OGG;SUPPORT_FILEFORMAT_MP3;SUPPORT_FILEFORMAT_FLAC;SUPPORT_STANDARD_FILEIO;SUPPORT_TRACELOG</PreProcessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
35 changes: 25 additions & 10 deletions src/rfxgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* NOTE: Avoids including tinyfiledialogs depencency library
*
* VERSIONS HISTORY:
* 3.3 (06-Mar-2023) ADDED: Support export to QOA file format
* 3.2 (14-Dec-2022) ADDED: Welcome window with sponsors info
* REDESIGNED: Main toolbar to add tooltips
* REVIEWED: Help window implementation
Expand Down Expand Up @@ -416,7 +417,7 @@ int main(int argc, char *argv[])
// Show dialog: load sound (.rfx)
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_O)) showLoadFileDialog = true;

// Show dialog: export wave (.wav, .raw, .h)
// Show dialog: export wave (.wav, .qoa, .raw, .h)
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_E)) windowExportActive = true;

// Select current sound slot
Expand Down Expand Up @@ -753,9 +754,11 @@ int main(int argc, char *argv[])
GuiLabel((Rectangle){ messageBox.x + 12, messageBox.y + 24 + 12 + 48 + 16, 106, 24 }, "Sample Size:");
GuiLabel((Rectangle){ messageBox.x + 12, messageBox.y + 24 + 12 + 72 + 24, 106, 24 }, "Channels:");

fileTypeActive = GuiComboBox((Rectangle){ messageBox.x + 12 + 100, messageBox.y + 24 + 12, 124, 24 }, "WAV;RAW;CODE", fileTypeActive);
fileTypeActive = GuiComboBox((Rectangle){ messageBox.x + 12 + 100, messageBox.y + 24 + 12, 124, 24 }, "WAV;QOA;RAW;CODE", fileTypeActive);
sampleRateActive = GuiComboBox((Rectangle){ messageBox.x + 12 + 100, messageBox.y + 24 + 12 + 24 + 8, 124, 24 }, "22050 Hz;44100 Hz", sampleRateActive);
if (fileTypeActive == 1) { sampleSizeActive = 1; GuiDisable(); }
sampleSizeActive = GuiComboBox((Rectangle){ messageBox.x + 12 + 100, messageBox.y + 24 + 12 + 48 + 16, 124, 24 }, "8 bit;16 bit;32 bit", sampleSizeActive);
GuiEnable();
channelsActive = GuiComboBox((Rectangle){ messageBox.x + 12 + 100, messageBox.y + 24 + 12 + 72 + 24, 124, 24 }, "Mono;Stereo", channelsActive);

if (result == 1) // Export button pressed
Expand All @@ -772,6 +775,9 @@ int main(int argc, char *argv[])

windowExportActive = false;
showExportFileDialog = true;

memset(outFileName, 0, 512);
strcpy(outFileName, "sound");
}
else if (result == 0) windowExportActive = false;
}
Expand Down Expand Up @@ -848,8 +854,9 @@ int main(int argc, char *argv[])
char fileTypeFilters[64] = { 0 };

if (fileTypeActive == 0) { strcpy(fileTypeFilters, "*.wav"); strcat(outFileName, ".wav"); }
else if (fileTypeActive == 1) { strcpy(fileTypeFilters, "*.raw"); strcat(outFileName, ".raw"); }
else if (fileTypeActive == 2) { strcpy(fileTypeFilters, "*.h"); strcat(outFileName, ".h"); }
else if (fileTypeActive == 1) { strcpy(fileTypeFilters, "*.qoa"); strcat(outFileName, ".qoa"); }
else if (fileTypeActive == 2) { strcpy(fileTypeFilters, "*.raw"); strcat(outFileName, ".raw"); }
else if (fileTypeActive == 3) { strcpy(fileTypeFilters, "*.h"); strcat(outFileName, ".h"); }

int result = GuiFileDialog(DIALOG_SAVE_FILE, "Export wave file...", outFileName, fileTypeFilters, TextFormat("File type (%s)", fileTypeFilters));
#endif
Expand All @@ -865,13 +872,13 @@ int main(int argc, char *argv[])
if ((GetFileExtension(outFileName) == NULL) || !IsFileExtension(outFileName, ".wav")) strcat(outFileName, ".wav\0");
ExportWave(cwave, outFileName); // Export wave data as WAV file
}
else if (fileTypeActive == 2)
else if (fileTypeActive == 1) // Export Wave as QOA data
{
// Check for valid extension and make sure it is
if ((GetFileExtension(outFileName) == NULL) || !IsFileExtension(outFileName, ".h")) strcat(outFileName, ".h\0");
ExportWaveAsCode(cwave, outFileName); // Export wave data as code file
if ((GetFileExtension(outFileName) == NULL) || !IsFileExtension(outFileName, ".qoa")) strcat(outFileName, ".qoa\0");
ExportWave(cwave, outFileName); // Export wave data as QOA file
}
else if (fileTypeActive == 1) // Export Wave as RAW data
else if (fileTypeActive == 2) // Export Wave as RAW data
{
// Check for valid extension and make sure it is
if ((GetFileExtension(outFileName) == NULL) || !IsFileExtension(outFileName, ".raw")) strcat(outFileName, ".raw\0");
Expand All @@ -883,6 +890,13 @@ int main(int argc, char *argv[])
fclose(rawFile);
}
}
else if (fileTypeActive == 3) // Export as code file
{
// Check for valid extension and make sure it is
if ((GetFileExtension(outFileName) == NULL) || !IsFileExtension(outFileName, ".h")) strcat(outFileName, ".h\0");
ExportWaveAsCode(cwave, outFileName); // Export wave data as code file
}


UnloadWave(cwave);

Expand Down Expand Up @@ -954,7 +968,7 @@ static void ShowCommandLineInfo(void)
printf(" -i, --input <filename.ext> : Define input file.\n");
printf(" Supported extensions: .rfx, .wav, .ogg, .flac, .mp3\n\n");
printf(" -o, --output <filename.ext> : Define output file.\n");
printf(" Supported extensions: .wav, .raw, .h\n");
printf(" Supported extensions: .wav, .qoa, .raw, .h\n");
printf(" NOTE: If not specified, defaults to: output.wav\n\n");
printf(" -f, --format <sample_rate>,<sample_size>,<channels>\n");
printf(" : Define output wave format. Comma separated values.\n");
Expand Down Expand Up @@ -1025,6 +1039,7 @@ static void ProcessCommandLine(int argc, char *argv[])
if (((i + 1) < argc) && (argv[i + 1][0] != '-'))
{
if (IsFileExtension(argv[i + 1], ".wav") ||
IsFileExtension(argv[i + 1], ".qoa") ||
IsFileExtension(argv[i + 1], ".raw") ||
IsFileExtension(argv[i + 1], ".h"))
{
Expand Down Expand Up @@ -1126,7 +1141,7 @@ static void ProcessCommandLine(int argc, char *argv[])
WaveFormat(&wave, sampleRate, sampleSize, channels);

// Export wave data as audio file (.wav) or code file (.h)
if (IsFileExtension(outFileName, ".wav")) ExportWave(wave, outFileName);
if (IsFileExtension(outFileName, ".wav") || IsFileExtension(outFileName, ".qoa")) ExportWave(wave, outFileName);
else if (IsFileExtension(outFileName, ".h")) ExportWaveAsCode(wave, outFileName);
else if (IsFileExtension(outFileName, ".raw"))
{
Expand Down

0 comments on commit 075896d

Please sign in to comment.