-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsfio_sample.c
79 lines (64 loc) · 1.96 KB
/
dsfio_sample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* dsfio_sample.c */
/*----------------------------------------------------
Copyright (c) 2024 AUDIY
Released under the MIT license
https://opensource.org/licenses/mit-license.php
----------------------------------------------------*/
/* Include standard libraries */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <limits.h>
/* Include prototype header file */
#include "dsfio.h"
void printb(uint8_t v);
void putb(uint8_t v);
int main(void) {
DSF *dsf;
DSD_STREAM *stream;
//char *filename = "Sine_1kHz_0dB_LR_DSD64_swap.dsf";
char *filename = "Sine_1kHz_0dB_LR_DSD64.dsf";
//uint8_t left, right;
dsf = alloc_DSF();
stream = alloc_STREAM();
/* Prototype Definition */
read_DSF(dsf, filename);
shape_STREAM(dsf, stream);
for (uint64_t i = 0; i < (dsf->data.chunkSize - 12)/2; i++){
//printf("%lld: 0x%2x, 0x%2x\n", i, *stream->DSDL, *stream->DSDR);
printf("%lu: ", i);
putb(*stream->DSDL);
printf(", ");
putb(*stream->DSDL);
printf("\n");
/*
for (uint64_t j = 8; j > 0; j--) {
left = *stream->DSDL / (int)(pow(2, j-1));
right = *stream->DSDR / (int)(pow(2, j-1));
//printf("%1d, %1d\n", left, right);
if (left == 1) {
*stream->DSDL -= (int)pow(2, j-1);
}
if (right == 1) {
*stream->DSDR -= (int)pow(2, j-1);
}
}
*/
stream->DSDL++;
stream->DSDR++;
}
free_DSF(dsf);
free_STREAM(stream);
return 0;
}
void printb(uint8_t v) {
unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
do putchar(mask & v ? '1' : '0');
while (mask >>= 1);
}
void putb(uint8_t v) {
//putchar('0'), putchar('b'), printb(v), putchar('\n');
putchar('0'), putchar('b'), printb(v);
}