00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifdef HAVE_CONFIG_H
00011 #include "config.h"
00012 #endif
00013
00014 #include <assert.h>
00015
00016 #include "taptaudio_paimpl.h"
00017
00018 AudioSystem::AudioSystem(AUDIO_FORMAT format,
00019 double sampleRate,
00020 int inputChannels,
00021 int outputChannels,
00022 int deviceIDin,
00023 int deviceIDout
00024 )
00025 :
00026 impl(0)
00027 {
00028 if (AUDIO_TRACKS == 0) {
00029 DODEBUG(NOTICE, ("[An] Audio is disabled in the config file"));
00030 return;
00031 }
00032 assert(!instance || "There can only be one audio system!");
00033
00034 SDL_mutexP(AudioSystemImpl::as_mutex);
00035 if (format == AF_Default)
00036 format = AF_Int16;
00037
00038 try {
00039 if (AUDIO_TRACKS > 1) {
00040 switch(format) {
00041 case AF_Float32:
00042 impl = new AudioSystemMixerT<float>(inputChannels, outputChannels,
00043 sampleRate, format, AUDIO_TRACKS,
00044 deviceIDin, deviceIDout);
00045 break;
00046 case AF_Int32:
00047 impl = new AudioSystemMixerT<Sint32>(inputChannels, outputChannels,
00048 sampleRate, format, AUDIO_TRACKS,
00049 deviceIDin, deviceIDout);
00050
00051 break;
00052 case AF_Int16:
00053 impl = new AudioSystemMixerT<Sint16>(inputChannels, outputChannels,
00054 sampleRate, format, AUDIO_TRACKS,
00055 deviceIDin, deviceIDout);
00056
00057 break;
00058 case AF_Int8:
00059 impl = new AudioSystemMixerT<Sint8>(inputChannels, outputChannels,
00060 sampleRate, format, AUDIO_TRACKS,
00061 deviceIDin, deviceIDout);
00062
00063 break;
00064 default: break;
00065
00066 }
00067 }
00068 if (!impl) {
00069 impl = new AudioSystemImpl(inputChannels, outputChannels, sampleRate, format,
00070 deviceIDin, deviceIDout);
00071
00072 }
00073 } catch (PaError &err) {
00074 DODEBUG(ERROR, ("[Ae] Error initialising audio system: %s",
00075 Pa_GetErrorText(err)));
00076 impl = 0;
00077 }
00078
00079 AudioSystem::instance = this;
00080
00081 SDL_mutexV(AudioSystemImpl::as_mutex);
00082 }
00083
00084 AudioSystem::~AudioSystem() {
00085 if (impl) {
00086 impl->stop();
00087 impl->waitstop();
00088 delete impl;
00089 }
00090 AudioSystem::instance = 0;
00091 }
00092
00093 ASSample* AudioSystem::loadSample(const std::string &name) {
00094 return (this && impl) ? impl->loadSample(name) : 0;
00095 }
00096
00097 ASSample* AudioSystem::loadRawSample(const std::string &name, void* data, unsigned long size) {
00098 return (this && impl && data) ? impl->loadRawSample(name, data, size) : 0;
00099 }
00100
00101 bool AudioSystem::mixSample(ASSample *samp, bool record_after, double record_size, float vol, unsigned* trackno) {
00102 return (this && impl && samp) ? impl->mixSample(samp, record_after, record_size, false, vol, trackno) : false;
00103 }
00104
00105 bool AudioSystem::mixSample(ASSample *samp, float vol, unsigned* trackno) {
00106 return (this && impl && samp) ? impl->mixSample(samp, false, 0, false, vol, trackno) : false;
00107 }
00108
00109 bool AudioSystem::loopSample(ASSample *samp, float vol, unsigned* trackno) {
00110 return (this && impl && samp) ? impl->loopSample(samp, vol, trackno) : false;
00111 }
00112
00113 bool AudioSystem::freeSample(ASSample *samp) {
00114 return (this && impl && samp) ? impl->freeSample(samp) : false;
00115 }
00116
00117 unsigned AudioSystem::stopSample(ASSample *samp, int trackno) {
00118 return (this && impl && samp) ? impl->stopSample(samp, trackno) : false;
00119 }
00120
00121 bool AudioSystem::startRec(double secondsMax) {
00122 return (this && impl) ? impl->startRec(secondsMax) : false;
00123 }
00124
00125 ASSample* AudioSystem::stopRec(const std::string &name, bool save, bool save_in_thread) {
00126 return (this && impl) ? impl->stopRec(name, save, save_in_thread) : 0;
00127 }
00128
00129 bool AudioSystem::isRecording() {
00130 return (this && impl) ? impl->isRecording() : false;
00131 }
00132
00133 unsigned AudioSystem::setVolume(ASSample *samp, float vol, int trackno) {
00134 return (this && impl && samp) ? impl->setVolume(samp, vol, trackno) : 0;
00135 }
00136
00137 void AudioSystem::stop() {
00138 if (this && impl)
00139 impl->stop();
00140 }
00141
00142 unsigned AudioSystem::AUDIO_TRACKS = 32;
00143 AudioSystem* AudioSystem::instance = 0;
00144
00145
00146 ASSample* AudioSystem::loadSample(const char* name) {
00147 return loadSample(std::string(name));
00148 }
00149
00150 ASSample* AudioSystem::loadRawSample(const char* name, void* data, unsigned long size) {
00151 return loadRawSample(std::string(name), data, size);
00152 }
00153
00154 ASSample* AudioSystem::stopRec(const char* name, bool save, bool save_in_thread) {
00155 return stopRec(std::string(name), save, save_in_thread);
00156 }
00157
00158 void AudioSystem::setDebugLevel(unsigned level) {
00159 SETDEBUG(level);
00160 }
00161
00162 void AudioSystem::setDebugFile(void* FILESTAR) {
00163 taptaudio_debug_file = static_cast<FILE*>(FILESTAR);
00164 }
00165
00166 void AudioSystem::listDevices() {
00167 AudioSystemImpl::listDevices();
00168 }