Skip to content

Commit

Permalink
Change comment fomat
Browse files Browse the repository at this point in the history
  • Loading branch information
AUDIY authored Jan 14, 2024
1 parent 6f05418 commit c247397
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
6 changes: 3 additions & 3 deletions DSFIO/alloc_DSF.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
66 changes: 33 additions & 33 deletions DSFIO/dsfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,74 @@
https://opensource.org/licenses/mit-license.php
----------------------------------------------------*/

// include guard
/* include guard */
#ifndef INCLUDED_DSFIO
#define INCLUDED_DSFIO

#include <stdint.h>

//extern C
/* extern C */
#ifdef __cplusplus
extern "C"
{
#endif

/* 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
4 changes: 2 additions & 2 deletions DSFIO/free_DSF.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions DSFIO/free_STREAM.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
74 changes: 38 additions & 36 deletions DSFIO/read_DSF.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down

0 comments on commit c247397

Please sign in to comment.