Blender V2.61 - r43446

AUD_SinusReader.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include "AUD_SinusReader.h"
00031 
00032 #include <cmath>
00033 
00034 #ifndef M_PI
00035 #define M_PI 3.14159265358979323846
00036 #endif
00037 
00038 AUD_SinusReader::AUD_SinusReader(float frequency, AUD_SampleRate sampleRate) :
00039     m_frequency(frequency),
00040     m_position(0),
00041     m_sampleRate(sampleRate)
00042 {
00043 }
00044 
00045 bool AUD_SinusReader::isSeekable() const
00046 {
00047     return true;
00048 }
00049 
00050 void AUD_SinusReader::seek(int position)
00051 {
00052     m_position = position;
00053 }
00054 
00055 int AUD_SinusReader::getLength() const
00056 {
00057     return -1;
00058 }
00059 
00060 int AUD_SinusReader::getPosition() const
00061 {
00062     return m_position;
00063 }
00064 
00065 AUD_Specs AUD_SinusReader::getSpecs() const
00066 {
00067     AUD_Specs specs;
00068     specs.rate = m_sampleRate;
00069     specs.channels = AUD_CHANNELS_MONO;
00070     return specs;
00071 }
00072 
00073 void AUD_SinusReader::read(int& length, bool& eos, sample_t* buffer)
00074 {
00075     // fill with sine data
00076     for(int i = 0; i < length; i++)
00077     {
00078         buffer[i] = sin((m_position + i) * 2 * M_PI * m_frequency / m_sampleRate);
00079     }
00080 
00081     m_position += length;
00082     eos = false;
00083 }