Skip to content

Commit

Permalink
added cmake project and tidied up
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Lazzarini committed Jan 26, 2022
1 parent 2244347 commit 030a084
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 79 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CMake project for MUSIC V
cmake_minimum_required (VERSION 2.8.12 )
project(Music5)
enable_language(Fortran)

function(add_program NAME)
if(${ARGC} GREATER 1)
add_executable(${NAME} "src/${NAME}.c")
else()
add_executable(${NAME} "src/${NAME}.f")
endif()
endfunction()

add_program(pass1)
add_program(pass2)
add_program(pass3)
add_program(towav c)
add_program(music5 c)
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, vlazzarini
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions scripts/music5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
rm snd.raw
cp -f $1 score
./pass1
./pass2
./pass3
./towav $2


10 changes: 8 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile for MUSIC V
# Victor Lazzarini, Jun 08

PROGS = pass1 pass2 pass3
PROGS = pass1 pass2 pass3 towav music5

all: $(PROGS)

Expand All @@ -14,5 +14,11 @@ pass2: pass2.f
pass3: pass3.f
gfortran -o pass3 pass3.f

towav: towav.c
cc -o towav towav.c

music5: music5.c
cc -o music5 music5.c

clean: $(PROGS)
rm -f $(PROGS)
rm -f $(PROGS)
66 changes: 0 additions & 66 deletions src/examples.txt

This file was deleted.

55 changes: 55 additions & 0 deletions src/music5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// MUSIC V driver program
// calls pass1, pass2, pass3 and towav to produce an output
// (c) V Lazzarini, 2022
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
if (argc > 2) {
int ret;
char command[1024];
sprintf(command, "cp -f %s score", argv[1]);
system(command);
ret = system("./pass1");
if(ret == 0) {
ret = system("./pass2");
if(ret == 0) {
ret = system("./pass3");
if(ret == 0) {
sprintf(command, "./towav %s", argv[2]);
system(command);
return 0;
}
else printf("pass 3 failed\n");
} else printf("pass 2 failed\n");
} else printf("pass 1 failed\n");
return 1;
} else printf("usage: %s score output.wav \n", argv[1]);
return -1;
}



11 changes: 0 additions & 11 deletions src/music5.sh

This file was deleted.

92 changes: 92 additions & 0 deletions src/towav.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Simple dependency-free raw 44100 Hz 32-bit floats mono
// conversion from raw data to RIFF-Wave format
// (c) V Lazzarini, 2022
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE

#include <stdio.h>

const char RIFF_ID[4] = {'R','I','F','F'};
const char WAVE_ID[4] = {'W','A','V','E'};
const char FMT_ID[4] = {'f','m','t',' '};
const char DATA_ID[4] = {'d','a','t','a'};

typedef struct wave_head{
int magic; // 'RIFF'
int len0; // Chunk size = len + 8 + 16 + 12
int magic1; // 'WAVE'
int magic2; // 'fmt '
int len; // length of header (16)
short format;// 1 is PCM integer, 3 is float integer
short nchns; // Number of channels
int rate; // sampling frequency
int aver; // Average bytes/sec !!
short nBlockAlign; // (rate*nch +7)/8
short size; // size of each sample (8,16,32)
int magic3; // 'data'
int datasize; // data chunk size
} WAVEHEAD;

#define bufsize 512

int main(int argc, const char *argv[]) {
FILE *fp, *fpi;
size_t r = 0, bytes =0;
WAVEHEAD header;
float buf[bufsize];
const char* fname = argc > 1 ? argv[1] : "snd.wav";
header.magic = (long) (*(long*)RIFF_ID); // 'RIFF'
header.len0 = 0;
header.magic1 = (long) (*(long*)WAVE_ID); // 'WAVE'
header.magic2 = (long) (*(long*)FMT_ID);; // 'fmt '
header.len = 16; // length of header (16)
header.format = 3;
header.nchns = 1; // Number of channels
header.rate = 44100; // sampling frequency
header.aver = 176400;
header.nBlockAlign = 4; // (rate*nch +7)/8
header.size = 32; // size of each sample (8,16,32)
header.magic3= (long) (*(long*)DATA_ID);;
header.datasize = 0;

if((fpi = fopen("snd.raw", "r")) == NULL) {
printf("Could not open input snd.raw \n");
return -1;
}
if((fp = fopen(fname, "w")) != NULL) {
fwrite(&header,sizeof(WAVEHEAD),1,fp);
do {
r = fread(buf,sizeof(float),bufsize,fpi);
fwrite(buf,sizeof(float),r,fp);
bytes += (4*r);
} while(r);
rewind(fp);
header.datasize = bytes;
header.len0 = sizeof(WAVEHEAD) - 8 + bytes;
fwrite(&header,sizeof(WAVEHEAD),1,fp);
fclose(fp);
printf("Wrote %zu bytes of 32-bit float samples to %s \n", bytes, fname);
} else printf("Could not open %s for output\n", fname);
fclose(fpi);
return 0;
}

0 comments on commit 030a084

Please sign in to comment.