Line 2... |
Line 2... |
//
|
//
|
// Filename: buildsamples.cpp
|
// Filename: buildsamples.cpp
|
//
|
//
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
//
|
//
|
// Purpose:
|
// Purpose: This program converts an 8kHz, 16t, mono- sound data file into
|
|
// samples that can be read and understood by the C compiler and
|
|
// hence included in a S6SoC project as the ``doorbell'' audio sound.
|
|
//
|
|
// To use this, first convert your sound file to 8kHz, 16t, raw mono
|
|
// format. The sox utility works well for this purpose.
|
|
//
|
|
// Then, run this program wih the single argument being the name of that
|
|
// sound file. The standard output will be the resulting C-code
|
|
// representing/recreating that sound file. Pipe this into a file for
|
|
// inclusion in your program. You can then reference both the number of
|
|
// samples from that file, as well as the number of words those samples
|
|
// are stored in, as well as what those samples are.
|
|
//
|
|
// The samples themselves can then be placed in a flash partition, and
|
|
// read like any memory from within your program.
|
//
|
//
|
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
Line 47... |
Line 62... |
|
|
char cbuf[SLEN];
|
char cbuf[SLEN];
|
short sbuf[SLEN];
|
short sbuf[SLEN];
|
int nread = 0, nr;
|
int nread = 0, nr;
|
|
|
|
if (argc != 1) {
|
|
fprintf(stderr,
|
|
"Usage:\tbuildsamples samplefile\n"
|
|
"\n"
|
|
"\twhere 'samplefile' is a sound data file consisting of 16-bit samples\n"
|
|
"\tthat have been sampled at 8kHz. The sample file should have no\n"
|
|
"\theader, and should only reference a mono (not stereo) output.\n"
|
|
"\n"
|
|
"\tThe result is a C program fragment that can be redirected to a file for\n"
|
|
"\tlater inclusion in your project.\n");
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
fp = fopen(argv[1], "rb");
|
fp = fopen(argv[1], "rb");
|
if (!fp) {
|
if (!fp) {
|
fprintf(stderr, "Could not open %s for reading\n", argv[1]);
|
fprintf(stderr, "Could not open %s for reading\n", argv[1]);
|
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
}
|
}
|