OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [buildsamples.cpp] - Blame information for rev 12

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    buildsamples.cpp
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#include <stdio.h>
39
#include <stdlib.h>
40
#include <string.h>
41
 
42
#define SLEN    512
43
#define ILEN    (SLEN/2)
44
 
45
int     main(int argc, char **argv) {
46
        FILE    *fp, *legal;
47
 
48
        char    cbuf[SLEN];
49
        short   sbuf[SLEN];
50
        int     nread = 0, nr;
51
 
52
        fp = fopen(argv[1], "rb");
53
        if (!fp) {
54
                fprintf(stderr, "Could not open %s for reading\n", argv[1]);
55
                exit(EXIT_FAILURE);
56
        }
57
 
58
        /*
59
        legal = fopen("../legal.txt", "r");
60
        if (!legal)
61
                legal = fopen("../../legal.txt", "r");
62
        */
63
        legal = NULL;
64
        if (legal) {
65
                while(fgets(cbuf, SLEN, legal)) {
66
                        if (strncmp(cbuf, "// Filename:", 12)==0)
67
                                printf("// Filename:\tsamples.c\n");
68
                        else    printf("%s", cbuf);
69
                } fclose(legal);
70
        } else {
71
                printf("// This file should be copyrighted but I can't find\n");
72
                printf("// the copyright statement.\n//\n");
73
        }
74
 
75
        printf(
76
"// This file is computer generated--DO NOT EDIT IT!  The generator file can\n"
77
"// be found in trunk/sw/host/%s\n"
78
"//\n"
79
"//\n"
80
"#ifndef\tSOUND_DATA_H\n"
81
"#define\tSOUND_DATA_H\n\n"
82
"const\tint\tsound_data[] = {\n", __FILE__);
83
 
84
        while((nr = fread(sbuf, sizeof(short), SLEN, fp))>0) {
85
                int     pos = 0;
86
                nread += nr;
87
                while(pos < nr) {
88
                        printf("\t");
89
                        for(int i=0; (pos<((nr+1)&-2))&&(i<8); i+=2) {
90
                                int iv = (sbuf[pos]<<16)|(sbuf[pos+1] & 0x0ffff);
91
                                printf("0x%08x, ", iv);
92
                                pos+=2;
93
                        } printf("\n");
94
                }
95
        } printf("\t0\n};\n");
96
 
97
        printf("\n\n"
98
"#define\tNSAMPLES\t%d\n"
99
"#define\tNSAMPLE_WORDS\t%d\n"
100
"\n\n#endif\n", nread, 1+((nread+1)>>1));
101
 
102
}
103
 

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.