Compare commits

...

2 Commits

Author SHA1 Message Date
tth
92f6e5cf23 refactoring in progress 2022-03-10 10:44:45 +01:00
tth
082fb8e671 wav/text convertors now working 2022-03-08 11:33:01 +01:00
7 changed files with 285 additions and 26 deletions

View File

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

View File

@ -4,8 +4,21 @@ Stay tuned, film at 11.
## Cheat Code ## Cheat Code
Certains composants de ce sous-projet fortranique sont Certains composants [utiles](c-tools/)
de ce sous-projet fortranique sont
(pour le moment) (pour le moment)
ecrits en C, pour un accès facile à des bibliothèques tierces ecrits en C, pour un accès facile à des bibliothèques tierces
comme `libsndfile`, composant essentiel du SoundBrotching. comme `libsndfile` ou `libao`, composants essentiels 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.

4
SoundBrotching/c-tools/.gitignore vendored Normal file
View File

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

View File

@ -0,0 +1,27 @@
#
# 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

@ -0,0 +1,32 @@
/*
* 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

@ -0,0 +1,102 @@
/*
* 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

@ -0,0 +1,98 @@
/*
* 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;
}
/* --------------------------------------------------------------- */