2 * Copyright 2006, Haiku.
4 * Copyright (c) 2002-2004 Matthijs Hollemans
5 * Copyright (c) 2003 Jerome Leveque
6 * Distributed under the terms of the MIT License.
18 #include "SoftSynth.h"
20 BSynth
* be_synth
= NULL
;
22 using namespace BPrivate
;
31 BSynth::BSynth(synth_mode mode
)
46 BSynth::LoadSynthData(entry_ref
* instrumentsFile
)
48 if (instrumentsFile
== NULL
) {
52 BPath
path(instrumentsFile
);
53 status_t err
= path
.InitCheck();
56 return fSynth
->SetInstrumentsFile(path
.Path());
61 BSynth::LoadSynthData(synth_mode mode
)
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.
69 if (fSynthMode
== B_SAMPLES_ONLY
) {
70 fprintf(stderr
, "[midi] LoadSynthData: BSamples is not supported\n");
73 return fSynth
->SetDefaultInstrumentsFile();
92 BSynth::IsLoaded() const
94 return fSynth
->IsLoaded();
99 BSynth::SetSamplingRate(int32 sample_rate
)
101 return fSynth
->SetSamplingRate(sample_rate
);
106 BSynth::SamplingRate() const
108 return fSynth
->SamplingRate();
113 BSynth::SetInterpolation(interpolation_mode interp_mode
)
115 return fSynth
->SetInterpolation(interp_mode
);
120 BSynth::Interpolation() const
122 return fSynth
->Interpolation();
127 BSynth::SetReverb(reverb_mode rev_mode
)
129 fSynth
->SetReverb(rev_mode
);
134 BSynth::Reverb() const
136 return fSynth
->Reverb();
141 BSynth::EnableReverb(bool reverb_enabled
)
143 return fSynth
->EnableReverb(reverb_enabled
);
148 BSynth::IsReverbEnabled() const
150 return fSynth
->IsReverbEnabled();
155 BSynth::SetVoiceLimits(
156 int16 maxSynthVoices
, int16 maxSampleVoices
, int16 limiterThreshhold
)
159 err
= fSynth
->SetMaxVoices(maxSynthVoices
);
161 err
= fSynth
->SetLimiterThreshold(limiterThreshhold
);
168 BSynth::MaxSynthVoices() const
170 return fSynth
->MaxVoices();
175 BSynth::MaxSampleVoices() const
177 fprintf(stderr
, "[midi] MaxSampleVoices: BSamples not supported\n");
183 BSynth::LimiterThreshhold() const
185 return fSynth
->LimiterThreshold();
190 BSynth::SetSynthVolume(double theVolume
)
192 fSynth
->SetVolume(theVolume
);
197 BSynth::SynthVolume() const
199 return fSynth
->Volume();
204 BSynth::SetSampleVolume(double theVolume
)
206 fprintf(stderr
, "[midi] SetSampleVolume: BSamples not supported\n");
211 BSynth::SampleVolume(void) const
213 fprintf(stderr
, "[midi] SampleVolume: BSamples not supported\n");
219 BSynth::GetAudio(int16
* pLeft
, int16
* pRight
, int32 max_samples
) const
221 // We don't print a "not supported" message here. That would cause
222 // significant slowdowns because applications ask for this many times.
224 if (fSynth
->fMonitorSize
<= 0) {
225 memset(pLeft
, 0, max_samples
* sizeof(int16
));
226 memset(pRight
, 0, max_samples
* sizeof(int16
));
230 int32 nSamples
= fSynth
->fMonitorSize
/ sizeof(float)
231 / fSynth
->fMonitorChans
;
232 if (nSamples
> max_samples
)
233 nSamples
= max_samples
;
234 float* sPtr
= fSynth
->fMonitor
;
235 for (int32 i
= 0; i
< nSamples
; i
++, sPtr
+= fSynth
->fMonitorChans
) {
236 *pLeft
++ = (int16
)(*sPtr
* 32768);
237 *pRight
++ = (int16
)(*(sPtr
+ 1) * 32768);
258 BSynth::SetControllerHook(int16 controller
, synth_controller_hook cback
)
260 fprintf(stderr
, "[midi] SetControllerHook is not supported\n");
269 fSynthMode
= B_NO_SYNTH
;
271 fSynth
= new BSoftSynth();
276 BSynth::CountClients() const
282 void BSynth::_ReservedSynth1() { }
283 void BSynth::_ReservedSynth2() { }
284 void BSynth::_ReservedSynth3() { }
285 void BSynth::_ReservedSynth4() { }