/* CMP_portaudio.h to feed ComParser's preprocessor (see CMP_prep.h) with live audio from a portaudio (v18) callback routine. The realtime RUNNING_DATA object embeds the audio preprocessor (PREP) object. This file is not needed for the PD external (neither is CMP_portaudio.c). CMP version 1.35, june 17, 2004. Latest version available at: http://kmt.hku.nl/~pieter/SOFT/ Copyright (c) 2001-2004 Schreck Ensemble - Pieter Suurmond 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. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. 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. */ /*----------------------------------------------------------------------------*/ typedef struct /* Data that may be accessed by PA callback. */ { PREP audioprep; /* Dynamically allocated preprocessor object. */ int samplesPerFrame; /* The number of channels for the PA stream. */ short* input; /* Input buffer for the preprocessor, needed */ /* to copy data from interleaved streams (or */ /* to convert incoming floats to ints, etc.). */ long varidistFrames; /* Size (time-dimension) of large circular */ /* output buffer, not limited to powers of 2. */ short* varidistOutput; /* Startaddress of the large circular buffer */ /* with varidistFrames*(2*varidistScalars) */ /* bytes. Alignment is as follows: */ /* 0: reference value (prevent null-vector). */ /* 1: bipolar RMS difference within window. */ /* 2: varidistBands linear magnitudes (pos). */ /* (thus 2 more shorts than varidistBands) */ long writtenIndex; /* Index between 0 and varidistFrames (excl). */ /* Points to last vector written. */ long readIndex; /* Points to last vector read. (>=0 or -1). */ /* For audio recording during analysis: */ short* audioRecBuffer; /* Start of circular audio buffer. */ long audioRecWriteI; /* Write index (post-increment!). */ long audioRecFrames; /* Number of 16 bit mono frames (shorts), */ /* always a multiple of half fftInputSize! */ } callBackData; /*----------------------------------------------------------------------------*/ typedef struct /* Can't we do with one single struct? */ { long samplerate; /* Stored at startup of process. */ int chunksize; /* Number of audioframes per feature vector. */ PortAudioStream* stream; callBackData cbdata; /* Used by the callback routine. */ } RUNNING_DATA; /*----------------------------------------------------------------------------*/ /* Searches for portaudio devices. Reports available audio-i/o to filestream msg, which may be stdout, stderr or some textfile already opened for writing by the caller. Returns 0 in case of success, but also returns 0 if argument msg is NULL. Returns a (non-zero) portaudio error number on failure. */ int audio_devices(FILE* msg); /*----------------------------------------------------------------------------*/ /* Starts realtime analysis (the preprocessing layer as PortAudio process) and immediately returns. Call stopAnalysisVD to stop this realtime background process. */ int start_analysis(RUNNING_DATA** data, /* Recve object or NULL here. */ short channels, long samplerate, int chunksize, FILE* msg); /* May be NULL, stderr, etc. */ /*----------------------------------------------------------------------------*/ /* Stops analysis and releases the realtime object. Argument msg may be NULL. */ int stop_analysis(RUNNING_DATA** data, FILE* msg); /*----------------------------------------------------------------------------*/ /* Dumps last frames analysis-frames to open filestream msg. Does nothing when you supply a NULL pointer for msg. */ void view_analysis(RUNNING_DATA* ana, long frames, FILE* msg);