1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
///////////////////////////////////////////////////////////////////////////////
// $Id: Sound.cxx,v 1.3 2000/01/10 23:33:06 bwmott Exp $
///////////////////////////////////////////////////////////////////////////////
//
// Sound.cxx - Sound class
//
//
// Bradford W. Mott
// Copyright (C) 1995
// January 4,1995
//
///////////////////////////////////////////////////////////////////////////////
// $Log: Sound.cxx,v $
// Revision 1.3 2000/01/10 23:33:06 bwmott
// Sound system uses the /dev/dsp device now instead of the /dev/audio device
//
// Revision 1.2 1996/01/06 05:12:39 bwmott
// Changed all NULLs to 0 and added (char*) cast in the write system call
//
// Revision 1.1 1995/01/08 06:48:24 bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "Sound.hxx"
///////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////
Sound::Sound(SampleCollection* sampleCollection)
: mySampleCollection(sampleCollection)
{
// Determine if there is a usable sound device
int soundDevice = open("/dev/dsp", O_WRONLY, 0);
if(soundDevice == -1)
{
myState = Disabled;
}
else
{
myState = Enabled;
close(soundDevice);
}
}
///////////////////////////////////////////////////////////////////////////////
// Destructor
///////////////////////////////////////////////////////////////////////////////
Sound::~Sound()
{
}
///////////////////////////////////////////////////////////////////////////////
// Play the named sample
///////////////////////////////////////////////////////////////////////////////
void Sound::playSample(char* sampleName)
{
// Play the sample if I'm enabled
if(myState == Enabled)
{
// Open the sound device
int audio = open("/dev/dsp", O_WRONLY, 0);
if(audio != -1)
{
// Get the sample from my sample collection
Sample* sample = mySampleCollection->getByName(sampleName);
if(sample != 0)
write(audio, (char*)sample->data(), sample->length());
close(audio);
}
}
}
|