Compare commits

..

No commits in common. "92f6e5cf23f994ce9f22b521f52d7f0614273008" and "307b5907964a0cdcf787ab2ef6129237c4d6e65a" have entirely different histories.

7 changed files with 26 additions and 285 deletions

View File

@ -2,9 +2,28 @@
# tth@konrad:~/Devel/Fortraneries/SoundBrotching$
#
GOPT = -Wall -Wextra -g
COPT = -Wall -Wextra -g -DDEBUG_LEVEL=1
all: panoramix genwaves
all: text2wav wav2text text2ao \
panoramix genwaves
# ----------------------------------------------------------
#
# C tools
#
CLIBS = -lsndfile support.o
support.o: support.c Makefile support.h
gcc $(COPT) -c $<
text2wav: text2wav.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -o $@
wav2text: wav2text.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -o $@
text2ao: text2ao.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -o $@
# ----------------------------------------------------------
#
@ -12,16 +31,14 @@ all: panoramix genwaves
#
FLIBS = soundbrotch.o
# support functions
soundbrotch.o: soundbrotch.f90 Makefile
gfortran $(GOPT) -c $<
gfortran $(COPT) -c $<
# main proggies
panoramix: panoramix.f90 Makefile $(FLIBS)
gfortran $(GOPT) $< $(FLIBS) -o $@
gfortran $(COPT) $< $(FLIBS) -o $@
genwaves: genwaves.f90 Makefile $(FLIBS)
gfortran $(GOPT) $< $(FLIBS) -o $@
gfortran $(COPT) $< $(FLIBS) -o $@
# ----------------------------------------------------------

View File

@ -4,21 +4,8 @@ Stay tuned, film at 11.
## Cheat Code
Certains composants [utiles](c-tools/)
de ce sous-projet fortranique sont
Certains composants de ce sous-projet fortranique sont
(pour le moment)
ecrits en C, pour un accès facile à des bibliothèques tierces
comme `libsndfile` ou `libao`, composants essentiels du SoundBrotching.
comme `libsndfile`, composant essentiel du SoundBrotching.
## Serious game
Quelques exemples simple, mais bruyants...
### genwaves
Génération de sons qui arrachent les oreilles.
### panoramix
Conversion de l'entrée en mono, et dépacement en sinus d'un
coté à l'autre.

View File

@ -1,4 +0,0 @@
*.wav

View File

@ -1,27 +0,0 @@
#
# tth@konrad:~/Devel/Fortraneries/SoundBrotching/c-tools$
#
COPT = -Wall -Wextra -g -DDEBUG_LEVEL=1
all: text2wav wav2text text2ao
# ----------------------------------------------------------
#
# C tools
#
CLIBS = -lsndfile support.o
support.o: support.c Makefile support.h
gcc $(COPT) -c $<
text2wav: text2wav.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -o $@
wav2text: wav2text.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -o $@
text2ao: text2ao.c Makefile support.h support.o
gcc $(COPT) $< $(CLIBS) -lao -o $@
# ------ eomf --------

View File

@ -1,32 +0,0 @@
/*
* C SUPPORT FUNCTIONS
*/
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
int display_sf_info(SF_INFO *psf, char *text)
{
fprintf(stderr, " +-- sf info [%s] %p\n", text, psf);
fprintf(stderr, " | samplerate %d\n", psf->samplerate);
fprintf(stderr, " | channels %d\n", psf->channels);
fprintf(stderr, " | frames %ld\n", psf->frames);
fprintf(stderr, " | format 0x%x\n", psf->format);
return 0;
}
/* --------------------------------------------------------------- */
void print_version(char *msg)
{
fprintf(stderr, "=== %s compiled %s, %s\n", \
msg, __DATE__, __TIME__);
}
/* --------------------------------------------------------------- */

View File

