begin of a new era, maybe

This commit is contained in:
tth
2022-03-31 22:14:11 +02:00
parent c47bcfe298
commit 595c6901c9
19 changed files with 208 additions and 274 deletions

View File

@@ -0,0 +1,16 @@
# C tools
Support utilities for SoundBrotching.
### wav2text
Conversion d'un fichier son en text machinable.
### text2wav
Conversion d'un fichier texte en fichier son.
### text2ao
Envoi d'un fichier texte vers une sortie audio.

View File

@@ -0,0 +1,60 @@
/*
* TEXT TO AUDIO OUTPUT
*/
#include <stdio.h>
#include <string.h>
#include <sndfile.h>
#include <ao/ao.h> /* for the sound output */
#include "support.h"
/* --------------------------------------------------------------- */
int sound_blasting(FILE *input)
{
int driver;
ao_sample_format format;
ao_device * device;
fprintf(stderr, ">>> %s ( %p )\n", __func__, input);
ao_initialize();
driver = ao_default_driver_id();
fprintf(stderr, " driver is #%d\n", driver);
memset(&format, 0, sizeof(ao_sample_format)); /* indispensable */
format.bits = 16;
format.channels = 2;
format.rate = 44100;
format.byte_format = AO_FMT_LITTLE; /* XXX ??? */
device = ao_open_live(driver, &format, NULL);
if (device == NULL)
{
fprintf(stderr, "\n%s: Error open device\n", __func__);
/*
* comment connaitre la cause de l'erreur ?
*/
return -2;
}
fprintf(stderr, "sound device open at %p\n", device);
return -1;
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
print_version(argv[0]);
if (argc < 2) {
fprintf(stderr, "%s uh?\n", argv[0]);
}
foo = sound_blasting(stdin);
fprintf(stderr, "sound blasting -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------- */

View File

@@ -2,12 +2,8 @@ program genwaves
use soundbrotch
! -----------------------------
implicit none
print *, "genwaves is coming soon..."
call soundbrotch_version()

View File

@@ -1,9 +1,35 @@
program panoramix
use soundbrotch
! ------------------------------------------------------
implicit none
integer :: left, right
integer :: errcode
integer :: nblus
real :: value, phi, ka
print *, "Panoramix coming soon..."
call soundbrotch_version()
nblus = 0
do
read (*, *, iostat=errcode) left, right
if (errcode .NE. 0) then
write(0, *) 'EOF ? ', errcode
exit
endif
! *** NON WORKING CODE ***
phi = real(nblus) / 20000.0
ka = sin(phi)
value = (real(left)+real(right)) / 2.05
left = int(value*ka)
right = int(value*(1.0-ka))
print *, left, right
nblus = nblus + 1
enddo
end program

View File

@@ -1,6 +1,13 @@
module soundbrotch
implicit none
! ---------------------------------------------------------
type t_sample
integer :: left
integer :: right
end type
! ---------------------------------------------------------
contains
@@ -8,7 +15,7 @@ module soundbrotch
subroutine soundbrotch_version ()
write(0, '(A)') "*** this is soundbrotch version alpha"
write(0, '(A)') "*** this is soundbrotch version alpha 666"
end subroutine

View File

@@ -1,31 +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);
return 0;
}
/* --------------------------------------------------------------- */
void print_version(char *msg)
{
fprintf(stderr, "======== %s === compiled %s, %s\n", \
msg, __DATE__, __TIME__);
}
/* --------------------------------------------------------------- */

View File

@@ -1,21 +0,0 @@
/*
* TEXT TO AUDIO OUTPUT
*/
#include <stdio.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
print_version(argv[0]);
return 0;
}
/* --------------------------------------------------------------- */

View File

@@ -1,34 +0,0 @@
/*
* TEXT TO WAV
*/
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
int convert_text_to_wav(char *outfname)
{
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, outfname);
#endif
return -1;
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
print_version(argv[0]);
if (2 != argc) {
fprintf(stderr, "fubar\n");
exit(1);
}
return 0;
}
/* --------------------------------------------------------------- */

View File

@@ -1,81 +0,0 @@
/*
* WAV TO TEXT
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sndfile.h>
#include "support.h"
/* --------------------------------------------------------------- */
int convert_wav_to_text(char *infname)
{
SNDFILE * sndf;
SF_INFO sfinfo;
int foo, lu;
short * samples;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, infname);
#endif
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, "why not ?");
if (foo) {
fprintf(stderr, "%s: corrupted sf_info ?\n", __func__);
abort();
}
/* 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 = %5lu\n", lu);
}
/*
* job done, some cleanup
*/
free(samples);
return -1;
}
/* --------------------------------------------------------------- */
void usage(void)
{
printf("usage:\n\twav2txt 1337.wav\n");
exit(0);
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
print_version(argv[0]);
if (2 != argc) usage();
foo = convert_wav_to_text(argv[1]);
fprintf(stderr, "got a %d from converter\n", foo);
return 0;
}
/* --------------------------------------------------------------- */