Főoldal | Osztályhierarchia | Osztálylista | Fájllista | Osztálytagok | Fájlelemek | Kapcsolódó lapok

wavefile.cc

00001 /*
00002  * SubTimer source file
00003  *  Copyright (C) 2005 Peter Salvi
00004  *   Last modification: <2005.03.23., 16:20:36>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include <qdatetime.h>
00022 
00023 #include "wavefile.hh"
00024 
00025 WaveFile::WaveFile()
00026 {
00027   opened = false;
00028   wave = NULL;
00029   dispbuf = NULL;
00030 }
00031 
00032 WaveFile::~WaveFile()
00033 {
00034   if(wave != NULL)
00035     delete[] wave;
00036   if(dispbuf != NULL)
00037     delete[] dispbuf;
00038 }
00039 
00040 bool WaveFile::isOpen() const
00041 {
00042   return opened;
00043 }
00044 
00045 void WaveFile::changeRes(int xres)
00046 {
00047   if(dispbuf != NULL)
00048     delete[] dispbuf;
00049  
00050   size_t const zoom = xres / (int)(640.0 / MAX_PIXPERSEC);
00051   pixpersec = MAX_PIXPERSEC / (double)zoom;
00052   size_t const new_length = wavelength / zoom;
00053   dispbuf = new char[new_length + 1280];
00054   for(size_t i = 0; i < new_length;) {
00055     int min = 0, max = 0;
00056     for(size_t j = i * zoom; j < (i + 2) * zoom; j += 2) {
00057       if(wave[j] < min)
00058         min = wave[j];
00059       if(wave[j + 1] > max)
00060         max = wave[j + 1];
00061     }
00062     dispbuf[i++] = min;
00063     dispbuf[i++] = max;
00064   }
00065   for(size_t j = 0; j < 1280; ++j)
00066     dispbuf[new_length + j] = 0;
00067 }
00068 
00069 void WaveFile::getDispBuffer(QTime const start, char *buffer) const
00070 {
00071   size_t const start_index = 
00072     (size_t)((double)MSECS(start) / 1000.0 * pixpersec) * 2;
00073   for(size_t i = 0; i < 1280; ++i)
00074     buffer[i] = dispbuf[start_index + i];
00075 }

Projekt: SubTimer Készült: Wed Mar 23 22:06:54 2005 Készítette: doxygen 1.3.6