@ -1,102 +0,0 @@
/*
* TEXT TO WAV
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
#define SMPL_COUNT 8192
/*
* WARNING !
* this function can read only 16bits stereo input
*/
int convert_text_to_wav(FILE *input, char *outfname, int format)
{
SNDFILE * sndf;
SF_INFO sfinfo;
short *buffer;
int left, right;
int nb_lus, idx;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, outfname);
#endif
if (format) {
fprintf(stderr, "in %s, format must be 0, was %d\n",
__func__, format);
exit(1);
}
/*
* allocate memory for input garbage
*/
if (NULL==(buffer=malloc(SMPL_COUNT * sizeof(short) * 2))) {
fprintf(stderr, "%s: MEMORY FULL\n", __func__);
abort();
}
memset(&sfinfo, 0, sizeof(sfinfo)); /* be clean */
sfinfo.samplerate = 44100;
sfinfo.channels = 2;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
if ( ! (sndf=sf_open(outfname, SFM_WRITE, &sfinfo)) ) {
fprintf(stderr, "write to %s : err %s\n",
outfname, sf_strerror (NULL));
return -2;
}
/*
* and now, ladies an gentelman, entering the big loop
*/
nb_lus = idx = 0;
memset(buffer, 0, SMPL_COUNT * sizeof(short) * 2);
while (2==fscanf(input, "%d %d", &left, &right)) {
buffer[idx++] = left;
buffer[idx++] = right;
if (idx >= SMPL_COUNT) {
/* flush buffer to file */
sf_write_short(sndf, buffer, idx);
idx = 0;
memset(buffer, 0, SMPL_COUNT * sizeof(short) * 2);
}
nb_lus += 1;
}
sf_write_short(sndf, buffer, idx);
sf_close(sndf);
fprintf(stderr, "%s: %d buffers written\n", __func__, nb_lus);
return 0;
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
print_version(argv[0]);
if (2 != argc) {
fprintf(stderr, "fubarized\n");
exit(1);
}
foo = convert_text_to_wav(stdin, argv[1], 0);
fprintf(stderr, "got a %d from text->wav converter\n", foo);
return 0;
}
/* --------------------------------------------------------------- */

View File

@ -1,98 +0,0 @@
/*
* WAV TO TEXT
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
/*
* at this time, 'format' must be 0
*/
int convert_wav_to_text(char *infname, int format)
{
SNDFILE * sndf;
SF_INFO sfinfo;
int foo, lu;
short * samples;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, infname);
#endif
if (format) {
fprintf(stderr, "in %s, format must be 0 and was %d\n",
__func__, format);
exit(1);
}
memset(&sfinfo, 0, sizeof(sfinfo)); /* be clean */
sndf = sf_open(infname, SFM_READ, &sfinfo);
if (sndf==NULL)
{
/*catch the snfile errmsg here XXX */
fprintf(stderr, "error sf_opening %s\n", infname);
exit(1);
}
foo = display_sf_info(&sfinfo, infname);
if (foo) {
fprintf(stderr, "%s: corrupted sf_info ?\n", __func__);
abort();
}
if (2 != sfinfo.channels) {
fprintf(stderr, "/!\\ %s is not a stereo file, exiting...\n",
infname);
return -2;
}
/* get memory for bufferins read from sound file */
if ( NULL == (samples = malloc(BUFFER_SIZE*sizeof(short))) )
{
perror("\n no memory in converter");
abort();
}
while ( (lu=sf_read_short(sndf, samples, BUFFER_SIZE)) > 0 )
{
// fprintf(stderr, " LU = %5u\n", lu);
for (foo=0; foo<lu; foo+=2) {
printf("%d %d\n", samples[foo], samples[foo+1]);
}
}
/*
* job done, some cleanup
*/
free(samples);
sf_close(sndf);
return 0;
}
/* --------------------------------------------------------------- */
void usage(void)
{
printf("usage:\n\twav2txt 1337.wav\n");
exit(0);
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
int format = 0;
print_version(argv[0]);
if (2 != argc) usage();
foo = convert_wav_to_text(argv[1], format);
fprintf(stderr, "got a %d from wav->text converter\n", foo);
return 0;
}
/* --------------------------------------------------------------- */