Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change generated types and separate signed/unsigned buffer in Arduino #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions wavdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ wavSound * loadWaveHeader(FILE * fp) {
void saveWave(FILE * fpI, wavSound *s, FILE * fpO, char * name) {
saveWave_(fpI, s, fpO, name, -1);
}

#define DATA_ARRAY_STRING_FORMAT "const signed char %s_data[]={"
#define DATA_ARRAY_STRING_FORMAT_ARDUINO_SIGNED "const int8_t %s_dataR[]={"
#define DATA_ARRAY_STRING_FORMAT_ARDUINO_UNSIGNED "const uint8_t %s_dataR[]={"
#define DATA_LENGTH_STRING_FORMAT "const size_t %s_length = %d;\n\n"


void saveWave_(FILE * fpI, wavSound *s, FILE * fpO, char * name, int MaxSamples) {
long filepos;
int i;
Expand All @@ -182,11 +189,11 @@ void saveWave_(FILE * fpI, wavSound *s, FILE * fpO, char * name, int MaxSamples)
if (MaxSamples != -1 && realLength > MaxSamples)
realLength = MaxSamples;

fprintf(fpO, "const int %s_length = %d;\n\n", name, realLength);
fprintf(fpO, DATA_LENGTH_STRING_FORMAT, name, realLength);

/* Is it a stereo file ? */
if (s->numChannels == 2) {
fprintf(fpO, "const signed char %s_dataL[]= {", name);
fprintf(fpO, DATA_ARRAY_STRING_FORMAT, name);
/* 8-bit ? convert 0-255 to -128-127 */
if (s->bitsPerSample == 8) {
for (i = 0 ; i < realLength ; i++) {
Expand All @@ -199,7 +206,7 @@ void saveWave_(FILE * fpI, wavSound *s, FILE * fpO, char * name, int MaxSamples)
// reset file position;
fseek(fpI, filepos, SEEK_SET);
fprintf(fpO, "};\n\n");
fprintf(fpO, "const signed char %s_dataR[]={", name);
fprintf(fpO, DATA_ARRAY_STRING_FORMAT, name);
for (i = 0 ; i < realLength ; i++) {
// read left output and forget about it
fread(&stuff8, sizeof(unsigned char), 1, fpI);
Expand All @@ -224,7 +231,7 @@ void saveWave_(FILE * fpI, wavSound *s, FILE * fpO, char * name, int MaxSamples)
// reset file position;
fseek(fpI, filepos, SEEK_SET);
fprintf(fpO, "};\n\n");
fprintf(fpO, "const signed char %s_dataR[]={", name);
fprintf(fpO, DATA_ARRAY_STRING_FORMAT, name);
for (i = 0 ; i < realLength ; i++) {
// read left output and forget about it
fread(&stuff8, sizeof(char), 1, fpI);
Expand All @@ -240,15 +247,16 @@ void saveWave_(FILE * fpI, wavSound *s, FILE * fpO, char * name, int MaxSamples)
/* Monaural file */
/** PATCHED FOR ARDUINO **/
else {
fprintf(fpO, "const signed char %s_data[] PROGMEM ={", name);
if (s->bitsPerSample == 8) {
fprintf(fpO, DATA_ARRAY_STRING_FORMAT_ARDUINO_UNSIGNED, name);
for (i = 0 ; i < realLength ; i++) {
fread(&stuff8, sizeof(unsigned char), 1, fpI);
fprintf(fpO, "%d, ", stuff8);
if ((i % 20) == 0) fprintf(fpO, "\n");
}
fprintf(fpO, "};\n");
} else {
fprintf(fpO, DATA_ARRAY_STRING_FORMAT_ARDUINO_SIGNED, name);
for (i = 0 ; i < realLength ; i++) {
fread(&stuff8, sizeof(char), 1, fpI);
fread(&stuff8, sizeof(char), 1, fpI);
Expand Down