2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <FMediaToneTypes.h>
20 #include <FBaseSysLog.h>
21 #include "FMedia_ToneGenerator.h"
23 using namespace Tizen::Base;
24 namespace Tizen {namespace Media
27 _ToneGenerator::_ToneGenerator(void)
31 _ToneGenerator::~_ToneGenerator(void)
36 _ToneGenerator::GenerateTone(Tizen::Base::ByteBuffer& toneBuffer, const int& firstFrequency, const int& secondFrequency,
37 long startSample, long endSample,
42 float first = 2 * M_PI * firstFrequency / (float) SAMPLING_RATE;
43 float second = 2 * M_PI * secondFrequency / (float) SAMPLING_RATE;
44 int j = toneBuffer.GetPosition();
46 //Gives the number of samples
47 j = j / _BYTES_PER_SAMPLE;
49 // Generate tone for the given samples
50 for (long i = startSample; i < endSample; i++, j++)
52 tempTone = ((sin(first * i) + sin(second * i)) * ((_MAX_TONE_PLAYER_VOLUME_VALUE * volume) / 100));
53 r = toneBuffer.SetShort(_BYTES_PER_SAMPLE * j, tempTone);
54 SysTryReturn(NID_MEDIA, r == E_SUCCESS , false, false, "[%s] Propagating", GetErrorMessage(r));
58 r = toneBuffer.SetPosition((j) * _BYTES_PER_SAMPLE);
59 SysTryReturn(NID_MEDIA, r == E_SUCCESS , false, false, "[%s] Propagating", GetErrorMessage(r));