home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- #include "audio.h"
- #include <stdio.h>
-
- #ifdef DEBUG
- #define dprintf printf
- #else
- #define dprintf 0&&
- #endif
-
- Audio::Audio()
- {
- long buf[32];
- dprintf("Audio\n");
- _numAudio = 0;
- setRate(AL_RATE_8000);
- setNumChannels(AL_MONO);
- setBytesPerSample(AL_SAMPLE_16);
- // buffer 2 seconds of data
- _bufferLength = getRate() * getNumChannels() * getBytesPerSample() * 2;
- _buffer = new char [_bufferLength];
-
- int n = 0;
- buf[n++] = AL_INPUT_RATE;
- buf[n++] = getRate();
- buf[n++] = AL_OUTPUT_RATE;
- buf[n++] = getRate();
- buf[n++] = AL_INPUT_SOURCE;
- buf[n++] = AL_INPUT_MIC;
- // buf[n++] = AL_LEFT_INPUT_ATTEN;
- // buf[n++] = 20;
- // buf[n++] = AL_RIGHT_INPUT_ATTEN;
- // buf[n++] = 20;
- buf[n++] = AL_OUTPUT_RATE;
- buf[n++] = getRate();
- buf[n++] = AL_MIC_MODE;
- buf[n++] = getNumChannels();
-
- ALsetparams(AL_DEFAULT_DEVICE, buf, n);
- ALconfig config = ALnewconfig();
- ALsetwidth(config,getBytesPerSample());
- ALsetchannels(config,getNumChannels());
- ALsetqueuesize(config, _bufferLength / getBytesPerSample());
- _port = ALopenport("security","r",config);
- ALfreeconfig(config);
- }
- Audio::~Audio()
- {
- dprintf("end Audio\n");
- ALcloseport(_port);
- delete [] _buffer;
- _port = NULL;
- }
-
- void *
- Audio::getAudio(int &numSamples)
- {
- dprintf("getAudio\n");
- numSamples = int(ALgetfilled(_port));
- if(numSamples > 0){
- if(_bufferLength < numSamples * getBytesPerSample()){
- delete [] _buffer;
- _bufferLength = numSamples * getBytesPerSample();
- _buffer = new char [_bufferLength ];
- }
- ALreadsamps(_port, _buffer, numSamples);
- dprintf("getAudio %d\n",numSamples);
- return _buffer;
- }
- }
-