1/* 2 * Copyright 2006, Haiku. 3 * 4 * Copyright (c) 2002-2004 Matthijs Hollemans 5 * Copyright (c) 2003 Jerome Leveque 6 * Distributed under the terms of the MIT License. 7 * 8 * Authors: 9 * J��r��me Leveque 10 * Matthijs Hollemans 11 */ 12 13#include <string.h> 14 15#include "debug.h" 16#include <Path.h> 17#include <Synth.h> 18#include "SoftSynth.h" 19 20BSynth* be_synth = NULL; 21 22using namespace BPrivate; 23 24 25BSynth::BSynth() 26{ 27 _Init(); 28} 29 30 31BSynth::BSynth(synth_mode mode) 32{ 33 _Init(); 34 fSynthMode = mode; 35} 36 37 38BSynth::~BSynth() 39{ 40 delete fSynth; 41 be_synth = NULL; 42} 43 44 45status_t 46BSynth::LoadSynthData(entry_ref* instrumentsFile) 47{ 48 if (instrumentsFile == NULL) { 49 return B_BAD_VALUE; 50 } 51 52 BPath path(instrumentsFile); 53 status_t err = path.InitCheck(); 54 if (err != B_OK) 55 return err; 56 return fSynth->SetInstrumentsFile(path.Path()); 57} 58 59 60status_t 61BSynth::LoadSynthData(synth_mode mode) 62{ 63 // Our softsynth doesn't support multiple modes like Be's synth did. 64 // Therefore, if you use this function, the synth will revert to its 65 // default instruments bank. However, we do keep track of the current 66 // synth_mode here, in order not to confuse old applications. 67 68 fSynthMode = mode; 69 if (fSynthMode == B_SAMPLES_ONLY) { 70 fprintf(stderr, "[midi] LoadSynthData: BSamples is not supported\n"); 71 } 72 73 return fSynth->SetDefaultInstrumentsFile(); 74} 75 76 77synth_mode 78BSynth::SynthMode() 79{ 80 return fSynthMode; 81} 82 83 84void 85BSynth::Unload() 86{ 87 fSynth->Unload(); 88} 89 90 91bool 92BSynth::IsLoaded() const 93{ 94 return fSynth->IsLoaded(); 95} 96 97 98status_t 99BSynth::SetSamplingRate(int32 sample_rate) 100{ 101 return fSynth->SetSamplingRate(sample_rate); 102} 103 104 105int32 106BSynth::SamplingRate() const 107{ 108 return fSynth->SamplingRate(); 109} 110 111 112status_t 113BSynth::SetInterpolation(interpolation_mode interp_mode) 114{ 115 return fSynth->SetInterpolation(interp_mode); 116} 117 118 119interpolation_mode 120BSynth::Interpolation() const 121{ 122 return fSynth->Interpolation(); 123} 124 125 126void 127BSynth::SetReverb(reverb_mode rev_mode) 128{ 129 fSynth->SetReverb(rev_mode); 130} 131 132 133reverb_mode 134BSynth::Reverb() const 135{ 136 return fSynth->Reverb(); 137} 138 139 140status_t 141BSynth::EnableReverb(bool reverb_enabled) 142{ 143 return fSynth->EnableReverb(reverb_enabled); 144} 145 146 147bool 148BSynth::IsReverbEnabled() const 149{ 150 return fSynth->IsReverbEnabled(); 151} 152 153 154status_t 155BSynth::SetVoiceLimits( 156 int16 maxSynthVoices, int16 maxSampleVoices, int16 limiterThreshhold) 157{ 158 status_t err = B_OK; 159 err = fSynth->SetMaxVoices(maxSynthVoices); 160 if (err == B_OK) { 161 err = fSynth->SetLimiterThreshold(limiterThreshhold); 162 } 163 return err; 164} 165 166 167int16 168BSynth::MaxSynthVoices() const 169{ 170 return fSynth->MaxVoices(); 171} 172 173 174int16 175BSynth::MaxSampleVoices() const 176{ 177 fprintf(stderr, "[midi] MaxSampleVoices: BSamples not supported\n"); 178 return 0; 179} 180 181 182int16 183BSynth::LimiterThreshhold() const 184{ 185 return fSynth->LimiterThreshold(); 186} 187 188 189void 190BSynth::SetSynthVolume(double theVolume) 191{ 192 fSynth->SetVolume(theVolume); 193} 194 195 196double 197BSynth::SynthVolume() const 198{ 199 return fSynth->Volume(); 200} 201 202 203void 204BSynth::SetSampleVolume(double theVolume) 205{ 206 fprintf(stderr, "[midi] SetSampleVolume: BSamples not supported\n"); 207} 208 209 210double 211BSynth::SampleVolume(void) const 212{ 213 fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n"); 214 return 0; 215} 216 217 218status_t 219BSynth::GetAudio(int16* pLeft, int16* pRight, int32 max_samples) const 220{ 221 if (fSynth->fMonitorSize <= 0) { 222 memset(pLeft, 0, max_samples * sizeof(int16)); 223 memset(pRight, 0, max_samples * sizeof(int16)); 224 return max_samples; 225 } 226 227 int32 nSamples = fSynth->fMonitorSize / sizeof(float) 228 / fSynth->fMonitorChans; 229 if (nSamples > max_samples) 230 nSamples = max_samples; 231 float* sPtr = fSynth->fMonitor; 232 for (int32 i = 0; i < nSamples; i++, sPtr += fSynth->fMonitorChans) { 233 *pLeft++ = (int16)(*sPtr * 32768); 234 *pRight++ = (int16)(*(sPtr + 1) * 32768); 235 } 236 return nSamples; 237} 238 239 240void 241BSynth::Pause() 242{ 243 fSynth->Pause(); 244} 245 246 247void 248BSynth::Resume() 249{ 250 fSynth->Resume(); 251} 252 253 254void 255BSynth::SetControllerHook(int16 controller, synth_controller_hook cback) 256{ 257 fprintf(stderr, "[midi] SetControllerHook is not supported\n"); 258} 259 260 261void 262BSynth::_Init() 263{ 264 delete be_synth; 265 be_synth = this; 266 fSynthMode = B_NO_SYNTH; 267 fClientCount = 0; 268 fSynth = new BSoftSynth(); 269} 270 271 272int32 273BSynth::CountClients() const 274{ 275 return fClientCount; 276} 277 278 279void BSynth::_ReservedSynth1() { } 280void BSynth::_ReservedSynth2() { } 281void BSynth::_ReservedSynth3() { } 282void BSynth::_ReservedSynth4() { } 283 284