diff --git a/DSFIO/alloc_DSF.c b/DSFIO/alloc_DSF.c index 9200113..640aac4 100644 --- a/DSFIO/alloc_DSF.c +++ b/DSFIO/alloc_DSF.c @@ -16,12 +16,12 @@ /* DSD struct allocation */ DSF *alloc_DSF(void){ - // Memory Allocation + /* Memory Allocation */ DSF *dsf = (DSF *)malloc(sizeof(DSF)); - // DSD data point to NULL + /* DSD data point to NULL */ dsf->data.data = NULL; - // Return Allocated DSD struct + /* Return Allocated DSD struct */ return dsf; } \ No newline at end of file diff --git a/DSFIO/dsfio.h b/DSFIO/dsfio.h index 89bd7f1..ae2f1f0 100644 --- a/DSFIO/dsfio.h +++ b/DSFIO/dsfio.h @@ -6,13 +6,13 @@ https://opensource.org/licenses/mit-license.php ----------------------------------------------------*/ -// include guard +/* include guard */ #ifndef INCLUDED_DSFIO #define INCLUDED_DSFIO #include -//extern C +/* extern C */ #ifdef __cplusplus extern "C" { @@ -20,60 +20,60 @@ extern "C" /* DSD chunk */ typedef struct { - char chunkID[4]; // "DSD " - uint64_t chunkSize; // 28 (Little Endian) - uint64_t fileSize; // Total File Size (Little Endian) - uint64_t metaPoint; // Pointer to Metadata chunk (Little Endian) + char chunkID[4]; /* "DSD " */ + uint64_t chunkSize; /* 28 (Little Endian) */ + uint64_t fileSize; /* Total File Size (Little Endian) */ + uint64_t metaPoint; /* Pointer to Metadata chunk (Little Endian) */ } DSD; /* Format chunk */ typedef struct { - char chunkID[4]; // "fmt " - uint64_t chunkSize; // Usually, 52 (Little Endian) - uint32_t formatVersion; // 1 (Little Endian) - uint32_t formatID; // 0: DSD RAW (Little Endian) - uint32_t channelType; // 1 - 7 (Little Endian), See Format Specification. - uint32_t channelNum; // 1 - 6 (Little Endian) - uint32_t samplesPerSec; // Sampling Frequency (Little Endian) - uint32_t bitsPerSample; // Quantization Bits (Little Endian) - uint64_t sampleCount; // samplesPerSec * [Playback time (sec)] (Little Endian) - uint32_t blockSize; // 4096 - //int32_t RSVD; // Fill Zero(0x00, 0x00, 0x00, 0x00) + char chunkID[4]; /* "fmt " */ + uint64_t chunkSize; /* Usually, 52 (Little Endian) */ + uint32_t formatVersion; /* 1 (Little Endian) */ + uint32_t formatID; /* 0: DSD RAW (Little Endian) */ + uint32_t channelType; /* 1 - 7 (Little Endian), See Format Specification. */ + uint32_t channelNum; /* 1 - 6 (Little Endian), See Format Specification. */ + uint32_t samplesPerSec; /* Sampling Frequency (Little Endian) */ + uint32_t bitsPerSample; /* Quantization Bits (Little Endian) */ + uint64_t sampleCount; /* samplesPerSec * [Playback time (sec)] (Little Endian) */ + uint32_t blockSize; /* 4096 */ + //int32_t RSVD; /* Fill Zero(0x00, 0x00, 0x00, 0x00) */ } FMT; /* DATA chunk */ typedef struct { - char chunkID[4]; // "data" - uint64_t chunkSize; // (data byte)+12 - uint8_t *data; // DSD data + char chunkID[4]; /* "data" */ + uint64_t chunkSize; /* (data byte)+12 */ + uint8_t *data; /* DSD data */ } DATA; /* DSF struct */ typedef struct { - DSD dsd; // DSD Chunk - FMT fmt; // Format chunk - DATA data; // Data chunk + DSD dsd; /* DSD Chunk */ + FMT fmt; /* Format chunk */ + DATA data; /* Data chunk */ } DSF; /* DSD stream */ typedef struct { - uint8_t *DSDL; // Left Data (8 samples in 1 index) - uint8_t *DSDR; // Right Data (8 samples in 1 index) + uint8_t *DSDL; /* Left Data (8 samples in 1 index) */ + uint8_t *DSDR; /* Right Data (8 samples in 1 index) */ } DSD_STREAM; /* Prototype Declaration */ -DSF *alloc_DSF(void); // alloc_DSD.c -void free_DSF(DSF *dsf); // free_DSD.c -void read_DSF(DSF *dsf, char *filename); // read_DSD.c +DSF *alloc_DSF(void); /* alloc_DSD.c */ +void free_DSF(DSF *dsf); /* free_DSD.c */ +void read_DSF(DSF *dsf, char *filename); /* read_DSD.c */ -DSD_STREAM *alloc_STREAM(void); // alloc_STREAM.c -void free_STREAM(DSD_STREAM *stream); // free_STREAM.c -void shape_STREAM(DSF *dsf, DSD_STREAM *stream); // shape_STREAM.c +DSD_STREAM *alloc_STREAM(void); /* alloc_STREAM.c */ +void free_STREAM(DSD_STREAM *stream); /* free_STREAM.c */ +void shape_STREAM(DSF *dsf, DSD_STREAM *stream); /* shape_STREAM.c */ #ifdef __cplusplus } #endif -// Close include guard -#endif +/* Close include guard */ +#endif \ No newline at end of file diff --git a/DSFIO/free_DSF.c b/DSFIO/free_DSF.c index ec67dab..59575ea 100644 --- a/DSFIO/free_DSF.c +++ b/DSFIO/free_DSF.c @@ -16,9 +16,9 @@ /* Free DSD struct */ void free_DSF(DSF *dsf){ - // Free DSD data + /* Free DSD data */ free(dsf->data.data); - // Free DSD struct + /* Free DSD struct */ free(dsf); } \ No newline at end of file diff --git a/DSFIO/free_STREAM.c b/DSFIO/free_STREAM.c index 2666734..5d10187 100644 --- a/DSFIO/free_STREAM.c +++ b/DSFIO/free_STREAM.c @@ -14,9 +14,12 @@ /* Include dsfio.h */ #include "dsfio.h" +/* free DSD_STREAM struct */ void free_STREAM(DSD_STREAM *stream){ + /* free DSD stream Data */ free(stream->DSDL); free(stream->DSDR); + /* free struct */ free(stream); } \ No newline at end of file diff --git a/DSFIO/read_DSF.c b/DSFIO/read_DSF.c index 0f42a00..909d7ca 100644 --- a/DSFIO/read_DSF.c +++ b/DSFIO/read_DSF.c @@ -24,55 +24,57 @@ void read_DSF(DSF *dsf, char *filename){ fread(dsf->dsd.chunkID, 1, 4, fp); if (strncmp(dsf->dsd.chunkID, "DSD ", 4) != 0) { + /* Throw the Error. */ printf("Error!: This File is NOT DSF.\n"); } else { - fread(&dsf->dsd.chunkSize, 8, 1, fp); - fread(&dsf->dsd.fileSize, 8, 1, fp); - fread(&dsf->dsd.metaPoint, 8, 1, fp); - fread(dsf->fmt.chunkID, 1, 4, fp); - fread(&dsf->fmt.chunkSize, 8, 1, fp); - fread(&dsf->fmt.formatVersion, 4, 1, fp); - fread(&dsf->fmt.formatID, 4, 1, fp); - fread(&dsf->fmt.channelType, 4, 1, fp); - fread(&dsf->fmt.channelNum, 4, 1, fp); - fread(&dsf->fmt.samplesPerSec, 4, 1, fp); - fread(&dsf->fmt.bitsPerSample, 4, 1, fp); - fread(&dsf->fmt.sampleCount, 8, 1, fp); - fread(&dsf->fmt.blockSize, 4, 1, fp); - fseek(fp, 4, SEEK_CUR); // RESERVED - fread(dsf->data.chunkID, 1, 4, fp); - fread(&dsf->data.chunkSize, 8, 1, fp); + fread(&dsf->dsd.chunkSize, 8, 1, fp); /* 28 */ + fread(&dsf->dsd.fileSize, 8, 1, fp); /* Total File Size */ + fread(&dsf->dsd.metaPoint, 8, 1, fp); /* Pointer to Metadata Chunk */ + fread(dsf->fmt.chunkID, 1, 4, fp); /* "fmt " */ + fread(&dsf->fmt.chunkSize, 8, 1, fp); /* Usually, 52 */ + fread(&dsf->fmt.formatVersion, 4, 1, fp); /* 1 */ + fread(&dsf->fmt.formatID, 4, 1, fp); /* 0: DSD RAW */ + fread(&dsf->fmt.channelType, 4, 1, fp); /* 1 - 7, See Format Specification. */ + fread(&dsf->fmt.channelNum, 4, 1, fp); /* 1 - 6, See Format Specification. */ + fread(&dsf->fmt.samplesPerSec, 4, 1, fp); /* Sampling Frequency */ + fread(&dsf->fmt.bitsPerSample, 4, 1, fp); /* Quantization Bits */ + fread(&dsf->fmt.sampleCount, 8, 1, fp); /* samplesPerSec * [Playback time (sec)] (Little Endian) */ + fread(&dsf->fmt.blockSize, 4, 1, fp); /* 4096 */ + fseek(fp, 4, SEEK_CUR); /* RESERVED (0x00, 0x00, 0x00, 0x00) */ + fread(dsf->data.chunkID, 1, 4, fp); /* "data" */ + fread(&dsf->data.chunkSize, 8, 1, fp); /* (data byte)+12 */ - /* - printf("%s\n", dsf->dsd.chunkID); - printf("%lld\n", dsf->dsd.chunkSize); - printf("%lld\n", dsf->dsd.fileSize); - printf("%lld\n", dsf->dsd.metaPoint); - printf("%s\n", dsf->fmt.chunkID); - printf("%lld\n", dsf->fmt.chunkSize); - printf("%d\n", dsf->fmt.formatVersion); - printf("%d\n", dsf->fmt.formatID); - printf("%d\n", dsf->fmt.channelType); - printf("%d\n", dsf->fmt.channelNum); - printf("%d\n", dsf->fmt.samplesPerSec); - printf("%d\n", dsf->fmt.bitsPerSample); - printf("%lld\n", dsf->fmt.sampleCount); - printf("%d\n", dsf->fmt.blockSize); - printf("%s\n", dsf->data.chunkID); - printf("%lld\n", dsf->data.chunkSize); - printf("\n"); - */ + /* For debug */ + //printf("%s\n", dsf->dsd.chunkID); + //printf("%lld\n", dsf->dsd.chunkSize); + //printf("%lld\n", dsf->dsd.fileSize); + //printf("%lld\n", dsf->dsd.metaPoint); + //printf("%s\n", dsf->fmt.chunkID); + //printf("%lld\n", dsf->fmt.chunkSize); + //printf("%d\n", dsf->fmt.formatVersion); + //printf("%d\n", dsf->fmt.formatID); + //printf("%d\n", dsf->fmt.channelType); + //printf("%d\n", dsf->fmt.channelNum); + //printf("%d\n", dsf->fmt.samplesPerSec); + //printf("%d\n", dsf->fmt.bitsPerSample); + //printf("%lld\n", dsf->fmt.sampleCount); + //printf("%d\n", dsf->fmt.blockSize); + //printf("%s\n", dsf->data.chunkID); + //printf("%lld\n", dsf->data.chunkSize); + //printf("\n"); /* Calcurate Data Byte */ uint64_t data_size = dsf->data.chunkSize - 12; /* Allocate data byte memory */ dsf->data.data = (uint8_t *)calloc(data_size, sizeof(uint8_t)); - data_ptr = dsf->data.data; // Head Pointer + data_ptr = dsf->data.data; /* Head Pointer */ for (uint64_t i = 0; i < data_size; i++) { /* Store 8 samples */ fread(dsf->data.data, 1, 1, fp); + + /* For Debug. */ //printf("%lld: %x\n", i, *dsd->data.data); dsf->data.data++; }