From: drowe67 Date: Sat, 7 Jul 2012 23:49:09 +0000 (+0000) Subject: pa_play test utility, works OK X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f83b1b3ea365c5de248c46e4a94c6061bb275196;p=freetel-svn-tracking.git pa_play test utility, works OK git-svn-id: https://svn.code.sf.net/p/freetel/code@584 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/unittest/Makefile.am b/codec2-dev/unittest/Makefile.am index 592442b2..60333e75 100644 --- a/codec2-dev/unittest/Makefile.am +++ b/codec2-dev/unittest/Makefile.am @@ -1,9 +1,9 @@ -AM_CFLAGS = -I../src -fPIC -g -DFLOATING_POINT -DVAR_ARRAYS -O2 +AM_CFLAGS = -I../src -fPIC -g -DFLOATING_POINT -DVAR_ARRAYS -O2 -Wall AUTOMAKE_OPTS = gnu NAME = libcodec2 AM_CPPFLAGS = $(AM_CFLAGS) -noinst_PROGRAMS = genres genlsp extract vqtrain vqtrainjnd tnlp tinterp tquant vq_train_jvm scalarlsptest tfdmdv t48_8 lspsync create_interleaver tlspsens pa_rec +noinst_PROGRAMS = genres genlsp extract vqtrain vqtrainjnd tnlp tinterp tquant vq_train_jvm scalarlsptest tfdmdv t48_8 lspsync create_interleaver tlspsens pa_rec pa_play genres_SOURCES = genres.c ../src/lpc.c genres_LDADD = $(lib_LTLIBRARIES) @@ -72,3 +72,7 @@ pa_rec_SOURCES = pa_rec.c ../src/fdmdv.c ../src/kiss_fft.c pa_rec_LDADD = $(lib_LTLIBRARIES) -lportaudio pa_rec_LDFLAGS = $(LIBS) +pa_play_SOURCES = pa_play.c ../src/fdmdv.c ../src/kiss_fft.c +pa_play_LDADD = $(lib_LTLIBRARIES) -lportaudio +pa_play_LDFLAGS = $(LIBS) + diff --git a/codec2-dev/unittest/Makefile.in b/codec2-dev/unittest/Makefile.in index 242ae343..7e83210d 100644 --- a/codec2-dev/unittest/Makefile.in +++ b/codec2-dev/unittest/Makefile.in @@ -41,7 +41,7 @@ noinst_PROGRAMS = genres$(EXEEXT) genlsp$(EXEEXT) extract$(EXEEXT) \ tinterp$(EXEEXT) tquant$(EXEEXT) vq_train_jvm$(EXEEXT) \ scalarlsptest$(EXEEXT) tfdmdv$(EXEEXT) t48_8$(EXEEXT) \ lspsync$(EXEEXT) create_interleaver$(EXEEXT) tlspsens$(EXEEXT) \ - pa_rec$(EXEEXT) + pa_rec$(EXEEXT) pa_play$(EXEEXT) subdir = unittest DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -74,6 +74,10 @@ am_lspsync_OBJECTS = lspsync.$(OBJEXT) quantise.$(OBJEXT) \ pack.$(OBJEXT) $(am__objects_1) lspsync_OBJECTS = $(am_lspsync_OBJECTS) lspsync_DEPENDENCIES = +am_pa_play_OBJECTS = pa_play.$(OBJEXT) fdmdv.$(OBJEXT) \ + kiss_fft.$(OBJEXT) +pa_play_OBJECTS = $(am_pa_play_OBJECTS) +pa_play_DEPENDENCIES = am_pa_rec_OBJECTS = pa_rec.$(OBJEXT) fdmdv.$(OBJEXT) \ kiss_fft.$(OBJEXT) pa_rec_OBJECTS = $(am_pa_rec_OBJECTS) @@ -134,16 +138,18 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(create_interleaver_SOURCES) $(extract_SOURCES) \ $(genlsp_SOURCES) $(genres_SOURCES) $(lspsync_SOURCES) \ - $(pa_rec_SOURCES) $(scalarlsptest_SOURCES) $(t48_8_SOURCES) \ - $(tfdmdv_SOURCES) $(tinterp_SOURCES) $(tlspsens_SOURCES) \ - $(tnlp_SOURCES) $(tquant_SOURCES) $(vq_train_jvm_SOURCES) \ - $(vqtrain_SOURCES) $(vqtrainjnd_SOURCES) + $(pa_play_SOURCES) $(pa_rec_SOURCES) $(scalarlsptest_SOURCES) \ + $(t48_8_SOURCES) $(tfdmdv_SOURCES) $(tinterp_SOURCES) \ + $(tlspsens_SOURCES) $(tnlp_SOURCES) $(tquant_SOURCES) \ + $(vq_train_jvm_SOURCES) $(vqtrain_SOURCES) \ + $(vqtrainjnd_SOURCES) DIST_SOURCES = $(create_interleaver_SOURCES) $(extract_SOURCES) \ $(genlsp_SOURCES) $(genres_SOURCES) $(lspsync_SOURCES) \ - $(pa_rec_SOURCES) $(scalarlsptest_SOURCES) $(t48_8_SOURCES) \ - $(tfdmdv_SOURCES) $(tinterp_SOURCES) $(tlspsens_SOURCES) \ - $(tnlp_SOURCES) $(tquant_SOURCES) $(vq_train_jvm_SOURCES) \ - $(vqtrain_SOURCES) $(vqtrainjnd_SOURCES) + $(pa_play_SOURCES) $(pa_rec_SOURCES) $(scalarlsptest_SOURCES) \ + $(t48_8_SOURCES) $(tfdmdv_SOURCES) $(tinterp_SOURCES) \ + $(tlspsens_SOURCES) $(tnlp_SOURCES) $(tquant_SOURCES) \ + $(vq_train_jvm_SOURCES) $(vqtrain_SOURCES) \ + $(vqtrainjnd_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -251,7 +257,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ -AM_CFLAGS = -I../src -fPIC -g -DFLOATING_POINT -DVAR_ARRAYS -O2 +AM_CFLAGS = -I../src -fPIC -g -DFLOATING_POINT -DVAR_ARRAYS -O2 -Wall AUTOMAKE_OPTS = gnu NAME = libcodec2 AM_CPPFLAGS = $(AM_CFLAGS) @@ -306,6 +312,9 @@ tlspsens_LDFLAGS = $(LIBS) pa_rec_SOURCES = pa_rec.c ../src/fdmdv.c ../src/kiss_fft.c pa_rec_LDADD = $(lib_LTLIBRARIES) -lportaudio pa_rec_LDFLAGS = $(LIBS) +pa_play_SOURCES = pa_play.c ../src/fdmdv.c ../src/kiss_fft.c +pa_play_LDADD = $(lib_LTLIBRARIES) -lportaudio +pa_play_LDFLAGS = $(LIBS) all: all-am .SUFFIXES: @@ -361,6 +370,9 @@ genres$(EXEEXT): $(genres_OBJECTS) $(genres_DEPENDENCIES) lspsync$(EXEEXT): $(lspsync_OBJECTS) $(lspsync_DEPENDENCIES) @rm -f lspsync$(EXEEXT) $(LINK) $(lspsync_LDFLAGS) $(lspsync_OBJECTS) $(lspsync_LDADD) $(LIBS) +pa_play$(EXEEXT): $(pa_play_OBJECTS) $(pa_play_DEPENDENCIES) + @rm -f pa_play$(EXEEXT) + $(LINK) $(pa_play_LDFLAGS) $(pa_play_OBJECTS) $(pa_play_LDADD) $(LIBS) pa_rec$(EXEEXT): $(pa_rec_OBJECTS) $(pa_rec_DEPENDENCIES) @rm -f pa_rec$(EXEEXT) $(LINK) $(pa_rec_LDFLAGS) $(pa_rec_OBJECTS) $(pa_rec_LDADD) $(LIBS) @@ -422,6 +434,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lspsync.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nlp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/octave.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pa_play.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pa_rec.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pack.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phase.Po@am__quote@ diff --git a/codec2-dev/unittest/pa_play.c b/codec2-dev/unittest/pa_play.c new file mode 100644 index 00000000..00ea0868 --- /dev/null +++ b/codec2-dev/unittest/pa_play.c @@ -0,0 +1,199 @@ +/* + pa_play.c + David Rowe + July 8 2012 + + Converts samples from a 16 bit short 8000 Hz rawfile to 480000Hz + sample rate and plays them using the default sound device. Used as + an intermediate step in Portaudio integration. + + Modified from paex_record.c Portaudio example. Original author + author Phil Burk http://www.softsynth.com +*/ + +/* + * $Id: paex_record.c 1752 2011-09-08 03:21:55Z philburk $ + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include "portaudio.h" +#include "fdmdv.h" + +#define SAMPLE_RATE 48000 /* 48 kHz sampling rate rec. as we + can trust accuracy of sound + card */ +#define N8 160 /* processing buffer size at 8 kHz */ +#define N48 (N8*FDMDV_OS) /* processing buffer size at 48 kHz */ +#define MEM8 (FDMDV_OS_TAPS/FDMDV_OS) +#define NUM_CHANNELS 2 /* I think most sound cards prefer + stereo, we will convert to mono + as we sample */ + +/* state information passed to call back */ + +typedef struct { + FILE *fin; + float in8k[MEM8 + N8]; +} paTestData; + + +/* + This routine will be called by the PortAudio engine when audio is + required. It may be called at interrupt level on some machines so + don't do anything that could mess up the system like calling + malloc() or free(). +*/ + +static int playCallback( const void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + FILE *fin = data->fin; + int i, nread; + int finished; + short *wptr = (short*)outputBuffer; + float *in8k = data->in8k; + float out48k[N48]; + short out48k_short[N48]; + short in8k_short[N8]; + + (void) outputBuffer; /* Prevent unused variable warnings. */ + (void) timeInfo; + (void) statusFlags; + (void) userData; + + /* note Portaudio docs recs. against making systems calls like + fwrite() in this callback but seems to work OK */ + + nread = fread(in8k_short, sizeof(short), N8, fin); + if (nread == N8) + finished = paContinue; + else + finished = paComplete; + + for(i=0; idefaultLowOutputLatency; + outputParameters.hostApiSpecificStreamInfo = NULL; + + /* Play some audio --------------------------------------------- */ + + err = Pa_OpenStream( + &stream, + NULL, + &outputParameters, + SAMPLE_RATE, + N48, + paClipOff, + playCallback, + &data ); + if( err != paNoError ) goto done; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto done; + + while( ( err = Pa_IsStreamActive( stream ) ) == 1 ) + { + Pa_Sleep(100); + } + if( err < 0 ) goto done; + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto done; + + fclose(data.fin); + + +done: + Pa_Terminate(); + if( err != paNoError ) + { + fprintf( stderr, "An error occured while using the portaudio stream\n" ); + fprintf( stderr, "Error number: %d\n", err ); + fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); + err = 1; /* Always return 0 or 1, but no other return codes. */ + } + return err; +} + diff --git a/codec2-dev/unittest/pa_rec.c b/codec2-dev/unittest/pa_rec.c index 6ed22d87..79366621 100644 --- a/codec2-dev/unittest/pa_rec.c +++ b/codec2-dev/unittest/pa_rec.c @@ -3,7 +3,8 @@ David Rowe July 6 2012 - Records at 48000 Hz from default sound device to a file. + Records at 48000 Hz from default sound device, convertes to 8 kHz, + and saves to raw file. Used to get experience with Portaudio. Modified from paex_record.c Portaudio example. Original author author Phil Burk http://www.softsynth.com @@ -46,12 +47,16 @@ #include "portaudio.h" #include "fdmdv.h" -#define SAMPLE_RATE 48000 -#define N8 160 /* processing buffer size at 8 kHz */ -#define N48 (N8*FDMDV_OS) /* processing buffer size at 48 kHz */ -#define NUM_CHANNELS 2 /* I think most sound cards like stereo, we will - convert to mono as we sample */ -#define SAMPLE_SILENCE 0 +#define SAMPLE_RATE 48000 /* 48 kHz sampling rate rec. as we + can trust accuracy of sound + card */ +#define N8 160 /* processing buffer size at 8 kHz */ +#define N48 (N8*FDMDV_OS) /* processing buffer size at 48 kHz */ +#define NUM_CHANNELS 2 /* I think most sound cards prefer + stereo, we will convert to mono + as we sample */ + +/* state information passed to call back */ typedef struct { FILE *fout; @@ -60,10 +65,13 @@ typedef struct { } paTestData; -/* This routine will be called by the PortAudio engine when audio is available. -** It may be called at interrupt level on some machines so don't do anything -** that could mess up the system like calling malloc() or free(). +/* + This routine will be called by the PortAudio engine when audio is + available. It may be called at interrupt level on some machines so + don't do anything that could mess up the system like calling + malloc() or free(). */ + static int recordCallback( const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, @@ -112,7 +120,7 @@ static int recordCallback( const void *inputBuffer, void *outputBuffer, for(i=0; idefaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; - /* Record some audio. -------------------------------------------- */ + /* Record some audio --------------------------------------------- */ err = Pa_OpenStream( &stream,